From 531d7bbd0fabad394b34da69ced22bb902a836ed Mon Sep 17 00:00:00 2001 From: FredApps Date: Fri, 20 Nov 2026 22:49:52 +0100 Subject: [PATCH] Gate generated registry helpers on dependency suite --- crates/ui-contract/src/lib.rs | 16 ++++++++++++++++ crates/ui-macros/src/component.rs | 12 ++++++++---- crates/ui-macros/src/lib.rs | 4 +++- crates/ui/src/lib.rs | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/crates/ui-contract/src/lib.rs b/crates/ui-contract/src/lib.rs index 418ddd0ee..07d8990d0 100644 --- a/crates/ui-contract/src/lib.rs +++ b/crates/ui-contract/src/lib.rs @@ -29,3 +29,19 @@ pub mod __private { pub use egui; pub use inventory; } + +/// Emits generated suite-only items when this dependency enables the suite. +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "suite")] +macro_rules! __suite_items { + ($($item:item)*) => { $($item)* }; +} + +/// Discards generated suite-only items in fixture-only consumers. +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "suite"))] +macro_rules! __suite_items { + ($($item:item)*) => {}; +} diff --git a/crates/ui-macros/src/component.rs b/crates/ui-macros/src/component.rs index 65c236eed..de48e3f15 100644 --- a/crates/ui-macros/src/component.rs +++ b/crates/ui-macros/src/component.rs @@ -236,8 +236,10 @@ fn registrations(k: &TokenStream, types: &[Type], declared: &Declared, shape: Sh let helper = registry_helper(types)?; Ok(quote! { #gate - pub(crate) fn #helper(registry: &mut #k::testing::Registry) { - #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + #k::__suite_items! { + pub(crate) fn #helper(registry: &mut #k::testing::Registry) { + #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + } } // Outside the gate: the sample exists in every build, so it is never dead code where the registration is absent. @@ -261,8 +263,10 @@ pub(crate) fn pattern_registrations(k: &TokenStream, types: &[Type], purpose: &s }; quote! { #gate - pub(crate) fn #helper(registry: &mut #k::testing::Registry) { - #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + #k::__suite_items! { + pub(crate) fn #helper(registry: &mut #k::testing::Registry) { + #(registry.add_registration(<#types as #k::testing::Registered>::registration());)* + } } #gate const _: () = { diff --git a/crates/ui-macros/src/lib.rs b/crates/ui-macros/src/lib.rs index dbb092ee4..5eca7a646 100644 --- a/crates/ui-macros/src/lib.rs +++ b/crates/ui-macros/src/lib.rs @@ -266,7 +266,9 @@ pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { #func #gate - pub(crate) fn #helper() -> #k::testing::StoryRegistration { #registration } + #k::__suite_items! { + pub(crate) fn #helper() -> #k::testing::StoryRegistration { #registration } + } } .into() diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index b66112c99..6ac1521ca 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -23,7 +23,7 @@ pub use craft_ui_canvas::{canvas, canvas_controls, dialog}; #[cfg(feature = "testing")] pub use craft_ui_contract::registry; #[doc(hidden)] -pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern}; +pub use craft_ui_contract::{__private, __register_command_set, __register_contract, __register_pattern, __suite_items}; pub use craft_ui_contract::{InstallError, InstallSpec, contract, fonts, install, layout, primitives, runtime, style, words}; pub use craft_ui_panels::{docking, rails, sections}; pub use craft_ui_shell::shell;