Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f588bfa

Browse files
committed
Assume host target in get_file_name
1 parent 5d79366 commit f588bfa

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

build_system/build_sysroot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn build_sysroot(
2323
fs::create_dir_all(target_dir.join("lib")).unwrap();
2424

2525
// Copy the backend
26-
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", host_triple);
26+
let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib");
2727
let cg_clif_dylib_path = target_dir
2828
.join(if cfg!(windows) {
2929
// Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the
@@ -37,7 +37,7 @@ pub(crate) fn build_sysroot(
3737

3838
// Build and copy rustc and cargo wrappers
3939
for wrapper in ["rustc-clif", "cargo-clif"] {
40-
let wrapper_name = get_wrapper_file_name(wrapper, "bin", host_triple);
40+
let wrapper_name = get_wrapper_file_name(wrapper, "bin");
4141

4242
let mut build_cargo_wrapper_cmd = Command::new("rustc");
4343
build_cargo_wrapper_cmd

build_system/mod.rs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,42 +48,13 @@ pub fn main() {
4848
// The target dir is expected in the default location. Guard against the user changing it.
4949
env::set_var("CARGO_TARGET_DIR", "target");
5050

51-
52-
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
53-
host_triple
54-
} else if let Some(host_triple) = config::get_value("host") {
55-
host_triple
56-
} else {
57-
rustc_info::get_host_triple()
58-
};
59-
let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
60-
if target_triple != "" {
61-
target_triple
62-
} else {
63-
host_triple.clone() // Empty target triple can happen on GHA
64-
}
65-
} else if let Some(target_triple) = config::get_value("target") {
66-
target_triple
67-
} else {
68-
host_triple.clone()
69-
};
70-
71-
if target_triple.ends_with("-msvc") {
72-
eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
73-
eprintln!("Switch to the MinGW toolchain for Windows support.");
74-
eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
75-
eprintln!("set the global default target to MinGW");
76-
process::exit(1);
77-
}
78-
79-
8051
let mut args = env::args().skip(1);
8152
let command = match args.next().as_deref() {
8253
Some("prepare") => {
8354
if args.next().is_some() {
8455
arg_error!("./y.rs prepare doesn't expect arguments");
8556
}
86-
prepare::prepare(&host_triple);
57+
prepare::prepare();
8758
process::exit(0);
8859
}
8960
Some("build") => Command::Build,
@@ -124,6 +95,33 @@ pub fn main() {
12495
}
12596
target_dir = std::env::current_dir().unwrap().join(target_dir);
12697

98+
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
99+
host_triple
100+
} else if let Some(host_triple) = config::get_value("host") {
101+
host_triple
102+
} else {
103+
rustc_info::get_host_triple()
104+
};
105+
let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
106+
if target_triple != "" {
107+
target_triple
108+
} else {
109+
host_triple.clone() // Empty target triple can happen on GHA
110+
}
111+
} else if let Some(target_triple) = config::get_value("target") {
112+
target_triple
113+
} else {
114+
host_triple.clone()
115+
};
116+
117+
if target_triple.ends_with("-msvc") {
118+
eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
119+
eprintln!("Switch to the MinGW toolchain for Windows support.");
120+
eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
121+
eprintln!("set the global default target to MinGW");
122+
process::exit(1);
123+
}
124+
127125
let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features);
128126
match command {
129127
Command::Test => {

build_system/prepare.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::process::Command;
88
use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version};
99
use super::utils::{copy_dir_recursively, spawn_and_wait};
1010

11-
pub(crate) fn prepare(host_triple: &str) {
11+
pub(crate) fn prepare() {
1212
prepare_sysroot();
1313

1414
eprintln!("[INSTALL] hyperfine");
@@ -49,8 +49,8 @@ pub(crate) fn prepare(host_triple: &str) {
4949
build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer");
5050
spawn_and_wait(build_cmd);
5151
fs::copy(
52-
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", host_triple)),
53-
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", host_triple)),
52+
Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")),
53+
Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")),
5454
)
5555
.unwrap();
5656
}

build_system/rustc_info.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ pub(crate) fn get_default_sysroot() -> PathBuf {
4343
Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned()
4444
}
4545

46-
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> String {
46+
pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String {
4747
let file_name = Command::new("rustc")
4848
.stderr(Stdio::inherit())
4949
.args(&[
5050
"--crate-name",
5151
crate_name,
5252
"--crate-type",
5353
crate_type,
54-
"--target",
55-
target,
5654
"--print",
5755
"file-names",
5856
"-",
@@ -69,8 +67,8 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) ->
6967
/// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to
7068
/// underscores (`_`). This is specially made for the the rustc and cargo wrappers
7169
/// which have a dash in the name, and that is not allowed in a crate name.
72-
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str, target: &str) -> String {
70+
pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String {
7371
let crate_name = crate_name.replace('-', "_");
74-
let wrapper_name = get_file_name(&crate_name, crate_type, target);
72+
let wrapper_name = get_file_name(&crate_name, crate_type);
7573
wrapper_name.replace('_', "-")
7674
}

build_system/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl TestRunner {
415415
{
416416
let mut rustc_clif = self.root_dir.clone();
417417
rustc_clif.push("build");
418-
rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.host_triple));
418+
rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin"));
419419

420420
let mut cmd = Command::new(rustc_clif);
421421
cmd.args(self.rust_flags.split_whitespace());
@@ -474,7 +474,7 @@ impl TestRunner {
474474
{
475475
let mut cargo_clif = self.root_dir.clone();
476476
cargo_clif.push("build");
477-
cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.host_triple));
477+
cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin"));
478478

479479
let mut cmd = Command::new(cargo_clif);
480480
cmd.args(args);

0 commit comments

Comments
 (0)