diff --git a/crates/swift-bridge-ir/src/codegen/generate_rust_tokens.rs b/crates/swift-bridge-ir/src/codegen/generate_rust_tokens.rs index 5cefc103..ce6a38c7 100644 --- a/crates/swift-bridge-ir/src/codegen/generate_rust_tokens.rs +++ b/crates/swift-bridge-ir/src/codegen/generate_rust_tokens.rs @@ -18,6 +18,7 @@ mod vec; impl ToTokens for SwiftBridgeModule { fn to_tokens(&self, tokens: &mut TokenStream) { let mod_name = &self.name; + let vis = &self.vis; let swift_bridge_path = &self.swift_bridge_path; let mut extern_rust_fn_tokens = vec![]; @@ -298,7 +299,7 @@ impl ToTokens for SwiftBridgeModule { let t = quote! { #[allow(non_snake_case)] #(#module_attributes)* - mod #mod_name { + #vis mod #mod_name { #module_inner } }; @@ -1045,4 +1046,20 @@ mod tests { &expected_fn, ); } + + /// Verify that we apply the module's visibility to the output. + #[test] + fn module_visibility() { + let start = quote! { + pub(super) mod foo { + } + }; + let expected = quote! { + #[allow(non_snake_case)] + pub(super) mod foo { + } + }; + + assert_tokens_eq(&parse_ok(start).to_token_stream(), &expected); + } } diff --git a/crates/swift-bridge-ir/src/lib.rs b/crates/swift-bridge-ir/src/lib.rs index 80d744b5..0df20ce3 100644 --- a/crates/swift-bridge-ir/src/lib.rs +++ b/crates/swift-bridge-ir/src/lib.rs @@ -8,7 +8,7 @@ #![deny(missing_docs)] use proc_macro2::Ident; -use syn::Path; +use syn::{Path, Visibility}; use crate::bridge_module_attributes::CfgAttr; use crate::parse::TypeDeclarations; @@ -58,6 +58,7 @@ const SWIFT_BRIDGE_PREFIX: &'static str = "__swift_bridge__"; /// ``` pub struct SwiftBridgeModule { name: Ident, + vis: Visibility, types: TypeDeclarations, functions: Vec, swift_bridge_path: Path, diff --git a/crates/swift-bridge-ir/src/parse.rs b/crates/swift-bridge-ir/src/parse.rs index 62322c5f..093cf083 100644 --- a/crates/swift-bridge-ir/src/parse.rs +++ b/crates/swift-bridge-ir/src/parse.rs @@ -57,6 +57,7 @@ impl Parse for SwiftBridgeModuleAndErrors { if let Ok(item_mod) = input.parse::() { let module_name = item_mod.ident; + let vis = item_mod.vis; let mut functions = vec![]; let mut type_declarations = TypeDeclarations::default(); @@ -125,6 +126,7 @@ impl Parse for SwiftBridgeModuleAndErrors { let module = SwiftBridgeModule { name: module_name, + vis, types: type_declarations, functions, swift_bridge_path: syn::parse2(quote! { swift_bridge }).unwrap(),