Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature gating subsystems via #[cfg] #41

Merged
merged 29 commits into from
Mar 29, 2023

Conversation

skunert
Copy link
Contributor

@skunert skunert commented Mar 27, 2023

In this PR I introduce guarding of subsystems via features.
Supported syntax:

#[orchestra(signal=Signal, event=ExternalEvent, error=SubsystemError, gen=AllMessages)]
struct MyOverseer<T, U, V, W> {
	#[cfg(feature = "feature1")]
	#[subsystem(consumes: Subsystem1Message, sends: [Subsystem2Message])]
	subsystem1: Sub1,

	#[subsystem(consumes: Subsystem2Message, sends: [Subsystem1Message])]
	subsystem2: Sub2,
}

Basically this allows re-use of one orchestra in scenarios where it is not needed to run all subsystems. The #cfg attribute macro currently supports any, all, not and feature = "something".

Limitations

  • Feature unification. The current implementation is not very useful when you have a large workspace, and different crates depend on the defined orchestra with different features enabled.

  • Performance depends on the number of unique cfg expressions defined in the crate. With the current design of the orchestra builder, I have to build distinct feature combinations for the builder. This scales with O(2^n) where n is the number of distinct feature expressions. I tested a bit and impact is starting to show at around 7 different feature expressions.

@skunert skunert requested a review from drahnr March 27, 2023 11:47
@@ -15,6 +15,7 @@ declarative.
#[subsystem(MsgA, sends: [MsgB])]
sub_a: AwesomeSubSysA,

#[cfg(any(feature = "feature1", feature = "feature2"))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

assert_eq!("any (not (feature = \"no\") , any (feature = \"any2\" , feature = \"any1\") , all (feature = \"f2\" , feature = \"f1\" , feature = \"f3\"))"
, to_parse.to_token_stream().to_string());
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very nice.

Copy link
Collaborator

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small nits, generally looks very good!

Q: do we want to allow arbitrary #[] macros eventually? I.e. copying derive over to the generated struct only and keeping any other ones on all items. But that's for another time I think.

@skunert
Copy link
Contributor Author

skunert commented Mar 28, 2023

Q: do we want to allow arbitrary #[] macros eventually? I.e. copying derive over to the generated struct only and keeping any other ones on all items. But that's for another time I think.

Not sure I understand, how could this be used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants