LukeMathWalker / cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Apache License 2.0
1.81k stars 116 forks source link

Minimise `recipe.json` when `cargo chef prepare` is called with a `--bin` flag #208

Open LukeMathWalker opened 1 year ago

LukeMathWalker commented 1 year ago

cargo-chef slims down the workspace members to just the specified binary when cargo chef prepare is invoked with a --bin flag. At the moment (see #207) we still keep around ALL other local manifests, in case the binary depends on another one of the local crates via a path dependency. To maximise cache reuse, we could be more sophisticated: only include in the recipe.json file the manifests of the local crates that are in the dependency closure of the specified binary target.

markdingram commented 1 year ago

I think this would follow on nicely from https://github.com/LukeMathWalker/cargo-chef/pull/169

An earlier version had a "collect_local_packages" that walked down from the workspace_packages collecting all local manifests https://github.com/LukeMathWalker/cargo-chef/commit/585a0f5e8784e2be0dc0c9da0dfb5d4915f703a4

Realised that wasn't necessary for #169, but it could serve as the basis for this

etep commented 1 month ago

There are no examples of how to use the --bin for prepare. Curious to know, are we supposed to use one of the following:

--bin app                      # raw binary name
--bin target/release/app       # the path into the build collateral
--bin services/app             # the path into the source code (kind of...)
--bin services/src/app         # the path toward main.rs but with app