From 6aff4cb1dde37c675619c5037dae478e92d1103d Mon Sep 17 00:00:00 2001 From: FredApps Date: Thu, 19 Nov 2026 14:37:53 +0100 Subject: [PATCH] Honor inner module conditions in registry discovery --- crates/ui-macros/src/registry.rs | 13 ++++++++++++- crates/ui-macros/tests/fixtures/registry/child.rs | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/ui-macros/src/registry.rs b/crates/ui-macros/src/registry.rs index 53bf34e0c..5dc543577 100644 --- a/crates/ui-macros/src/registry.rs +++ b/crates/ui-macros/src/registry.rs @@ -17,7 +17,15 @@ impl Parse for FirstType { } fn attrs_cfg(attrs: &[Attribute]) -> Vec { - attrs.iter().filter(|a| a.path().is_ident("cfg") || a.path().is_ident("cfg_attr")).cloned().collect() + attrs + .iter() + .filter(|a| a.path().is_ident("cfg") || a.path().is_ident("cfg_attr")) + .cloned() + .map(|mut attr| { + attr.style = syn::AttrStyle::Outer; + attr + }) + .collect() } fn derives(attrs: &[Attribute], wanted: &str) -> bool { @@ -129,6 +137,7 @@ fn walk( .map_err(|e| syn::Error::new_spanned(module, format!("cannot read {}: {e}", file.display())))?; let parsed = syn::parse_file(&text).map_err(|e| syn::Error::new_spanned(module, format!("cannot parse {}: {e}", file.display())))?; + cfg.extend(attrs_cfg(&parsed.attrs)); let child_dir = if file.file_name().is_some_and(|n| n == "mod.rs" || n == "main.rs" || n == "lib.rs") { file.parent().unwrap_or(dir).to_path_buf() } else { @@ -248,6 +257,8 @@ mod tests { assert!(generated.contains("__registry_story_view")); assert!(generated.contains("__registry_trial_changes")); assert!(generated.contains("__registry_trial_path_trial")); + assert!(generated.contains("cfg (not (target_arch = \"wasm32\"))")); + assert!(!generated.contains("# !")); } } } diff --git a/crates/ui-macros/tests/fixtures/registry/child.rs b/crates/ui-macros/tests/fixtures/registry/child.rs index 58ec79e0f..832cf8638 100644 --- a/crates/ui-macros/tests/fixtures/registry/child.rs +++ b/crates/ui-macros/tests/fixtures/registry/child.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_arch = "wasm32"))] + #[story(Widget)] fn view() {}