From 32909b8d65af612ce2ca79e7373e7d235cf8d67c 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 but also makes it so it can work without rustup. --- src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 263458e..254bbb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1077,7 +1077,22 @@ fn cargo( script_args: &[OsString], run_quietly: bool, ) -> MainResult { - let mut cmd = Command::new("cargo"); + let mut cmd = if std::env::var_os("RUSTUP_TOOLCHAIN").is_some() { + let mut cmd = Command::new("rustup"); + // Always specify a toolchain to avoid being affected by rust-version(.toml) files: + let toolchain_version = toolchain_version.unwrap_or("stable"); + cmd.args(["run", toolchain_version, "cargo"]); + cmd + } else { + if let Some(toolchain_version) = toolchain_version { + return Err(format!( + "--toolchain-version={} cannot be used without rustup being available", + toolchain_version + ) + .into()); + } + Command::new("cargo") + }; // Set tracing on if not set if std::env::var_os("RUST_BACKTRACE").is_none() { @@ -1085,9 +1100,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 {