]> git.lizzy.rs Git - rust.git/commitdiff
Return Compiler from build_sysroot
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>
Sat, 14 Jan 2023 13:04:40 +0000 (13:04 +0000)
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>
Sat, 14 Jan 2023 14:18:11 +0000 (14:18 +0000)
build_system/abi_cafe.rs
build_system/build_sysroot.rs
build_system/mod.rs
build_system/tests.rs

index 8352c1a965a75d8b9447079363d365730531081a..8742389f3322718645ccd25d2e1c4a0e9f9f600f 100644 (file)
@@ -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");
index 92d01750fab00e6da9e6a7c7c725495cc4e8f87b..7902c7005e017e9e45275681864c705e011e9028 100644 (file)
@@ -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");
index 910213be85e2cda8c1405d5f4029f3c6bba54764..6f388cd605fce2f194d0f43cea484e5c7233b29d 100644 (file)
@@ -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);
         }
index e915ed2a381d5d01ecc301ecadf8bb251d5e2a01..dcfadd737566e20d8a76f0fb8bf393e9b27eb654 100644 (file)
@@ -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);