From 56454051606bb010e02426bfea3329aefe0b85b9 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 9 Dec 2023 11:49:07 -0500 Subject: [PATCH] workaround cargo bugs on windows --- src/bootstrap/src/bin/rustc.rs | 9 +++++++-- src/bootstrap/src/core/builder.rs | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 7ca6a78bb509f..649940ac3fbbd 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -16,7 +16,7 @@ //! never get replaced. use std::env; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::{Child, Command}; use std::time::Instant; @@ -85,7 +85,12 @@ fn main() { } else { // Cargo doesn't respect RUSTC_WRAPPER for version information >:( // don't remove the first arg if we're being run as RUSTC instead of RUSTC_WRAPPER. - if args[0] == env::current_exe().expect("couldn't get path to rustc shim") { + // Cargo also sometimes doesn't pass the `.exe` suffix on Windows - add it manually. + let current_exe = env::current_exe().expect("couldn't get path to rustc shim"); + // NOTE: we intentionally pass the name of the host, not the target. + let host = env::var("CFG_COMPILER_BUILD_TRIPLE").unwrap(); + let arg0 = exe(args[0].to_str().expect("only utf8 paths are supported"), &host); + if Path::new(&arg0) == current_exe { args.remove(0); } rustc_real diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index b3a77383b5690..43d9a14661c37 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -2014,7 +2014,11 @@ impl<'a> Builder<'a> { // Environment variables *required* throughout the build // // FIXME: should update code to not require this env var + + // The host this new compiler will *run* on. cargo.env("CFG_COMPILER_HOST_TRIPLE", target.triple); + // The host this new compiler is being *built* on. + cargo.env("CFG_COMPILER_BUILD_TRIPLE", compiler.host.triple); // Set this for all builds to make sure doc builds also get it. cargo.env("CFG_RELEASE_CHANNEL", &self.config.channel);