Skip to content

Commit 8e94b35

Browse files
author
Luca Palmieri
authored
Automatically detect which Rust toolchain should be used (#138)
* Automatically detect which Rust toolchain should be used by deferring to the `CARGO` env variable. * Fmt
1 parent 38f24c5 commit 8e94b35

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ If you want to build in `--release` mode:
8383
cargo chef cook --release --recipe-path recipe.json
8484
```
8585

86-
You can leverage it in a Dockerfile:
86+
You can also choose to override which Rust toolchain should be used. E.g., to force the `nightly` toolchain:
87+
88+
```bash
89+
cargo +nightly chef cook --recipe-path recipe.json
90+
```
91+
92+
`cargo-chef` is designed to be leveraged in Dockerfiles:
8793

8894
```dockerfile
8995
FROM lukemathwalker/cargo-chef:latest-rust-1.56.0 AS chef

src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ fn _main() -> Result<(), anyhow::Error> {
173173
}
174174
});
175175

176-
let unstable_features: Option<HashSet<String>> = unstable_features.and_then(|unstable_features| {
177-
if unstable_features.is_empty() {
178-
None
179-
} else {
180-
Some(unstable_features.into_iter().collect())
181-
}
182-
});
176+
let unstable_features: Option<HashSet<String>> =
177+
unstable_features.and_then(|unstable_features| {
178+
if unstable_features.is_empty() {
179+
None
180+
} else {
181+
Some(unstable_features.into_iter().collect())
182+
}
183+
});
183184

184185
let profile = match (release, profile) {
185186
(false, None) => OptimisationProfile::Debug,

src/recipe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ fn build_dependencies(args: &CookArgs) {
8585
offline,
8686
..
8787
} = args;
88-
let mut command = Command::new("cargo");
88+
let cargo_path = std::env::var("CARGO").expect("The `CARGO` environment variable was not set. This is unexpected: it should always be provided by `cargo` when invoking a custom sub-command, allowing `cargo-chef` to correctly detect which toolchain should be used. Please file a bug.");
89+
let mut command = Command::new(cargo_path);
8990
let command_with_args = if *check {
9091
command.arg("check")
9192
} else {

0 commit comments

Comments
 (0)