From 4dbafefe74f32ca7f76009e6ce3136348a017b3a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 14 Jan 2023 13:04:40 +0000 Subject: [PATCH] Return Compiler from build_sysroot --- build_system/abi_cafe.rs | 2 +- build_system/build_sysroot.rs | 26 +++++++++++++------- build_system/mod.rs | 6 ++--- build_system/tests.rs | 45 +++++++++++++++++------------------ 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs index 8352c1a965a..8742389f332 100644 --- a/build_system/abi_cafe.rs +++ b/build_system/abi_cafe.rs @@ -32,7 +32,7 @@ pub(crate) fn run( sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, - &bootstrap_host_compiler.triple, + bootstrap_host_compiler.triple.clone(), ); eprintln!("Running abi-cafe"); diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 92d01750fab..7902c7005e0 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -18,14 +18,16 @@ pub(crate) fn build_sysroot( sysroot_kind: SysrootKind, cg_clif_dylib_src: &Path, bootstrap_host_compiler: &Compiler, - target_triple: &str, -) { + target_triple: String, +) -> Compiler { eprintln!("[BUILD] sysroot {:?}", sysroot_kind); DIST_DIR.ensure_fresh(dirs); BIN_DIR.ensure_exists(dirs); LIB_DIR.ensure_exists(dirs); + let is_native = bootstrap_host_compiler.triple == target_triple; + // Copy the backend let cg_clif_dylib_path = if cfg!(windows) { // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the @@ -55,12 +57,12 @@ pub(crate) fn build_sysroot( let host_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib"); - let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(target_triple).join("lib"); + let target_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&target_triple).join("lib"); fs::create_dir_all(&host_rustlib_lib).unwrap(); fs::create_dir_all(&target_rustlib_lib).unwrap(); if target_triple == "x86_64-pc-windows-gnu" { - if !default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib").exists() { + if !default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib").exists() { eprintln!( "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \ to compile a sysroot for it.", @@ -68,7 +70,7 @@ pub(crate) fn build_sysroot( process::exit(1); } for file in fs::read_dir( - default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), + default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"), ) .unwrap() { @@ -108,9 +110,9 @@ pub(crate) fn build_sysroot( try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap())); } - if target_triple != bootstrap_host_compiler.triple { + if !is_native { for file in fs::read_dir( - default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), + default_sysroot.join("lib").join("rustlib").join(&target_triple).join("lib"), ) .unwrap() { @@ -127,13 +129,13 @@ pub(crate) fn build_sysroot( &cg_clif_dylib_path, ); - if bootstrap_host_compiler.triple != target_triple { + if !is_native { build_clif_sysroot_for_triple( dirs, channel, { let mut bootstrap_target_compiler = bootstrap_host_compiler.clone(); - bootstrap_target_compiler.triple = target_triple.to_owned(); + bootstrap_target_compiler.triple = target_triple.clone(); bootstrap_target_compiler.set_cross_linker_and_runner(); bootstrap_target_compiler }, @@ -152,6 +154,12 @@ pub(crate) fn build_sysroot( } } } + + let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple); + if !is_native { + target_compiler.set_cross_linker_and_runner(); + } + target_compiler } pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot"); diff --git a/build_system/mod.rs b/build_system/mod.rs index 910213be85e..6f388cd605f 100644 --- a/build_system/mod.rs +++ b/build_system/mod.rs @@ -154,7 +154,7 @@ pub fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, - &target_triple, + target_triple.clone(), ); if bootstrap_host_compiler.triple == target_triple { @@ -177,7 +177,7 @@ pub fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, - &target_triple, + target_triple, ); } Command::Bench => { @@ -187,7 +187,7 @@ pub fn main() { sysroot_kind, &cg_clif_dylib, &bootstrap_host_compiler, - &target_triple, + target_triple, ); bench::benchmark(&dirs, &bootstrap_host_compiler); } diff --git a/build_system/tests.rs b/build_system/tests.rs index e915ed2a381..dcfadd73756 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -242,21 +242,21 @@ pub(crate) fn run_tests( sysroot_kind: SysrootKind, cg_clif_dylib: &Path, bootstrap_host_compiler: &Compiler, - target_triple: &str, + target_triple: String, ) { - let runner = - TestRunner::new(dirs.clone(), target_triple.to_owned(), get_host_triple() == target_triple); - if config::get_bool("testsuite.no_sysroot") { - build_sysroot::build_sysroot( + let target_compiler = build_sysroot::build_sysroot( dirs, channel, SysrootKind::None, cg_clif_dylib, bootstrap_host_compiler, - &target_triple, + target_triple.clone(), ); + let runner = + TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple); + BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs); runner.run_testsuite(NO_SYSROOT_SUITE); } else { @@ -267,26 +267,29 @@ pub(crate) fn run_tests( let run_extended_sysroot = config::get_bool("testsuite.extended_sysroot"); if run_base_sysroot || run_extended_sysroot { - build_sysroot::build_sysroot( + let target_compiler = build_sysroot::build_sysroot( dirs, channel, sysroot_kind, cg_clif_dylib, bootstrap_host_compiler, - &target_triple, + target_triple.clone(), ); - } - if run_base_sysroot { - runner.run_testsuite(BASE_SYSROOT_SUITE); - } else { - eprintln!("[SKIP] base_sysroot tests"); - } + let runner = + TestRunner::new(dirs.clone(), target_compiler, get_host_triple() == target_triple); - if run_extended_sysroot { - runner.run_testsuite(EXTENDED_SYSROOT_SUITE); - } else { - eprintln!("[SKIP] extended_sysroot tests"); + if run_base_sysroot { + runner.run_testsuite(BASE_SYSROOT_SUITE); + } else { + eprintln!("[SKIP] base_sysroot tests"); + } + + if run_extended_sysroot { + runner.run_testsuite(EXTENDED_SYSROOT_SUITE); + } else { + eprintln!("[SKIP] extended_sysroot tests"); + } } } @@ -298,11 +301,7 @@ struct TestRunner { } impl TestRunner { - pub fn new(dirs: Dirs, target_triple: String, is_native: bool) -> Self { - let mut target_compiler = Compiler::clif_with_triple(&dirs, target_triple); - if !is_native { - target_compiler.set_cross_linker_and_runner(); - } + pub fn new(dirs: Dirs, mut target_compiler: Compiler, is_native: bool) -> Self { if let Ok(rustflags) = env::var("RUSTFLAGS") { target_compiler.rustflags.push(' '); target_compiler.rustflags.push_str(&rustflags);