diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-29 13:02:56 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-29 13:02:56 +0800 |
| commit | 2d2eef2770025b5fe7db3f1e36e2dc7daede16ca (patch) | |
| tree | 632f4e0a46f3bdd273ba6831bbf2bb00f94f42be /mingling_macros | |
| parent | 8dfdc48d8d781f47d4a3206a1b8400110b593045 (diff) | |
refactor(macros): reorganize module structure and parse pathf include
inline
Instead of using `include!` with generated paths, read the file at
compile time and parse it into a token stream during macro expansion.
Diffstat (limited to 'mingling_macros')
| -rw-r--r-- | mingling_macros/src/lib.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 8955b37..43747aa 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -164,8 +164,6 @@ mod enum_tag; mod group_impl; mod groupped; mod help; -#[cfg(feature = "structural_renderer")] -mod structural_data; mod node; mod pack; #[cfg(feature = "extra_macros")] @@ -175,6 +173,8 @@ mod program_setup; mod render; mod renderer; mod res_injection; +#[cfg(feature = "structural_renderer")] +mod structural_data; #[cfg(feature = "comp")] mod suggest; @@ -1816,7 +1816,10 @@ pub fn program_final_gen(_input: TokenStream) -> TokenStream { let chain_exist = get_global_set(&CHAINS_EXIST).lock().unwrap().clone(); #[cfg(feature = "structural_renderer")] - let structural_renderers = get_global_set(&STRUCTURAL_RENDERERS).lock().unwrap().clone(); + let structural_renderers = get_global_set(&STRUCTURAL_RENDERERS) + .lock() + .unwrap() + .clone(); #[cfg(feature = "comp")] let completions = get_global_set(&COMPLETIONS).lock().unwrap().clone(); @@ -2038,8 +2041,21 @@ pub fn program_final_gen(_input: TokenStream) -> TokenStream { }; let pathf_include = if cfg!(feature = "pathf") { - quote! { - include!(concat!(env!("OUT_DIR"), "/", env!("CARGO_PKG_NAME"), "/type_using.rs")); + let out_dir = std::env::var("OUT_DIR").ok(); + let crate_name = std::env::var("CARGO_PKG_NAME").ok(); + + match (out_dir, crate_name) { + (Some(dir), Some(name)) => { + let path = std::path::Path::new(&dir).join(&name).join("type_using.rs"); + match std::fs::read_to_string(&path) { + Ok(content) => { + let tokens: proc_macro2::TokenStream = content.parse().unwrap_or_default(); + tokens + } + Err(_) => quote! {}, + } + } + _ => quote! {}, } } else { quote! {} @@ -2130,7 +2146,10 @@ pub fn program_final_gen(_input: TokenStream) -> TokenStream { .unwrap() .clear(); #[cfg(feature = "structural_renderer")] - get_global_set(&STRUCTURAL_RENDERERS).lock().unwrap().clear(); + get_global_set(&STRUCTURAL_RENDERERS) + .lock() + .unwrap() + .clear(); TokenStream::from(expanded) } |
