Gate generated registry helpers on dependency suite

This commit is contained in:
FredApps
2026-11-20 22:49:52 +01:00
parent 50e00dd493
commit 531d7bbd0f
4 changed files with 28 additions and 6 deletions
+16
View File
@@ -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)*) => {};
}
+8 -4
View File
@@ -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 _: () = {
+3 -1
View File
@@ -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()
+1 -1
View File
@@ -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;