-
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 downloads crate files for unused targets #8981
Comments
Arguably the same bug exists in cargo/src/cargo/ops/cargo_fetch.rs Lines 40 to 44 in 862df61
|
Hmm, this will be complicated by the fact that for |
Sorry I'm still catching up on the issues so if this is irrelevant by this point ignore me, but I believe this is intentional. Without |
Ah, sorry missed your question: Yes, the bug here is that My point above was more that since the default for |
Make cargo metadata and tree respect target Previously, the `metadata` and `tree` subcommands would download dependencies for all targets, regardless of whether those targets were actually enabled. This PR updates them so that they only download the same dependencies that building would do with the requested target(s). `cargo metadata` still includes all targets by default; you can only opt _out_ using `--filter-platform`. Ideally it should use `--target` the same way `tree` does, but it's too late to change that now. Fixes #8981.
Problem
cargo metadata
(andcargo tree
, possibly also others) downloads the.crate
files for dependencies that are not used under the currentcfg
parameters. This means that it will, for example, download windows-only dependencies even if run on a UNIX platform.cargo build
and friends do not do this. This occurs even with--filter-platform
/--target
is passed to filter for a particular target (I understandcargo metadata
is supposed to cover all targets unless explicitly otherwise specified).Steps
Cargo.toml
with acfg
-guarded dependency:cargo check
, and notice that it does not downloadserde
.cargo metadata --filter-platform x86_64-unknown-linux-gnu
, and notice that it does downloadserde
.Possible Solution(s)
The cause of the bug is here:
cargo/src/cargo/ops/cargo_output_metadata.rs
Lines 133 to 136 in de42302
As the comment notes, that logic should do target filtering as expressed in
PackageSet::download_accessible
:cargo/src/cargo/core/package.rs
Line 485 in 862df61
Notes
Output of
cargo version
: cargo 1.48.0 (65cbdd2 2020-10-14)The text was updated successfully, but these errors were encountered: