From f588bfa0956dbd7880c08a22c612e9831df2e3d8 Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Sat, 30 Jul 2022 23:04:59 +0100 Subject: [PATCH] Assume host target in get_file_name --- build_system/build_sysroot.rs | 4 +-- build_system/mod.rs | 58 +++++++++++++++++------------------ build_system/prepare.rs | 6 ++-- build_system/rustc_info.rs | 8 ++--- build_system/tests.rs | 4 +-- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index ed1c04808c5..6e4b57cf4d3 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -23,7 +23,7 @@ pub(crate) fn build_sysroot( fs::create_dir_all(target_dir.join("lib")).unwrap(); // Copy the backend - let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib", host_triple); + let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); let cg_clif_dylib_path = target_dir .join(if cfg!(windows) { // 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( // Build and copy rustc and cargo wrappers for wrapper in ["rustc-clif", "cargo-clif"] { - let wrapper_name = get_wrapper_file_name(wrapper, "bin", host_triple); + let wrapper_name = get_wrapper_file_name(wrapper, "bin"); let mut build_cargo_wrapper_cmd = Command::new("rustc"); build_cargo_wrapper_cmd diff --git a/build_system/mod.rs b/build_system/mod.rs index 3a6d58a2a6d..4772a5a7778 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -48,42 +48,13 @@ pub fn main() { // The target dir is expected in the default location. Guard against the user changing it. env::set_var("CARGO_TARGET_DIR", "target"); - - let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { - host_triple - } else if let Some(host_triple) = config::get_value("host") { - host_triple - } else { - rustc_info::get_host_triple() - }; - let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { - if target_triple != "" { - target_triple - } else { - host_triple.clone() // Empty target triple can happen on GHA - } - } else if let Some(target_triple) = config::get_value("target") { - target_triple - } else { - host_triple.clone() - }; - - if target_triple.ends_with("-msvc") { - eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); - eprintln!("Switch to the MinGW toolchain for Windows support."); - eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); - eprintln!("set the global default target to MinGW"); - process::exit(1); - } - - let mut args = env::args().skip(1); let command = match args.next().as_deref() { Some("prepare") => { if args.next().is_some() { arg_error!("./y.rs prepare doesn't expect arguments"); } - prepare::prepare(&host_triple); + prepare::prepare(); process::exit(0); } Some("build") => Command::Build, @@ -124,6 +95,33 @@ pub fn main() { } target_dir = std::env::current_dir().unwrap().join(target_dir); + let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { + host_triple + } else if let Some(host_triple) = config::get_value("host") { + host_triple + } else { + rustc_info::get_host_triple() + }; + let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { + if target_triple != "" { + target_triple + } else { + host_triple.clone() // Empty target triple can happen on GHA + } + } else if let Some(target_triple) = config::get_value("target") { + target_triple + } else { + host_triple.clone() + }; + + if target_triple.ends_with("-msvc") { + eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); + eprintln!("Switch to the MinGW toolchain for Windows support."); + eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); + eprintln!("set the global default target to MinGW"); + process::exit(1); + } + let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple, use_unstable_features); match command { Command::Test => { diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b499aaa703c..7e0fd182d98 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -8,7 +8,7 @@ use std::process::Command; use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use super::utils::{copy_dir_recursively, spawn_and_wait}; -pub(crate) fn prepare(host_triple: &str) { +pub(crate) fn prepare() { prepare_sysroot(); eprintln!("[INSTALL] hyperfine"); @@ -49,8 +49,8 @@ pub(crate) fn prepare(host_triple: &str) { build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); spawn_and_wait(build_cmd); fs::copy( - Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin", host_triple)), - Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin", host_triple)), + Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), + Path::new("simple-raytracer").join(get_file_name("raytracer_cg_llvm", "bin")), ) .unwrap(); } diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 63e1d16ead6..913b589afcc 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -43,7 +43,7 @@ pub(crate) fn get_default_sysroot() -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } -pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { +pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { let file_name = Command::new("rustc") .stderr(Stdio::inherit()) .args(&[ @@ -51,8 +51,6 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> crate_name, "--crate-type", crate_type, - "--target", - target, "--print", "file-names", "-", @@ -69,8 +67,8 @@ pub(crate) fn get_file_name(crate_name: &str, crate_type: &str, target: &str) -> /// Similar to `get_file_name`, but converts any dashes (`-`) in the `crate_name` to /// underscores (`_`). This is specially made for the the rustc and cargo wrappers /// which have a dash in the name, and that is not allowed in a crate name. -pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str, target: &str) -> String { +pub(crate) fn get_wrapper_file_name(crate_name: &str, crate_type: &str) -> String { let crate_name = crate_name.replace('-', "_"); - let wrapper_name = get_file_name(&crate_name, crate_type, target); + let wrapper_name = get_file_name(&crate_name, crate_type); wrapper_name.replace('_', "-") } diff --git a/build_system/tests.rs b/build_system/tests.rs index 2c96c5cc175..2b4ae39a75e 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -415,7 +415,7 @@ impl TestRunner { { let mut rustc_clif = self.root_dir.clone(); rustc_clif.push("build"); - rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin", &self.host_triple)); + rustc_clif.push(get_wrapper_file_name("rustc-clif", "bin")); let mut cmd = Command::new(rustc_clif); cmd.args(self.rust_flags.split_whitespace()); @@ -474,7 +474,7 @@ impl TestRunner { { let mut cargo_clif = self.root_dir.clone(); cargo_clif.push("build"); - cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin", &self.host_triple)); + cargo_clif.push(get_wrapper_file_name("cargo-clif", "bin")); let mut cmd = Command::new(cargo_clif); cmd.args(args);