Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Recipe {
if args.no_build {
return Ok(());
}
build_dependencies(&args);
build_dependencies(&args, self.skeleton.rust_toolchain_file.is_some());
self.skeleton
.remove_compiled_dummies(
current_directory,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub enum AllFeatures {
Disabled,
}

fn build_dependencies(args: &CookArgs) {
fn build_dependencies(args: &CookArgs, restored_rust_toolchain_file: bool) {
let CookArgs {
profile,
command: command_arg,
Expand All @@ -120,7 +120,16 @@ fn build_dependencies(args: &CookArgs) {
no_build: _no_build,
jobs,
} = args;
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.");
let cargo_path = if restored_rust_toolchain_file {
// if we just restored a rust-toolchain.toml from the recipe, RUSTUP_TOOLCHAIN might
// point to the wrong thing
std::env::remove_var("RUSTUP_TOOLCHAIN");
// Simply invoking `cargo` from the path without RUSTUP_TOOLCHAIN set will make cargo
// pick up the right toolchain
"cargo".to_string()
} else {
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.")
};
let mut command = Command::new(cargo_path);
let command_with_args = match command_arg {
CommandArg::Build => command.arg("build"),
Expand Down