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 {