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

fix: use toolchain file while building dependencies #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
12 changes: 9 additions & 3 deletions src/recipe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Skeleton;
use crate::{RustToolchainFile, Skeleton};
use anyhow::Context;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Recipe {
if args.no_build {
return Ok(());
}
build_dependencies(&args);
build_dependencies(&args, &self.skeleton.rust_toolchain_file);
self.skeleton
.remove_compiled_dummies(
current_directory,
Expand Down Expand Up @@ -94,7 +94,7 @@ pub enum AllFeatures {
Disabled,
}

fn build_dependencies(args: &CookArgs) {
fn build_dependencies(args: &CookArgs, toolchain: &Option<(RustToolchainFile, String)>) {
let CookArgs {
profile,
command: command_arg,
Expand All @@ -119,6 +119,12 @@ fn build_dependencies(args: &CookArgs) {
no_build: _no_build,
} = 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.");
if toolchain.is_some() {
// If that variable is already set, the provided toolchain from the recipe would be
// ignored. Unsetting it make cargo later use the toolchain file for building the
// dependencies.
std::env::remove_var("RUSTUP_TOOLCHAIN");
}
let mut command = Command::new(cargo_path);
let command_with_args = match command_arg {
CommandArg::Build => command.arg("build"),
Expand Down