cargo metadata
's resolved
output includes features from all packages in workspace, cannot be filtered.
#12735
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-metadata
S-triage
Status: This issue is waiting on initial triage.
Problem
I'm working on a tool that wraps multiple
cargo build
invocations and trying to make a progress bar for the overall output. Towards this end, I need to know, for each invocation, how many artifacts it needs to build, which I believe is the point of thecargo metadata
command (and correspondingcargo_metadata
crate that wraps it for Rust).The problem is that I'm building in a workspace where I have something like the following setup:
a
feature is supplied.a
feature.a
feature.When I run
cargo metadata
, it builds the dependency tree for the entire workspace, so I see that Crate B depends on Crate A (because Crate D requires the feature, and features are additive). However, when I runcargo build -p C
to only build Crate C, the feature is not enabled (because Crate D doesn't appear) so only crates B and C are built. Thus, naively reading the dependency tree provided says 3 crates, but then cargo build only reports 2 crates.The docs for
cargo metadata
say the following about how it decides which features are enabled:I want to set this "current package" to Crate C, which will set the features based on that. However, as far as I can tell,
cargo metadata
always sets this "current package" to be every package in the workspace, and it takes all the features from combining every crate. This even happens if I use--manifest-path
to explicitly specify theCargo.toml
file from Crate C.Proposed Solution
My preferred interface would be to add a
--package
option tocargo metadata
which allows you to explicitly filter packages in the workspace, repeatable if you want to have multiple packages at the root of your dependency tree.If combined with
--no-deps
, then only the explicitly-listed packages are included in the output. Otherwise, it outputs the listed packages and all of their transitive dependencies, from the workspace or from outside. I primarily care about theresolve
field, and don't care much how this interacts with thepackages
field.If only one
--package
argument is required, then any features listed in a--features
argument applies to that one package (e.g.cargo metadata --package my_package --features foo,bar
will enable thefoo
andbar
features ofmy_package
).Beyond those two, I think the interactions with the other existing flags and arguments are straightforward and uncomplicated.
Notes
Coming from this rust-users forum thread, I assume what I want isn't currently possible based on the lack of responses, please correct me if I'm wrong.
The text was updated successfully, but these errors were encountered: