diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index f40b639..edd16b3 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -570,7 +570,7 @@ impl Parse { return; } - if item.is_no_mangle() && (abi.is_omitted() || abi.is_c()) { + if item.vis == syn::Visibility::Public && item.is_no_mangle() && (abi.is_omitted() || abi.is_c()) { match Function::load(item.ident.to_string(), decl, false, &item.attrs, mod_cfg) { Ok(func) => { info!("Take {}::{}.", crate_name, &item.ident); @@ -582,6 +582,12 @@ impl Parse { } } } else { + if item.vis != syn::Visibility::Public { + warn!( + "Skip {}::{} - (not `pub`).", + crate_name, &item.ident + ); + } if (abi.is_omitted() || abi.is_c()) && !item.is_no_mangle() { warn!( "Skip {}::{} - (`extern` but not `no_mangle`).", @@ -649,14 +655,29 @@ impl Parse { let static_name = item.ident.to_string(); - match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) { - Ok(constant) => { - info!("Take {}::{}.", crate_name, &item.ident); + if item.vis == syn::Visibility::Public && item.is_no_mangle() { + match Static::load(static_name.clone(), ty, mutability, &item.attrs, mod_cfg) { + Ok(constant) => { + info!("Take {}::{}.", crate_name, &item.ident); - self.globals.try_insert(constant); + self.globals.try_insert(constant); + } + Err(msg) => { + warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg); + } } - Err(msg) => { - warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg); + } else { + if item.vis != syn::Visibility::Public { + warn!( + "Skip {}::{} - (not `pub`).", + crate_name, &item.ident + ); + } + if !item.is_no_mangle() { + warn!( + "Skip {}::{} - (not `no_mangle`).", + crate_name, &item.ident + ); } } } diff --git a/tests/rust/alias.rs b/tests/rust/alias.rs index 435e707..86e3e00 100644 --- a/tests/rust/alias.rs +++ b/tests/rust/alias.rs @@ -24,8 +24,9 @@ type Unit = i32; type SpecialStatus = Status; #[no_mangle] -extern "C" fn root(x: IntFoo, - y: DoubleFoo, - z: Unit, - w: SpecialStatus) -{ } +pub extern "C" fn root( + x: IntFoo, + y: DoubleFoo, + z: Unit, + w: SpecialStatus +) { } diff --git a/tests/rust/annotation.rs b/tests/rust/annotation.rs index b078921..a4c08ea 100644 --- a/tests/rust/annotation.rs +++ b/tests/rust/annotation.rs @@ -16,7 +16,8 @@ enum C { } #[no_mangle] -extern "C" fn root(x: A, - y: B, - z: C) -{ } +pub extern "C" fn root( + x: A, + y: B, + z: C +) { } diff --git a/tests/rust/cdecl.rs b/tests/rust/cdecl.rs index ceae1ce..d8b34cb 100644 --- a/tests/rust/cdecl.rs +++ b/tests/rust/cdecl.rs @@ -16,22 +16,23 @@ type M = [fn (i32, i32) -> bool; 16]; type N = [fn (i32, i32) -> (); 16]; #[no_mangle] -extern "C" fn O() -> fn () +pub extern "C" fn O() -> fn () { } #[no_mangle] -extern "C" fn root(a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - j: J, - k: K, - l: L, - m: M, - n: N) -{ } +pub extern "C" fn root( + a: A, + b: B, + c: C, + d: D, + e: E, + f: F, + g: G, + h: H, + i: I, + j: J, + k: K, + l: L, + m: M, + n: N +) { } diff --git a/tests/rust/cfg-2.rs b/tests/rust/cfg-2.rs index e65d2cd..515b3f3 100644 --- a/tests/rust/cfg-2.rs +++ b/tests/rust/cfg-2.rs @@ -22,5 +22,5 @@ struct Root { } #[no_mangle] -extern "C" fn root(a: Root) +pub extern "C" fn root(a: Root) { } diff --git a/tests/rust/cfg.rs b/tests/rust/cfg.rs index fd6d9b8..ed81823 100644 --- a/tests/rust/cfg.rs +++ b/tests/rust/cfg.rs @@ -32,10 +32,10 @@ struct BarHandle { #[cfg(all(unix, x11))] #[no_mangle] -extern "C" fn root(a: FooHandle) +pub extern "C" fn root(a: FooHandle) { } #[cfg(any(windows, target_pointer_width="32"))] #[no_mangle] -extern "C" fn root(a: BarHandle) +pub extern "C" fn root(a: BarHandle) { } diff --git a/tests/rust/constant.rs b/tests/rust/constant.rs index 3caab96..ee67081 100644 --- a/tests/rust/constant.rs +++ b/tests/rust/constant.rs @@ -8,4 +8,4 @@ struct Foo { } #[no_mangle] -extern "C" fn root(x: Foo) { } +pub extern "C" fn root(x: Foo) { } diff --git a/tests/rust/enum.rs b/tests/rust/enum.rs index 1e91d9e..03b0d48 100644 --- a/tests/rust/enum.rs +++ b/tests/rust/enum.rs @@ -44,10 +44,11 @@ enum E { } #[no_mangle] -extern "C" fn root(o: *mut Opaque, - a: A, - b: B, - c: C, - d: D, - e: E) -{ } +pub extern "C" fn root( + o: *mut Opaque, + a: A, + b: B, + c: C, + d: D, + e: E +) { } diff --git a/tests/rust/euclid.rs b/tests/rust/euclid.rs index 25a2d0c..d3c2940 100644 --- a/tests/rust/euclid.rs +++ b/tests/rust/euclid.rs @@ -55,26 +55,27 @@ type LayoutPoint2D = TypedPoint2D; type LayoutRect = TypedRect; #[no_mangle] -extern "C" fn root(length_a: TypedLength, - length_b: TypedLength, - length_c: Length, - length_d: LayoutLength, - side_offsets_a: TypedSideOffsets2D, - side_offsets_b: TypedSideOffsets2D, - side_offsets_c: SideOffsets2D, - side_offsets_d: LayoutSideOffsets2D, - size_a: TypedSize2D, - size_b: TypedSize2D, - size_c: Size2D, - size_d: LayoutSize2D, - point_a: TypedPoint2D, - point_b: TypedPoint2D, - point_c: Point2D, - point_d: LayoutPoint2D, - rect_a: TypedRect, - rect_b: TypedRect, - rect_c: Rect, - rect_d: LayoutRect, - transform_a: TypedTransform2D, - transform_b: TypedTransform2D) { -} +pub extern "C" fn root( + length_a: TypedLength, + length_b: TypedLength, + length_c: Length, + length_d: LayoutLength, + side_offsets_a: TypedSideOffsets2D, + side_offsets_b: TypedSideOffsets2D, + side_offsets_c: SideOffsets2D, + side_offsets_d: LayoutSideOffsets2D, + size_a: TypedSize2D, + size_b: TypedSize2D, + size_c: Size2D, + size_d: LayoutSize2D, + point_a: TypedPoint2D, + point_b: TypedPoint2D, + point_c: Point2D, + point_d: LayoutPoint2D, + rect_a: TypedRect, + rect_b: TypedRect, + rect_c: Rect, + rect_d: LayoutRect, + transform_a: TypedTransform2D, + transform_b: TypedTransform2D +) { } diff --git a/tests/rust/extern-2.rs b/tests/rust/extern-2.rs index 56eab18..92a9c18 100644 --- a/tests/rust/extern-2.rs +++ b/tests/rust/extern-2.rs @@ -1,11 +1,11 @@ #[no_mangle] -extern "C" fn first() +pub extern "C" fn first() { } #[no_mangle] -extern fn second() +pub extern fn second() { } #[no_mangle] -fn third() +pub fn third() { } diff --git a/tests/rust/fail-str.rs b/tests/rust/fail-str.rs index d5c2008..1306859 100644 --- a/tests/rust/fail-str.rs +++ b/tests/rust/fail-str.rs @@ -6,6 +6,7 @@ struct Foo<'a> { const BAR: &'static str = ""; #[no_mangle] -extern "C" fn root(a: Foo<'static>, - b: &'static str) -{ } +pub extern "C" fn root( + a: Foo<'static>, + b: &'static str +) { } diff --git a/tests/rust/inner_mod.rs b/tests/rust/inner_mod.rs index 8b65a2a..89411ad 100644 --- a/tests/rust/inner_mod.rs +++ b/tests/rust/inner_mod.rs @@ -6,5 +6,5 @@ mod foo { } #[no_mangle] -extern "C" fn root(a: foo::Foo) +pub extern "C" fn root(a: foo::Foo) { } diff --git a/tests/rust/monomorph-1.rs b/tests/rust/monomorph-1.rs index 01d9caa..a75cc23 100644 --- a/tests/rust/monomorph-1.rs +++ b/tests/rust/monomorph-1.rs @@ -16,12 +16,13 @@ struct Tuple { type Indirection = Tuple; #[no_mangle] -extern "C" fn root(a: Foo, - b: Foo, - c: Bar, - d: Foo>, - e: Bar>, - f: Bar>, - g: Tuple, f32>, - h: Indirection) { -} +pub extern "C" fn root( + a: Foo, + b: Foo, + c: Bar, + d: Foo>, + e: Bar>, + f: Bar>, + g: Tuple, f32>, + h: Indirection +) { } diff --git a/tests/rust/monomorph-2.rs b/tests/rust/monomorph-2.rs index ed62d78..f81ea5b 100644 --- a/tests/rust/monomorph-2.rs +++ b/tests/rust/monomorph-2.rs @@ -9,7 +9,7 @@ struct A; struct B; #[no_mangle] -extern "C" fn foo(a: List) { } +pub extern "C" fn foo(a: List) { } #[no_mangle] -extern "C" fn bar(b: List) { } +pub extern "C" fn bar(b: List) { } diff --git a/tests/rust/monomorph-3.rs b/tests/rust/monomorph-3.rs index 23b8b2a..b1d69e4 100644 --- a/tests/rust/monomorph-3.rs +++ b/tests/rust/monomorph-3.rs @@ -16,12 +16,13 @@ union Tuple { type Indirection = Tuple; #[no_mangle] -extern "C" fn root(a: Foo, - b: Foo, - c: Bar, - d: Foo>, - e: Bar>, - f: Bar>, - g: Tuple, f32>, - h: Indirection) { -} +pub extern "C" fn root( + a: Foo, + b: Foo, + c: Bar, + d: Foo>, + e: Bar>, + f: Bar>, + g: Tuple, f32>, + h: Indirection +) { } diff --git a/tests/rust/simplify-option-ptr.rs b/tests/rust/simplify-option-ptr.rs index dc98146..b6e3f5b 100644 --- a/tests/rust/simplify-option-ptr.rs +++ b/tests/rust/simplify-option-ptr.rs @@ -16,8 +16,9 @@ union Bar { } #[no_mangle] -extern "C" fn root(a: Option<&Opaque>, - b: Option<&mut Opaque>, - c: Foo, - d: Bar) -{ } +pub extern "C" fn root( + a: Option<&Opaque>, + b: Option<&mut Opaque>, + c: Foo, + d: Bar +) { } diff --git a/tests/rust/static.rs b/tests/rust/static.rs index 0f8f6a9..2a81b15 100644 --- a/tests/rust/static.rs +++ b/tests/rust/static.rs @@ -1,5 +1,7 @@ -static NUMBER: i32 = 10; -static STRING: &'static libc::c_char = "hello world"; +#[no_mangle] +pub static NUMBER: i32 = 10; +#[no_mangle] +pub static STRING: &'static libc::c_char = "hello world"; #[repr(C)] struct Foo { @@ -8,8 +10,10 @@ struct Foo { struct Bar { } -static mut FOO: Foo = Foo { }; -static BAR: Bar = Bar { }; +#[no_mangle] +pub static mut FOO: Foo = Foo { }; +#[no_mangle] +pub static BAR: Bar = Bar { }; #[no_mangle] -extern "C" fn root() { } +pub extern "C" fn root() { } diff --git a/tests/rust/std_lib.rs b/tests/rust/std_lib.rs index 01d5abb..05e0f2a 100644 --- a/tests/rust/std_lib.rs +++ b/tests/rust/std_lib.rs @@ -1,5 +1,6 @@ #[no_mangle] -extern "C" fn root(a: &Vec, - b: &Option, - c: &Result) -{ } +pub extern "C" fn root( + a: &Vec, + b: &Option, + c: &Result +) { } diff --git a/tests/rust/struct.rs b/tests/rust/struct.rs index 649477f..5fb9f18 100644 --- a/tests/rust/struct.rs +++ b/tests/rust/struct.rs @@ -28,9 +28,10 @@ struct TupleRenamed(i32, f32); struct TupleNamed(i32, f32); #[no_mangle] -extern "C" fn root(a: *mut Opaque, - b: Normal, - c: NormalWithZST, - d: TupleRenamed, - e: TupleNamed) -{ } +pub extern "C" fn root( + a: *mut Opaque, + b: Normal, + c: NormalWithZST, + d: TupleRenamed, + e: TupleNamed +) { } diff --git a/tests/rust/typedef.rs b/tests/rust/typedef.rs index 7162f47..bf7ceb8 100644 --- a/tests/rust/typedef.rs +++ b/tests/rust/typedef.rs @@ -7,5 +7,5 @@ struct Foo { type IntFoo = Foo; #[no_mangle] -extern "C" fn root(a: IntFoo) +pub extern "C" fn root(a: IntFoo) { } diff --git a/tests/rust/union.rs b/tests/rust/union.rs index 7db29c3..b76f98a 100644 --- a/tests/rust/union.rs +++ b/tests/rust/union.rs @@ -20,7 +20,8 @@ union NormalWithZST { } #[no_mangle] -extern "C" fn root(a: *mut Opaque, - b: Normal, - c: NormalWithZST) -{ } +pub extern "C" fn root( + a: *mut Opaque, + b: Normal, + c: NormalWithZST +) { }