diff --git a/perlmod-macro/src/attribs.rs b/perlmod-macro/src/attribs.rs index d439a91..13979a6 100644 --- a/perlmod-macro/src/attribs.rs +++ b/perlmod-macro/src/attribs.rs @@ -8,6 +8,7 @@ pub struct ModuleAttrs { pub file_name: Option, pub lib_name: Option, pub write: Option, + pub boot: Option, } fn is_ident_check_dup(path: &syn::Path, var: &Option, what: &'static str) -> bool { @@ -29,6 +30,7 @@ impl TryFrom for ModuleAttrs { let mut file_name = None; let mut lib_name = None; let mut write = None; + let mut boot = None; for arg in args { match arg { @@ -43,6 +45,8 @@ impl TryFrom for ModuleAttrs { file_name = Some(expand_env_vars(&litstr)?); } else if is_ident_check_dup(&path, &lib_name, "lib") { lib_name = Some(expand_env_vars(&litstr)?); + } else if is_ident_check_dup(&path, &boot, "boot") { + boot = Some(litstr.parse::()?); } else { error!(path => "unknown argument"); } @@ -70,6 +74,7 @@ impl TryFrom for ModuleAttrs { file_name, lib_name, write, + boot, }) } } diff --git a/perlmod-macro/src/package.rs b/perlmod-macro/src/package.rs index 04e000b..ac62fda 100644 --- a/perlmod-macro/src/package.rs +++ b/perlmod-macro/src/package.rs @@ -107,6 +107,11 @@ impl Package { let bootstrap_name = format!("boot_{}", self.attrs.package_name).replace("::", "__"); let bootstrap_ident = Ident::new(&bootstrap_name, Span::call_site()); + let boot = match &self.attrs.boot { + Some(boot) => quote! { #boot(); }, + None => TokenStream::new(), + }; + quote! { #[no_mangle] pub extern "C" fn #bootstrap_ident( @@ -123,6 +128,8 @@ impl Package { #newxs } }); + + #boot } } }