Skip to content
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

Add the ability to restrict what crates cargo fetch downloads by target #5216

Closed
briansmith opened this issue Mar 21, 2018 · 4 comments
Closed
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@briansmith
Copy link

I am building the crate only for the x86-64-unknown-linux-musl target. My crate depends on several crates that have optional, target-specific dependencies on the fuchsia-zircon crate and/or the winapi crate. Since I'm targetting Linux, I will never need those crates downloaded. However, cargo fetch --locked always downloads winapi and fuchsia-zircon, presumably just in case I decide to build for targets that need them. Downloading all the crates (currently 60, for a quite small code base) takes a non-trivial amount of time, so I'd like to avoid downloading any crates that won't be used for the targets I'm intending to build for. The cargo fetch happens in a Dockerfile and the Cargo.lock very frequently changes, causing the whole Dockerfile to be built from scratch.

I propose that we add a --target or --targets flag to cargo fetch that works analogously to the same/similarly-named flag for cargo build. In particular, cargo fetch would only download dependencies that would be compiled by cargo build for the given target(s), and it would avoid downloading the dependencies that wouldn't be compiled by cargo build.

@briansmith
Copy link
Author

I see that cargo build does this already: It won't download a crate that it won't build, AFAICT. So, I think it should be straightforward to add a --target option to cargo fetch since presumably cargo build is already somehow passing a target to the implicit cargo fetch it does.

@alexcrichton alexcrichton added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Mar 21, 2018
@bmwill
Copy link
Contributor

bmwill commented Apr 9, 2018

I'm thinking of picking this up, unless someone else is already working on it.

I've spent a couple hours looking through the code which does the package/dependency filtering in cargo build (which lives in unit_dependencies.rs) and I think I understand how it could be applied to cargo fetch. Would it make sense to simply re-use that logic even though it appears to be more specialized for compilation (since it lives in the cargo_rustc module) as opposed to reimplementing the filtering of dependencies just for fetch?

bors added a commit that referenced this issue Apr 27, 2018
cargo-fetch: add option to fetch for a target

Teach cargo-fetch how to optionally fetch dependencies based on a target
platform by specifying the target triple via `--target <TRIPLE>`.

#5216
@DarkDrek
Copy link
Contributor

This seems to be done so issue can be closed.

@alexcrichton
Copy link
Member

Indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

4 participants