From 66267c80daf6d7e10cac015742609c0ccae1d669 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 9 Mar 2022 23:31:40 -0600 Subject: [PATCH] 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. --- src/toolchain.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/toolchain.rs b/src/toolchain.rs index 4c74317b94..951dbf31f3 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -401,6 +401,19 @@ impl<'a> InstalledCommonToolchain<'a> { cmd.env("RUSTUP_TOOLCHAIN", &self.0.name); cmd.env("RUSTUP_HOME", &self.0.cfg.rustup_dir); + // It's valid (although slightly cursed) to tell a rustup cargo proxy to use a custom rustc + // from a different toolchain. + if env::var("RUSTC").is_err() { + // Set RUSTC for the spawned binary. 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. + cmd.env("RUSTC", self.0.path.join("bin").join("rustc")); + } + if env::var("RUSTDOC").is_err() { + cmd.env("RUSTDOC", self.0.path.join("bin").join("rustdoc")); + } } fn set_ldpath(&self, cmd: &mut Command) {