Pre-Pre-RFC: making `std`-dependent Cargo features a first-class concept

I have experience as a Gentoo developer, where we have the concept of USE flags for our package ebuild scripts. I think there's a lot Cargo could learn from such systems to evolve the functionality of features, which honestly feels very MVP now.

I think this is all kind of skating around the issue that the additivity property is unnecessarily restrictive. Instead we could allow negative dependencies (strawman syntax) like !std, which would request a build that doesn't have that property or errors out if another dependency in the tree requires std.

Gentoo also maintains a limited list of "global" USE flags in addition to the package-specific flags. These basically get extracted as we go when we encounter a flag that's used across a bunch of packages with the same meaning, and then you can set a global value for it. If we bake in a short list of global features like std, alloc and maybe things like serde, I think that would go a long way towards helping with this.

(I've also occasionally wanted something like Gentoo's REQUIRED_USE, which allows more complex restrictions of what flags can be used together. For example, this would allow enforcing mutual exclusion of some feature flags, which could help for example with keeping dependency trees for those features from conflicting -- I guess this would require extensions to the Cargo.lock format.)

7 Likes