-
Notifications
You must be signed in to change notification settings - Fork 2.6k
The cargo metadata --filter-platform
flag defaults to $CARGO_BUILD_TARGET
and can't be overridden
#15270
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
Labels
Comments
I don't think it was intentional. I believe this regressed in #8167 which changed metadata to call |
egad I must atone for my sins |
github-merge-queue bot
pushed a commit
that referenced
this issue
Mar 6, 2025
This commit fixes a (five year old!) regression in `cargo metadata` where if `--filter-platform` isn't explicitly specified it will accidentally read `$CARGO_BUILD_TARGET` (or `build.target` configuration) and use that as the default `--filter-platform`. The reason for this is that the calculation for targets changed in #8167 and while the shared function makes sense for other commands such as `cargo build` the targets have a different meaning in `cargo metadata` so a slightly different set of functionality is desired. This commit fixes the issue by introducing a new constructor for the list of `CompileKind` variants where the fallback of "if nothing is specified" is explicitly chosen. Closes #15270 <!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Today the
--filter-platform
flag to thecargo metadata
subcommand defaults to$CARGO_BUILD_TARGET
or the configuration ofbuild.target
within.cargo/config.toml
. This behavior does not appear to be overridable (or I'm also perhaps missing something in which case this issue is moot), meaning that if a tool wants to executecargo metadata
specifically without a platform filter then there's no way for the tool to opt-in to that behavior.This issue is downstream of mozilla/cargo-vet#652 where the bug doesn't actually lie in that repository, but rather in the interaction of the various features in play here. In short
cargo vet
runscargo metadata
to learn about the crate graph and generally wants all information about all platforms. Locally I havebuild.target
configured in.cargo/config.toml
, however, which means that the results ofcargo vet
are subtly different on my machine. This discrepancy in behavior was the source of the original bug report.To reproduce this behavior while I'm sure it can be minimized further I can see this with the wasmtime repository:
Effectively
--filter-platform
, as expected, changes the output ofcargo metadata
. TheCARGO_BUILD_TARGET
then affects this by default so even when--filter-platform
isn't passed it produces the same output as-if it were passed.I'll note that I'm assuming that the behavior of reading
CARGO_BUILD_TARGET
is intentional, but I also realize that may also not be intentional. If it's not intentional, then that's also a possible fix to this! If it is intentional, then this would boil down to a feature request to have a CLI flag for something like--filter-platform all
to explicitly request, regardless of other configuration, that no filter be applied.The text was updated successfully, but these errors were encountered: