Skip to content

Commit

Permalink
fix: Make work on Windows
Browse files Browse the repository at this point in the history
This works around rust-lang/rustup#3036 but also makes it so it can work
without rustup.
  • Loading branch information
epage committed Sep 1, 2022
1 parent c994518 commit 32909b8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,17 +1077,29 @@ fn cargo(
script_args: &[OsString],
run_quietly: bool,
) -> MainResult<Command> {
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() {
cmd.env("RUST_BACKTRACE", "1");
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 {
Expand Down

0 comments on commit 32909b8

Please sign in to comment.