Skip to content

Commit 629eab7

Browse files
committed
Avoid hard-coded rustc when building wrappers
1 parent 22c5249 commit 629eab7

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

build_system/build_sysroot.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::path::Path;
33
use std::process::{self, Command};
44

55
use super::path::{Dirs, RelPath};
6-
use super::rustc_info::{get_file_name, get_rustc_version, get_wrapper_file_name};
6+
use super::rustc_info::{
7+
get_file_name, get_rustc_version, get_toolchain_name, get_wrapper_file_name,
8+
};
79
use super::utils::{spawn_and_wait, try_hard_link, CargoProject, Compiler};
810
use super::SysrootKind;
911

@@ -44,8 +46,9 @@ pub(crate) fn build_sysroot(
4446
for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
4547
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
4648

47-
let mut build_cargo_wrapper_cmd = Command::new("rustc");
49+
let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
4850
build_cargo_wrapper_cmd
51+
.env("TOOLCHAIN_NAME", get_toolchain_name())
4952
.arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
5053
.arg("-o")
5154
.arg(DIST_DIR.to_path(dirs).join(wrapper_name))

build_system/rustc_info.rs

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ pub(crate) fn get_host_triple() -> String {
2323
.to_owned()
2424
}
2525

26+
pub(crate) fn get_toolchain_name() -> String {
27+
let active_toolchain = Command::new("rustup")
28+
.stderr(Stdio::inherit())
29+
.args(&["show", "active-toolchain"])
30+
.output()
31+
.unwrap()
32+
.stdout;
33+
String::from_utf8(active_toolchain).unwrap().trim().split_once(' ').unwrap().0.to_owned()
34+
}
35+
2636
pub(crate) fn get_cargo_path() -> PathBuf {
2737
let cargo_path = Command::new("rustup")
2838
.stderr(Stdio::inherit())

scripts/cargo-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
2727

2828
// Ensure that the right toolchain is used
29-
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
29+
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
3030

3131
let args: Vec<_> = match env::args().nth(1).as_deref() {
3232
Some("jit") => {

scripts/rustc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() {
2424
}
2525

2626
// Ensure that the right toolchain is used
27-
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
27+
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
2828

2929
#[cfg(unix)]
3030
Command::new("rustc").args(args).exec();

scripts/rustdoc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() {
2424
}
2525

2626
// Ensure that the right toolchain is used
27-
env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
27+
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
2828

2929
#[cfg(unix)]
3030
Command::new("rustdoc").args(args).exec();

0 commit comments

Comments
 (0)