-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
70 lines (59 loc) · 2.24 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Demonstration of https://github.com/rust-lang/rust/issues/110624
// i.e. even with +whole-archive, re-exporting requires no_mangle
#[link(name="ext_issue110624", kind="static", modifiers = "+whole-archive")]
extern "C" {
#[no_mangle]
pub fn foo_issue110624_with_no_mangle();
pub fn foo_issue110624_without_no_mangle();
}
#[link(name="ext_issue110624_2", kind="static", modifiers = "+whole-archive")]
extern "C" {
pub fn foo_issue110624_2_without_no_mangle();
}
// Demonstration of https://github.com/rust-lang/rfcs/pull/3556
#[link(name="ext_rfc3556", kind="static")]
extern "C" {
// FUNCTIONS
// Should be re-exported
#[no_mangle]
pub fn foo_rfc3556_pub_with_no_mangle();
// Should warn and not be re-exported
#[no_mangle]
fn foo_rfc3556_priv_with_no_mangle();
// Should not be re-exported
pub fn foo_rfc3556_pub_without_no_mangle();
// Should not be re-exported
fn foo_rfc3556_priv_without_no_mangle();
// STATICS
// Should be re-exported
#[no_mangle]
pub static mut foo_rfc3556_global_pub_with_no_mangle: std::ffi::c_int;
// Should warn and not be re-exported
#[no_mangle]
static mut foo_rfc3556_global_priv_with_no_mangle: std::ffi::c_int;
// Should not be re-exported
pub static mut foo_rfc3556_global_pub_without_no_mangle: std::ffi::c_int;
// Should not be re-exported
static mut foo_rfc3556_global_priv_without_no_mangle: std::ffi::c_int;
}
// Demonstration of normal symbol export
#[no_mangle]
pub extern "C" fn foo_pub_no_mangle_rust_fn() {}
// no_mangle on extern rust functions always marks the symbol as globally visible
#[no_mangle]
extern "C" fn foo_priv_no_mangle_rust_fn() {}
// Make sure all the imports are used
#[no_mangle]
pub unsafe extern "C" fn x() -> std::ffi::c_int {
foo_issue110624_with_no_mangle();
foo_issue110624_without_no_mangle();
foo_issue110624_2_without_no_mangle();
foo_rfc3556_pub_with_no_mangle();
foo_rfc3556_priv_with_no_mangle();
foo_rfc3556_pub_without_no_mangle();
foo_rfc3556_priv_without_no_mangle();
foo_rfc3556_global_pub_with_no_mangle +
foo_rfc3556_global_priv_with_no_mangle +
foo_rfc3556_global_pub_without_no_mangle +
foo_rfc3556_global_priv_without_no_mangle
}