-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add support for "default" features #6572
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
Comments
This already exists, and is called |
Indeed. Going to assume you just missed this part of the docs, @almindor. Let me know if you meant something else. |
@almindor I wouldn't call it Another Idea I have is some other kind of features (let's call them backends), which just work like features, but you are only allowed to select exactly one, like this:
If your apllication supports multiple kinds of backends, it could look like this:
These features could still be specified by using "--features", but in case no default is specified, cargo will not even start compiliation. |
Or some more general way: add a way to make specific features incompatible. |
As @porky11 said this is something else than you think. It's a way to have an feature pre-selected if a user doesn't specify one but only if they don't specify one. Default does not get "deselected" when you select a specific feature as far as I know. |
@dwijnand sorry forgot to flag you, see above. The issue is different than you think |
I see, thanks for the detail. |
I have the same requirement and I think these can be considered as enum feature flags, where one needs to select one feature flag of a group, and if no one is selected, a default one should be used. |
Am I correct that this is just #2980 with a specific solution? |
For providing default, people can do it today with explicit #[cfg(not(any(feature = "backend1", feature = "backend2")))]
mod backend {
// my default backend implementation
}
I think so. Going to close this promptly because I feel like we need to take the entire context of mutually exclusive features into account. For further discussions, please follow #2980. Thanks. |
Describe the problem you are trying to solve
When building libraries that have backends in them using
--features
flag in combination with the feature dependencies, it would be very useful to have a "no feature selected" configuration option so a "default" backend can be chosen.Describe the solution you'd like
Either something like
If the user just does
cargo build
or doesn't specify a feature list in their dependency definition for this crate they will getbackend2
selected by default as if they did--features backend2
. Same would happen for a project using this crate and not specifyingfeatures =
in their dependency definition.The other way of doing this could be to provide a
#[cfg(nofeatures)]
in case no features were chosen so that it could be used to provide a default in code.A more thorough design might be desirable however. Possibly with groups of features so that a default is tied only to "lack" of some features, but not all.
For example consider a project providing
backend1, backend2, non_backend_feature
as features. Ifnon_backend_feature
is chosen it shouldn't override the default in this case for the backend choice.Having groups of features could make this possible.
Notes
The text was updated successfully, but these errors were encountered: