-
Notifications
You must be signed in to change notification settings - Fork 91
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
Allow banning or requiring specific features. #226
Comments
We've had similar problems as well, usually with regards to |
Another example usecase: using crates like [[bans.deny]]
name = "tokio"
deny-features = ["rt-core", "io-driver", "time"] |
I would start with this if it is not blocked by anything. |
I don't believe it is blocked by anything, go for it! |
Is your feature request related to a problem? Please describe.
In #225 I mentioned a case where a particular feature was banned. It would be good to be able to ban X crate ever from appearing while the feature is enabled. Some examples:
Certain parts of the
regex-syntax
unicode tables take up many megabytes for obscure regex features.For a period of time in https://github.com/mozilla/application-services/ we had a feature where networking requests could be made through reqwest instead of via necko (gecko/Firefox's network engine).
This was used for firefox-ios (which has no gecko), but shipping this to users on other platforms would have been considered a massive problem.
We ultimately resolved it by switching from a feature-based solution to one where you pull in a reqwest backend and manually enable it. This feels more reliable given how features work.
In general features are well-known to be something that can easily be enabled at a distance by accident, and easily fail to be enabled by a misphrased cargo invocation (
cargo build -p --features
in workspaces does not respect the features you provide it -- although --all-features does). Some way of getting a handle here seems desirable.Describe the solution you'd like
This is tricky a bit. Here's one way you could do it, but it's sort of bolting it on, and maybe extending the model somehow is better. Also, I'm not tied to names.
Solution high level.
deny-features
to[ban.deny]
records, which only match if there's a feature in the final crate which is in the deny-features listallow-features
to[ban.deny]
records, which match if there's a feature in the final crate which isn't part of the allowlistexact-features
to[ban.deny]
records, which makesallow-features
strict -- if this is true, then allow-features must be the exact featureset of the final crate.Some examples:
Algorithm
Note that by "the deny block matches" I mean: the crate is denied unless allowed by some other mechanism (skip, for example). Of course, if the deny block fails to match (e.g. the crate is accepted), the crate still may be denied if another deny block happens to match. Also, feature sets are, of course, not sensitive to order. (["A", "B", "C"] and ["C", "B", "A"] are the same).
CF
be the final set of features for the indicated crate in the final crate graph.D
be a record inbans.deny
which otherwise applies to the crate (not excluded by version, for example).DF
beD.deny-features
if present, and the empty set otherwise.D.exact-features
is true:AF
beD.allow-features
if present, or the empty set if missing.AF
andCF
are identical sets thenD
does not apply (e.g. crate accepted, but see above)AF
andCF
differ, thenD
does apply (e.g. crate denied, but see above).D.exact-features
is false or missing:D.allowed-features
is missing, then all features are considered allowed.AF
beD.allow-features
CF
is a subset ofAF
, thenD
does not apply (accepted), otherwise D applies (denied)Edge cases
When loading a given
[[ban.deny]]
record, if any string is in bothdeny-features
andallow-features
, emit an error.It is legal for the feature lists to refer to features which do not exist. They behave the same -- e.g. if a user requires a feature and the crate does not offer that feature, they have to figure it out.
For clarity:
allow-features
behaves similarly tobans.allow
in that when not allowed it does not filter, and if it is provided it is very strict.exact-features
is true andallow-features
is missing, it's the same asexact-features=true
andallow-features=[]
-- all features are denied.Describe alternatives you've considered
See beginning. Scripts and avoiding the problem.
Additional context
N/A
The text was updated successfully, but these errors were encountered: