Files
continuwuity/src/macros/rustc.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
737 B
Rust
Raw Normal View History

2024-07-24 23:01:00 +00:00
use proc_macro::TokenStream;
use quote::quote;
2025-06-12 21:31:44 +00:00
use crate::utils::get_crate_name;
2024-07-24 23:01:00 +00:00
pub(super) fn flags_capture(args: TokenStream) -> TokenStream {
2025-06-12 21:31:44 +00:00
let Some(crate_name) = get_crate_name() else {
return args;
2024-07-24 23:01:00 +00:00
};
let flag = std::env::args().collect::<Vec<_>>();
let flag_len = flag.len();
2024-07-24 23:01:00 +00:00
let ret = quote! {
pub static RUSTC_FLAGS: [&str; #flag_len] = [#( #flag ),*];
2025-04-22 01:41:02 +00:00
#[tuwunel_core::ctor]
2024-07-24 23:01:00 +00:00
fn _set_rustc_flags() {
2025-04-22 01:41:02 +00:00
tuwunel_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
2025-04-22 01:41:02 +00:00
#[tuwunel_core::dtor]
2024-07-24 23:01:00 +00:00
fn _unset_rustc_flags() {
2025-04-22 01:41:02 +00:00
tuwunel_core::info::rustc::FLAGS.lock().expect("locked").remove(#crate_name);
2024-07-24 23:01:00 +00:00
}
};
ret.into()
}