@@ -206,6 +206,7 @@ fn command(bin: &str) -> Command {
206206 command. env_clear ( ) ;
207207
208208 // Propagate Window's `SystemRoot` environment variable as required for basic functioning
209+ // Notably, `git` for Windows won't function at all if this isn't set
209210 #[ cfg( target_family = "windows" ) ]
210211 if let Ok ( root) = env:: var ( "SystemRoot" ) {
211212 command. env ( "SystemRoot" , root) ;
@@ -228,6 +229,39 @@ fn command(bin: &str) -> Command {
228229 for key in [ "CARGO" , "RUSTC" , "RUSTDOC" ] {
229230 command. env ( key, cargo_env ( key) ) ;
230231 }
232+
233+ /*
234+ We also propagate `RUSTUP_HOME` and `RUSTUP_TOOLCHAIN` so that when we create a fresh
235+ `CARGO_HOME` later in this build script, `rustup` can still resolve its toolchain.
236+
237+ This wasn't observed as necessary on an `x86_64-unknown-linux-gnu` host. It was reported as
238+ necessary on an `aarch64-apple-darwin` host however. It _shouldn't_ be necessary as this script
239+ should _solely_ use the _already resolved_ `rustc`, `cargo`, as identified by the
240+ `RUSTC`, `CARGO` environment variables. It isn't observed to be problematic
241+ (re: reproducibility) to include here however, and solves a practical issue of this not working
242+ otherwise. Ideally, a cleaner solution would overall.
243+ */
244+ for key in [ "RUSTUP_HOME" , "RUSTUP_TOOLCHAIN" ] {
245+ if let Ok ( value) = env:: var ( key) {
246+ command. env ( key, value) ;
247+ }
248+ }
249+
250+ /*
251+ Finally, we propagate the host's `PATH`, as the Rust toolchain requires the host's C compiler,
252+ even when using the self-contained linker, in order to drive it and provide the
253+ platform-specific libraries.
254+
255+ While we could build a `PATH` from the Rust toolchain, and then append the value of
256+ `RUSTC_LINKER` (to have a `PATH` deterministic to the Rust toolchain with the sole exception of
257+ the host's linker), `RUSTC_LINKER` is the linker for the _target_, not the host, when we would
258+ want to set the linker for the host specifically. There also isn't a trivial way to query the
259+ _resolved_ linker after all the possible configuration methods are taken into consideration.
260+ */
261+ if let Ok ( path) = env:: var ( "PATH" ) {
262+ command. env ( "PATH" , path) ;
263+ }
264+
231265 /*
232266 Propagate toolchain configuration which are _optional_ and may not be set.
233267
@@ -698,21 +732,6 @@ which will build the WASM as part of its build process, with the necessary confi
698732 */
699733 build_command. env ( "WORKSPACE_DIR" , workspace_dir ( ) ) ;
700734
701- /*
702- We do propagate the host's `PATH`, as the Rust toolchain requires the host's C compiler, even
703- when using the self-contained linker, in order to drive it and provide the platform-specific
704- libraries.
705-
706- While we could build a `PATH` from the Rust toolchain, and then append the value of
707- `RUSTC_LINKER` (to have a `PATH` deterministic to the Rust toolchain with the sole exception of
708- the host's linker), `RUSTC_LINKER` is the linker for the _target_, not the host, when we would
709- want to set the linker for the host specifically. There also isn't a trivial way to query the
710- _resolved_ linker after all the possible configuration methods are taken into consideration.
711- */
712- if let Ok ( path) = env:: var ( "PATH" ) {
713- build_command. env ( "PATH" , path) ;
714- }
715-
716735 /*
717736 Install ourselves as the `rustc` wrapper for the reasons described above.
718737
0 commit comments