about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2021-09-25 15:25:08 +0200
committerHans Kratz <hans@appfour.com>2021-10-07 16:59:13 +0200
commit6162fc0c809477529875b294a8ce37ff8737356c (patch)
tree0f6c8a48e5949f3bb1b9810967dc913d5244e975 /src/bootstrap
parentca8078d7b2e40c24a39e5fe2a910afef4c91ebfc (diff)
downloadrust-6162fc0c809477529875b294a8ce37ff8737356c.tar.gz
rust-6162fc0c809477529875b294a8ce37ff8737356c.zip
Add wrapper for -Z gcc-ld=lld to invoke rust-lld with the correct flavor
The wrapper is installed as `ld` and `ld64` in the `lib\rustlib\<host_target>\bin\gcc-ld`
directory and its sole purpose is to invoke `rust-lld` in the parent directory with
the correct flavor.
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/compile.rs16
-rw-r--r--src/bootstrap/dist.rs13
-rw-r--r--src/bootstrap/tool.rs32
3 files changed, 48 insertions, 13 deletions
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index ae234fb1dc7..4b189672226 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -1136,14 +1136,14 @@ impl Step for Assemble {
             // for `-Z gcc-ld=lld`
             let gcc_ld_dir = libdir_bin.join("gcc-ld");
             t!(fs::create_dir(&gcc_ld_dir));
-            builder.copy(
-                &lld_install.join("bin").join(&src_exe),
-                &gcc_ld_dir.join(exe("ld", target_compiler.host)),
-            );
-            builder.copy(
-                &lld_install.join("bin").join(&src_exe),
-                &gcc_ld_dir.join(exe("ld64", target_compiler.host)),
-            );
+            for flavor in ["ld", "ld64"] {
+                let lld_wrapper_exe = builder.ensure(crate::tool::LldWrapper {
+                    compiler: build_compiler,
+                    target: target_compiler.host,
+                    flavor_feature: flavor,
+                });
+                builder.copy(&lld_wrapper_exe, &gcc_ld_dir.join(exe(flavor, target_compiler.host)));
+            }
         }
 
         // Similarly, copy `llvm-dwp` into libdir for Split DWARF. Only copy it when the LLVM
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 7c1bb1a9148..d4875cfe1b0 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -409,11 +409,14 @@ impl Step for Rustc {
                 let rust_lld = exe("rust-lld", compiler.host);
                 builder.copy(&src_dir.join(&rust_lld), &dst_dir.join(&rust_lld));
                 // for `-Z gcc-ld=lld`
-                let gcc_lld_dir = dst_dir.join("gcc-ld");
-                t!(fs::create_dir(&gcc_lld_dir));
-                builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host)));
-                builder
-                    .copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld64", compiler.host)));
+                let gcc_lld_src_dir = src_dir.join("gcc-ld");
+                let gcc_lld_dst_dir = dst_dir.join("gcc-ld");
+                t!(fs::create_dir(&gcc_lld_dst_dir));
+                for flavor in ["ld", "ld64"] {
+                    let exe_name = exe(flavor, compiler.host);
+                    builder
+                        .copy(&gcc_lld_src_dir.join(&exe_name), &gcc_lld_dst_dir.join(&exe_name));
+                }
             }
 
             // Copy over llvm-dwp if it's there
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index c0358946385..af6f4bb0e5f 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -664,6 +664,38 @@ impl Step for Cargo {
     }
 }
 
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct LldWrapper {
+    pub compiler: Compiler,
+    pub target: TargetSelection,
+    pub flavor_feature: &'static str,
+}
+
+impl Step for LldWrapper {
+    type Output = PathBuf;
+
+    fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+        run.never()
+    }
+
+    fn run(self, builder: &Builder<'_>) -> PathBuf {
+        let src_exe = builder
+            .ensure(ToolBuild {
+                compiler: self.compiler,
+                target: self.target,
+                tool: "lld-wrapper",
+                mode: Mode::ToolStd,
+                path: "src/tools/lld-wrapper",
+                is_optional_tool: false,
+                source_type: SourceType::InTree,
+                extra_features: vec![self.flavor_feature.to_owned()],
+            })
+            .expect("expected to build -- essential tool");
+
+        src_exe
+    }
+}
+
 macro_rules! tool_extended {
     (($sel:ident, $builder:ident),
        $($name:ident,