-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo metadata
should be able to ignore dev-dependencies for better feature resolution
#10718
Comments
I'm having a hard time seeing how we would implement What it sounds like you are wanting is for |
Update: It appears that this is a problem only for workspace members. #7754 tracks that separately. |
I do think a flag to not imply all-targets would be good either way in general i find cargo-tree's flag approach to be really good here (wondering if we can just get cargo-tree to have a machine readable output that's similar to metadata's one) |
Out of curiosity, I looked at what Setting dep kinds has two different effects
In my earlier answer, I had assumed we would completely respect the specified dep kinds for feature unification. Only partially respecting them is then doable. As for the removing of dependency edges, we've had several requests for different application-specific queries / filtering of data for |
Problem
cargo metadata
includes both normal dependencies and dev-dependencies, distinguishing them with either"kind": null
or"kind": "dev"
in the dependency list for a package.The problem is when there is a package that is used as both a normal dependency and as a dev-dependency with different sets of features. For example, consider the following packages:
In this setup,
cargo metadata
will happily enable the "dev_only" feature ofpackage_d
, resulting insome_big_dep
and all of its dependencies being included in the output.This is undesirable because:
cargo metadata
need to do a lot of work to track which features are used when; this is somethingcargo metadata
should do automatically.Proposed Solution
Add the following flag to
cargo metadata
:--dep-kinds
: only include the selected dependency kinds. Options (multiple can be specified):all
(default)normal
build
dev
This is similar to the
--edges
flag incargo tree
. If desired, theno-normal
,no-build
, andno-dev
options could be included in order for more complete parity betweencargo metadata
andcargo tree
.If
cargo metadata --dep-kinds normal
were run on the example above, thensome_big_dep
should be fully dropped from the output, as if I deleted it from the Cargo.toml file.Notes
The
--no-default-features
and--features
flags oncargo metadata
have extremely limited use with the limitation of not being able to ignore dev-dependencies. Projects that are careful about their dependencies and feature sets are the ones that benefit most from those flags, but any dev-dependency anywhere in the tree may still enable an undesired feature.CC @Manishearth
The text was updated successfully, but these errors were encountered: