Feature specification using wildcard

I wonder if the following is possible, (if not, I'd like to see it supported in the future):

[features]
default = [std]
std = ["*/std"] 

Concretely, */std enables the std feature on all its dependency who has this feature flag (i.e. with the same name), and ignore those that don't.

Background

I came to this feature request when I try to refactor my rust library to support no_std.
Now it seems idiomatic and common practice that most of my dependencies have a std features that I could turn on in normal circumstances, but specifying them individually like ["foo/std", "bar/std", ...,] is really not ideal.

I prefer not. How many std features do you need? Three? Six? Ten? But you only need to write them down only once. And everything is clear for everyone.

2 Likes

AFAIK, this is not possible (at least it is not documented in the Cargo Book). I also couldn't find a feature request issue in the Cargo repo that would describe that behaviour. Only feature requests for enabling all features of a single dependency, not enabling a single feature on all dependencies:

I don't have any authority on this, but I'd be on @vague's side and oppose such a feature request. It may be convenient at first, but could have unwanted side effects and is much harder to reason about. I'd definitely prefer the verbosity of enabling the feature for every dependency explicitly. That'd allow me to know just from reading your manifest file what dependencies have the std feature enabled and I wouldn't have to sift through all your dependencies and see which one even has such a feature.

Enabling the * glob pattern in dependency feature declarations would also be weird given that you already can use ? in your dependency feature declaration. ? in glob patterns normally matches any single character. In the dependency declaration, ? behind the dependency name means that the dependency is still optional and not enabled, unless the user enables it explicitly (i.e. with another feature). Something like *?/std looks like a broken glob pattern to me and makes it even harder to understand the meaning behind this expression.

Having said all this, you can of course ask the people that do have authority on this, whether they would consider such a feature. I don't know where best to start such a conversation, but I'd assume IRLO, Zulip or an issue would all be good places to reach the Cargo maintainers.

2 Likes

if I have 20 dependencies, all following the idiomatic no_std pattern, then I'd specify 20.

Yeah, it seems people don't like this at all, signal received. I do agree that being more explicit might be clearer.
I don't have a strong opinion here either, just thought such sugarcoat short-hand is convenient.

Thanks for the input (also @jofas for the more detailed argument)

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.