Skip to content

Commit 66267c8

Browse files
committed
Set RUSTC and RUSTDOC env for child processes run through the proxy
This serves two purposes: 1. It avoids the overhead of having to re-parse `settings.toml` on each proxy. In projects with many crates, this can have non-trivial overhead. 2. For build scripts, it provides an absolute path for RUSTC rather than forcing them to look it up in PATH. This allows them to find the sysroot path for the toolchain, rather than ending up somewhere in CARGO_HOME. The original motivation for this was to allow `bootstrap` in rust-lang/rust to allow building stage0 tools without python, only the host rust toolchain.
1 parent d080411 commit 66267c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/toolchain.rs

Lines changed: 13 additions & 0 deletions
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)