From cdf5e45b26d36f402fced2bfba81379bd6ea8d5e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 1 Sep 2022 10:05:28 -0500 Subject: [PATCH] fix: Make work on Windows This works around rust-lang/rustup#3036 --- src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 263458e..6eb1c34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1077,7 +1077,20 @@ fn cargo( script_args: &[OsString], run_quietly: bool, ) -> MainResult { - let mut cmd = Command::new("cargo"); + // Always specify a toolchain to avoid being affected by rust-version(.toml) files: + let toolchain_version = toolchain_version.unwrap_or("stable"); + + let mut cmd = if std::env::var_os("RUSTUP_TOOLCHAIN").is_some() { + // Running inside rustup which can't always call into rustup proxies, so explicitly call + // rustup + let mut cmd = Command::new("rustup"); + cmd.args(["run", toolchain_version, "cargo"]); + cmd + } else { + let mut cmd = Command::new("cargo"); + cmd.arg(format!("+{}", toolchain_version)); + cmd + }; // Set tracing on if not set if std::env::var_os("RUST_BACKTRACE").is_none() { @@ -1085,9 +1098,6 @@ fn cargo( info!("setting RUST_BACKTRACE=1 for this cargo run"); } - // Always specify a toolchain to avoid being affected by rust-version(.toml) files: - cmd.arg(format!("+{}", toolchain_version.unwrap_or("stable"))); - cmd.arg(cmd_name); if cmd_name == "run" && run_quietly {