Add `--download-only` option for multi-crate workspaces
Opened this issue · 2 comments
Context
I had run into an issue where chef wasn't caching properly because I'm using a workspace with multiple crates.
A minimal Dockerfile example could be:
ARG PROFILE=release
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release -p package
# alternative: cargo install --path package
Here, the package chosen may change the feature selection on some dependencies, which can cause a large recompile. Chef will have built for all packages, and so the dependencies will use the maximal feature set, while the build -p package
may choose a smaller feature set for some dependencies and recompile a large amount of code.
In my particular case, I have a single cargo workspace and Dockerfile where I am building multiple containers from different crates.
The options for cargo chef in a workspace are either:
- chef for all packages, build for all packages
- chef per-package, build per-package
- alternative: chef fetch for all packages, chef cook per-package, build per-package
I can see an outstanding issue (#180) that hints at usage of a workspace with multiple crates and may be suffering the same fate.
Proposal
Add a cargo chef fetch
or cargo chef cook --download-only
to download dependencies, but avoid compiling them. I'm ignorant to how cargo chef
is implemented, but the cargo fetch
command could hopefully provide the functionality?
Documentation
It might be worth adding a point about workspaces and crates depending on different features, it took me a few hours to figure out what was happening! Perhaps as a troubleshooting guide, or some form of "here's what's recommended for workspaces with multiple crates" section in the README?
I've had the same issue, try running it with --bin package
instead. That should use the same features as the workspace.
Or do you need the package to have different features than the workspace?
After #260 it is possible to do:
cargo chef cook --no-build
cargo fetch