Skip to content

Commit f9ed6fc

Browse files
ChrisDentonrami3l
authored andcommitted
Update CARGO env var if it is a rustup proxy
1 parent 4514d36 commit f9ed6fc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/toolchain.rs

+13
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,19 @@ impl<'a> Toolchain<'a> {
423423
};
424424
let mut cmd = Command::new(path);
425425
self.set_env(&mut cmd);
426+
427+
// If we're running cargo and the `CARGO` environment variable is set
428+
// to a rustup proxy then change `CARGO` to be the real cargo binary,
429+
// but only if we know the absolute path to cargo.
430+
// This works around an issue with old versions of cargo not updating
431+
// the environment variable itself.
432+
if Path::new(&binary).file_stem() == Some("cargo".as_ref()) && path.is_absolute() {
433+
if let Some(cargo) = self.cfg.process.var_os("CARGO") {
434+
if fs::read_link(&cargo).is_ok_and(|p| p.file_stem() == Some("rustup".as_ref())) {
435+
cmd.env("CARGO", path);
436+
}
437+
}
438+
}
426439
Ok(cmd)
427440
}
428441

0 commit comments

Comments
 (0)