Skip to content

Commit ccbce2c

Browse files
authored
Merge pull request #2958 from jyn514/jnelson/set-rustc-env
Set RUSTC and RUSTDOC env for child processes run through the proxy
2 parents bc18467 + 66267c8 commit ccbce2c

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
@@ -401,6 +401,19 @@ impl<'a> InstalledCommonToolchain<'a> {
401401

402402
cmd.env("RUSTUP_TOOLCHAIN", &self.0.name);
403403
cmd.env("RUSTUP_HOME", &self.0.cfg.rustup_dir);
404+
// It's valid (although slightly cursed) to tell a rustup cargo proxy to use a custom rustc
405+
// from a different toolchain.
406+
if env::var("RUSTC").is_err() {
407+
// Set RUSTC for the spawned binary. This serves two purposes:
408+
// 1. It avoids the overhead of having to re-parse `settings.toml` on each proxy.
409+
// In projects with many crates, this can have non-trivial overhead.
410+
// 2. For build scripts, it provides an absolute path for RUSTC rather than forcing them to look it up in PATH.
411+
// This allows them to find the sysroot path for the toolchain, rather than ending up somewhere in CARGO_HOME.
412+
cmd.env("RUSTC", self.0.path.join("bin").join("rustc"));
413+
}
414+
if env::var("RUSTDOC").is_err() {
415+
cmd.env("RUSTDOC", self.0.path.join("bin").join("rustdoc"));
416+
}
404417
}
405418

406419
fn set_ldpath(&self, cmd: &mut Command) {

0 commit comments

Comments
 (0)