]> git.lizzy.rs Git - rust.git/commitdiff
Move copying of self-contained objects to new function
authorMateusz Mikuła <mati865@gmail.com>
Tue, 2 Jun 2020 20:35:31 +0000 (22:35 +0200)
committerMateusz Mikuła <mati865@gmail.com>
Thu, 11 Jun 2020 16:33:42 +0000 (18:33 +0200)
src/bootstrap/compile.rs

index c09b73b042013ca77f3105bda1528fe40cc71a37..56d72d72b6109a1d3f74e210a79b202c07781aba 100644 (file)
@@ -74,6 +74,7 @@ fn run(self, builder: &Builder<'_>) {
             // Even if we're not building std this stage, the new sysroot must
             // still contain the third party objects needed by various targets.
             copy_third_party_objects(builder, &compiler, target);
+            copy_self_contained_objects(builder, &compiler, target);
 
             builder.ensure(StdLink {
                 compiler: compiler_to_use,
@@ -84,6 +85,7 @@ fn run(self, builder: &Builder<'_>) {
         }
 
         target_deps.extend(copy_third_party_objects(builder, &compiler, target).into_iter());
+        target_deps.extend(copy_self_contained_objects(builder, &compiler, target));
 
         let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
         std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -109,6 +111,19 @@ fn run(self, builder: &Builder<'_>) {
     }
 }
 
+fn copy_and_stamp(
+    builder: &Builder<'_>,
+    libdir: &Path,
+    sourcedir: &Path,
+    name: &str,
+    target_deps: &mut Vec<PathBuf>,
+) {
+    let target = libdir.join(name);
+    builder.copy(&sourcedir.join(name), &target);
+
+    target_deps.push((target, dependency_type));
+}
+
 /// Copies third party objects needed by various targets.
 fn copy_third_party_objects(
     builder: &Builder<'_>,
@@ -116,32 +131,8 @@ fn copy_third_party_objects(
     target: Interned<String>,
 ) -> Vec<PathBuf> {
     let libdir = builder.sysroot_libdir(*compiler, target);
-
     let mut target_deps = vec![];
 
-    let mut copy_and_stamp = |sourcedir: &Path, name: &str| {
-        let target = libdir.join(name);
-        builder.copy(&sourcedir.join(name), &target);
-        target_deps.push(target);
-    };
-
-    // Copies the CRT objects.
-    //
-    // rustc historically provides a more self-contained installation for musl targets
-    // not requiring the presence of a native musl toolchain. For example, it can fall back
-    // to using gcc from a glibc-targeting toolchain for linking.
-    // To do that we have to distribute musl startup objects as a part of Rust toolchain
-    // and link with them manually in the self-contained mode.
-    if target.contains("musl") {
-        let srcdir = builder.musl_root(target).unwrap().join("lib");
-        for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
-            copy_and_stamp(&srcdir, obj);
-        }
-    } else if target.ends_with("-wasi") {
-        let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
-        copy_and_stamp(&srcdir, "crt1.o");
-    }
-
     // Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx.
     //
     // This target needs to be linked to Fortanix's port of llvm's libunwind.
@@ -151,7 +142,13 @@ fn copy_third_party_objects(
         let src_path_env = "X86_FORTANIX_SGX_LIBS";
         let src =
             env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
-        copy_and_stamp(Path::new(&src), "libunwind.a");
+        copy_and_stamp(
+            builder,
+            &*libdir,
+            Path::new(&src),
+            "libunwind.a",
+            &mut target_deps,
+        );
     }
 
     if builder.config.sanitizers && compiler.stage != 0 {
@@ -163,6 +160,47 @@ fn copy_third_party_objects(
     target_deps
 }
 
+/// Copies third party objects needed by various targets for self-contained linkage.
+fn copy_self_contained_objects(
+    builder: &Builder<'_>,
+    compiler: &Compiler,
+    target: Interned<String>,
+) -> Vec<PathBuf> {
+    let libdir = builder.sysroot_libdir(*compiler, target);
+    let mut target_deps = vec![];
+
+    // Copies the CRT objects.
+    //
+    // rustc historically provides a more self-contained installation for musl targets
+    // not requiring the presence of a native musl toolchain. For example, it can fall back
+    // to using gcc from a glibc-targeting toolchain for linking.
+    // To do that we have to distribute musl startup objects as a part of Rust toolchain
+    // and link with them manually in the self-contained mode.
+    if target.contains("musl") {
+        let srcdir = builder.musl_root(target).unwrap().join("lib");
+        for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
+            copy_and_stamp(
+                builder,
+                &libdir_self_contained,
+                &srcdir,
+                obj,
+                &mut target_deps,
+            );
+        }
+    } else if target.ends_with("-wasi") {
+        let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
+        copy_and_stamp(
+            builder,
+            &libdir_self_contained,
+            &srcdir,
+            "crt1.o",
+            &mut target_deps,
+        );
+    }
+
+    target_deps
+}
+
 /// Configure cargo to compile the standard library, adding appropriate env vars
 /// and such.
 pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, stage: u32, cargo: &mut Cargo) {