Allow enabling a dependency if a feature is *off* #14188
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-triage
Status: This issue is waiting on initial triage.
Problem
Disclaimer: this looks like "mutually exclusive features" but it's not really the same thing. Dependencies are not mutually exclusive.
This situation came up a few times in my experience. Let's say there are three crates:
consumer
,powerful
andminimal
and the latter two provide similar functionality exceptpowerful
is much bigger and may even involve FFI (written in C).consumer
would like to depend on either of them and provide unified API that's just extended by depending onpowerful
, so users who don't need extra features would not incur the cost of compilingpowerful
and users who depend onpowerful
would not incur the cost ofminimal
. Some practical examples:secp256k1
crate to add partial pure-Rust implementation. This implementation needs au256
type which happens to be the same code as one of the downstream dependencies uses already. Ideally, it'd be a shared crate but that would force compilation ofu256
even when the C implementation is used for all other crates.cc
crate if they're compiling the bindings but don't really need it if they're just linking.no_std
crates requiring equivalent ofstd::io
traits but wanting to work withstd
traits too. E.g. using thecore2
crate.All current solutions to this have their problems:
compile_error!
if both are off. I've seen this done forcore2
it was super horrible to work with in library dependencies because they had to propagate this thing downwards, they were annoying to test and if someone accidentally enabled both then both would get compiled without any warning. (And in some edge cases it even caused breakage.)minimal
unconditionally, optionally havepowerful
- wastes compile timeminimal
intoconsumer
as a module and conditionally disable the module. Saves compile time in some cases but makes it worse in others. Also forces the maintainers to manually sync the versions.Proposed Solution
Allow specifying this:
When the feature
extra
is disabled thepowerful
dependency is activated. When it's disabled,minimal
is activated. Activating bothminimal
andpowerful
via other means is allowed in which case both dependencies get included. Perhaps this could issue a warning though.Notes
No response
The text was updated successfully, but these errors were encountered: