From 629eab79c16a6659a241c0b50ea986780934a65d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 14 Jan 2023 14:08:23 +0000 Subject: [PATCH] Avoid hard-coded rustc when building wrappers --- build_system/build_sysroot.rs | 7 +++++-- build_system/rustc_info.rs | 10 ++++++++++ scripts/cargo-clif.rs | 2 +- scripts/rustc-clif.rs | 2 +- scripts/rustdoc-clif.rs | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 15a5e030193..9eebcf95505 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,7 +3,9 @@ use std::path::Path; use std::process::{self, Command}; use super::path::{Dirs, RelPath}; -use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name}; +use super::rustc_info::{ + get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name, +}; use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler}; use super::SysrootKind; @@ -44,8 +46,9 @@ pub(crate) fn build_sysroot( for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { let wrapper_name = get_wrapper_file_name(wrapper, "bin"); - let mut build_cargo_wrapper_cmd = Command::new("rustc"); + let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc); build_cargo_wrapper_cmd + .env("TOOLCHAIN_NAME", get_toolchain_name()) .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs"))) .arg("-o") .arg(DIST_DIR.to_path(dirs).join(wrapper_name)) diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 6959d1e323c..8a7e1c472dd 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -23,6 +23,16 @@ pub(crate) fn get_host_triple() -> String { .to_owned() } +pub(crate) fn get_toolchain_name() -> String { + let active_toolchain = Command::new("rustup") + .stderr(Stdio::inherit()) + .args(&["show", "active-toolchain"]) + .output() + .unwrap() + .stdout; + String::from_utf8(active_toolchain).unwrap().trim().split_once(' ').unwrap().0.to_owned() +} + pub(crate) fn get_cargo_path() -> PathBuf { let cargo_path = Command::new("rustup") .stderr(Stdio::inherit()) diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs index 9362b47fa6d..c993430b830 100644 --- a/scripts/cargo-clif.rs +++ b/scripts/cargo-clif.rs @@ -26,7 +26,7 @@ fn main() { env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags); // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); let args: Vec<_> = match env::args().nth(1).as_deref() { Some("jit") => { diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs index 3abfcd8ddc8..c187f54a60e 100644 --- a/scripts/rustc-clif.rs +++ b/scripts/rustc-clif.rs @@ -24,7 +24,7 @@ fn main() { } // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); #[cfg(unix)] Command::new("rustc").args(args).exec(); diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs index a19d72acfa8..a6528ac41ae 100644 --- a/scripts/rustdoc-clif.rs +++ b/scripts/rustdoc-clif.rs @@ -24,7 +24,7 @@ fn main() { } // Ensure that the right toolchain is used - env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME")); #[cfg(unix)] Command::new("rustdoc").args(args).exec();