Ability to invert feature<>dependency relationship? #8949
Labels
A-features
Area: features — conditional compilation
A-optional-dependencies
Area: dependencies with optional=true
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Describe the problem you are trying to solve
Not sure if this has been considered already, but with lots of optional features in a library, keeping track & remembering which dependencies are still relevant/in-use over time is complicated. The main traditional approach to this is either labor-intensive (remove all dependencies & start adding things back in one-by-one until things compile again) or error-prone (manually documenting the feature set a dependency applies to & hoping you don't make a mistake). The labor intensive approach is also made even more challenging for features as removing a dependency now needs to be tested across the entire set of selectable features (combinatorial explosion).
Describe the solution you'd like
Ideally the set of features an optional dependency is relevant can be tied to a list of features so that when a dependency isn't relevant anymore it's easily noticed. Similarly, the labor intensive approach can be made simpler since you know specifically which features you need to test when modifying that list.
Notes
I'm sure there's corner cases to consider (e.g. should the features still list the dependencies & thus the
for_features
list must be consistent with the other? if not, can you use a mix or is it only one or the other? etc). This is much more ergonomic than doing it manually:Ideally at some point Cargo could also warn you when a declared dependency was never even actually used by the code so that it would be easier to note when declared dependencies didn't match the code.
I would think cargo itself should be able to do a much more thorough job than external crates can.
The text was updated successfully, but these errors were encountered: