diff --git a/src/bindgen/bitflags.rs b/src/bindgen/bitflags.rs index 6ca2452..6c89622 100644 --- a/src/bindgen/bitflags.rs +++ b/src/bindgen/bitflags.rs @@ -90,7 +90,7 @@ impl Flag { } = *self; quote! { #(#attrs)* - const #name : #struct_name = #struct_name { bits: #value }; + pub const #name : #struct_name = #struct_name { bits: #value }; } } } diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index 538d728..4fb84d6 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -691,6 +691,12 @@ impl Parse { let impl_path = ty.unwrap().get_root_path().unwrap(); for item in items.into_iter() { + if let syn::Visibility::Public(_) = item.vis { + } else { + warn!("Skip {}::{} - (not `pub`).", crate_name, &item.ident); + return; + } + let path = Path::new(item.ident.to_string()); match Constant::load( path, @@ -739,6 +745,12 @@ impl Parse { return; } + if let syn::Visibility::Public(_) = item.vis { + } else { + warn!("Skip {}::{} - (not `pub`).", crate_name, &item.ident); + return; + } + let path = Path::new(item.ident.to_string()); match Constant::load(path, mod_cfg, &item.ty, &item.expr, &item.attrs, None) { Ok(constant) => { diff --git a/tests/rust/assoc_const_conflict.rs b/tests/rust/assoc_const_conflict.rs index 26fe016..7907e32 100644 --- a/tests/rust/assoc_const_conflict.rs +++ b/tests/rust/assoc_const_conflict.rs @@ -1,7 +1,7 @@ #[repr(C)] struct Foo {} -const Foo_FOO: u32 = 42; +pub const Foo_FOO: u32 = 42; impl Foo { const FOO: i32 = 0; diff --git a/tests/rust/assoc_constant.rs b/tests/rust/assoc_constant.rs index 25a309e..57417ef 100644 --- a/tests/rust/assoc_constant.rs +++ b/tests/rust/assoc_constant.rs @@ -2,9 +2,12 @@ struct Foo {} impl Foo { - const GA: i32 = 10; - const BU: &'static str = "hello world"; - const ZO: f32 = 3.14; + pub const GA: i32 = 10; + pub const BU: &'static str = "hello world"; + pub const ZO: f32 = 3.14; + + pub(crate) const DONT_EXPORT_CRATE: i32 = 20; + const DONT_EXPORT_PRIV: i32 = 30; } #[no_mangle] diff --git a/tests/rust/const_conflict.rs b/tests/rust/const_conflict.rs index f31c392..041fecf 100644 --- a/tests/rust/const_conflict.rs +++ b/tests/rust/const_conflict.rs @@ -5,5 +5,5 @@ impl Foo { const FOO: i32 = 0; } -const Foo_FOO: u32 = 42; +pub const Foo_FOO: u32 = 42; diff --git a/tests/rust/const_transparent.rs b/tests/rust/const_transparent.rs index 23ce9c5..7032953 100644 --- a/tests/rust/const_transparent.rs +++ b/tests/rust/const_transparent.rs @@ -1,4 +1,4 @@ #[repr(transparent)] struct Transparent { field: u8 } -const FOO: Transparent = Transparent { field: 0 }; +pub const FOO: Transparent = Transparent { field: 0 }; diff --git a/tests/rust/constant.rs b/tests/rust/constant.rs index eb32bc7..548841d 100644 --- a/tests/rust/constant.rs +++ b/tests/rust/constant.rs @@ -1,12 +1,15 @@ -const FOO: i32 = 10; -const BAR: &'static str = "hello world"; +pub const FOO: i32 = 10; +pub const BAR: &'static str = "hello world"; pub const DELIMITER: char = ':'; pub const LEFTCURLY: char = '{'; pub const QUOTE: char = '\''; pub const TAB: char = '\t'; pub const NEWLINE: char = '\n'; pub const HEART: char = '❤'; -const ZOM: f32 = 3.14; +pub const ZOM: f32 = 3.14; + +pub(crate) const DONT_EXPORT_CRATE: i32 = 20; +const DONT_EXPORT_PRIV: i32 = 30; #[repr(C)] struct Foo { diff --git a/tests/rust/namespace_constant.rs b/tests/rust/namespace_constant.rs index ee67081..01a8450 100644 --- a/tests/rust/namespace_constant.rs +++ b/tests/rust/namespace_constant.rs @@ -1,6 +1,6 @@ -const FOO: i32 = 10; -const BAR: &'static str = "hello world"; -const ZOM: f32 = 3.14; +pub const FOO: i32 = 10; +pub const BAR: &'static str = "hello world"; +pub const ZOM: f32 = 3.14; #[repr(C)] struct Foo { diff --git a/tests/rust/namespaces_constant.rs b/tests/rust/namespaces_constant.rs index ee67081..01a8450 100644 --- a/tests/rust/namespaces_constant.rs +++ b/tests/rust/namespaces_constant.rs @@ -1,6 +1,6 @@ -const FOO: i32 = 10; -const BAR: &'static str = "hello world"; -const ZOM: f32 = 3.14; +pub const FOO: i32 = 10; +pub const BAR: &'static str = "hello world"; +pub const ZOM: f32 = 3.14; #[repr(C)] struct Foo { diff --git a/tests/rust/prefix.rs b/tests/rust/prefix.rs index 506e08b..a7bdc33 100644 --- a/tests/rust/prefix.rs +++ b/tests/rust/prefix.rs @@ -1,4 +1,4 @@ -const LEN: i32 = 42; +pub const LEN: i32 = 42; pub type NamedLenArray = [i32; LEN]; pub type ValuedLenArray = [i32; 42]; diff --git a/tests/rust/prefixed_struct_literal.rs b/tests/rust/prefixed_struct_literal.rs index 5a92ff0..1b8544d 100644 --- a/tests/rust/prefixed_struct_literal.rs +++ b/tests/rust/prefixed_struct_literal.rs @@ -5,10 +5,10 @@ struct Foo { } impl Foo { - const FOO: Foo = Foo{ a: 42, b: 47, }; + pub const FOO: Foo = Foo{ a: 42, b: 47, }; } -const BAR: Foo = Foo{ a: 42, b: 1337, }; +pub const BAR: Foo = Foo{ a: 42, b: 1337, }; #[no_mangle] pub extern "C" fn root(x: Foo) { } diff --git a/tests/rust/prefixed_struct_literal_deep.rs b/tests/rust/prefixed_struct_literal_deep.rs index dfadfdb..bfa2d8d 100644 --- a/tests/rust/prefixed_struct_literal_deep.rs +++ b/tests/rust/prefixed_struct_literal_deep.rs @@ -10,7 +10,7 @@ struct Bar { a: i32, } -const VAL: Foo = Foo { +pub const VAL: Foo = Foo { a: 42, b: 1337, bar: Bar { a: 323 }, diff --git a/tests/rust/rename.rs b/tests/rust/rename.rs index b5e3004..e89f0c3 100644 --- a/tests/rust/rename.rs +++ b/tests/rust/rename.rs @@ -31,7 +31,7 @@ type F = A; #[no_mangle] pub static G: i32 = 10; -const H: i32 = 10; +pub const H: i32 = 10; #[no_mangle] pub extern "C" fn root( diff --git a/tests/rust/struct_literal.rs b/tests/rust/struct_literal.rs index 00df8a1..733dac3 100644 --- a/tests/rust/struct_literal.rs +++ b/tests/rust/struct_literal.rs @@ -10,14 +10,14 @@ struct Bar { } impl Foo { - const FOO: Foo = Foo { a: 42, b: 47, }; - const FOO2: Self = Foo { a: 42, b: 47, }; - const FOO3: Self = Self { a: 42, b: 47, }; - const BAZ: Bar = Bar { a: 42, b: 47, }; + pub const FOO: Foo = Foo { a: 42, b: 47, }; + pub const FOO2: Self = Foo { a: 42, b: 47, }; + pub const FOO3: Self = Self { a: 42, b: 47, }; + pub const BAZ: Bar = Bar { a: 42, b: 47, }; } -const BAR: Foo = Foo { a: 42, b: 1337, }; -const BAZZ: Bar = Bar { a: 42, b: 1337, }; +pub const BAR: Foo = Foo { a: 42, b: 1337, }; +pub const BAZZ: Bar = Bar { a: 42, b: 1337, }; #[no_mangle] pub extern "C" fn root(x: Foo, bar: Bar) { }