2024-07-24 23:01:00 +00:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use quote::quote;
|
|
|
|
|
|
|
|
pub(super) fn flags_capture(args: TokenStream) -> TokenStream {
|
|
|
|
let cargo_crate_name = std::env::var("CARGO_CRATE_NAME");
|
|
|
|
let crate_name = match cargo_crate_name.as_ref() {
|
|
|
|
Err(_) => return args,
|
|
|
|
Ok(crate_name) => crate_name.trim_start_matches("conduit_"),
|
|
|
|
};
|
|
|
|
|
|
|
|
let flag = std::env::args().collect::<Vec<_>>();
|
2024-07-27 20:55:21 +00:00
|
|
|
let flag_len = flag.len();
|
2024-07-24 23:01:00 +00:00
|
|
|
let ret = quote! {
|
2024-07-27 20:55:21 +00:00
|
|
|
pub static RUSTC_FLAGS: [&str; #flag_len] = [#( #flag ),*];
|
|
|
|
|
2024-07-24 23:01:00 +00:00
|
|
|
#[conduit_core::ctor]
|
|
|
|
fn _set_rustc_flags() {
|
2024-07-27 20:55:21 +00:00
|
|
|
conduit_core::info::rustc::FLAGS.lock().expect("locked").insert(#crate_name, &RUSTC_FLAGS);
|
2024-07-24 23:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static strings have to be yanked on module unload
|
|
|
|
#[conduit_core::dtor]
|
|
|
|
fn _unset_rustc_flags() {
|
|
|
|
conduit_core::info::rustc::FLAGS.lock().expect("locked").remove(#crate_name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ret.into()
|
|
|
|
}
|