about summary refs log tree commit diff
diff options
context:
space:
mode:
authoronur-ozkan <work@onurozkan.dev>2025-01-16 17:34:31 +0300
committerJosh Stone <jistone@redhat.com>2025-01-23 11:48:35 -0800
commit558d43bf82bf19f71abf7cf94872b66489e731a8 (patch)
tree646a5ec1b5633b3c77ace48406998b8c923f8ed0
parent900ed0b1a1088a757016e4f7f5ad7bbdaef741a1 (diff)
downloadrust-558d43bf82bf19f71abf7cf94872b66489e731a8.tar.gz
rust-558d43bf82bf19f71abf7cf94872b66489e731a8.zip
resolve symlinks of LLVM tool binaries before copying them
There is a chance that these tools are being installed from an external LLVM
and we have no control over them. If any of these tools use symlinks, they will
fail during tarball distribution. This change makes copying process to resolve
symlinks just before placing them into the destination path.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
(cherry picked from commit cde58dd5f781c3998d2421132854d2a833937e85)
-rw-r--r--src/bootstrap/src/core/build_steps/compile.rs8
-rw-r--r--src/bootstrap/src/lib.rs8
2 files changed, 15 insertions, 1 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 8e088682f92..761220527b3 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -1800,7 +1800,13 @@ impl Step for Assemble {
                     // When using `download-ci-llvm`, some of the tools
                     // may not exist, so skip trying to copy them.
                     if src_path.exists() {
-                        builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
+                        // There is a chance that these tools are being installed from an external LLVM.
+                        // Use `Builder::resolve_symlink_and_copy` instead of `Builder::copy_link` to ensure
+                        // we are copying the original file not the symlinked path, which causes issues for
+                        // tarball distribution.
+                        //
+                        // See https://github.com/rust-lang/rust/issues/135554.
+                        builder.resolve_symlink_and_copy(&src_path, &libdir_bin.join(&tool_exe));
                     }
                 }
             }
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index c384fd6bf43..ac735f0f685 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -1681,6 +1681,14 @@ Executed at: {executed_at}"#,
         paths
     }
 
+    /// Copies a file from `src` to `dst`.
+    ///
+    /// If `src` is a symlink, `src` will be resolved to the actual path
+    /// and copied to `dst` instead of the symlink itself.
+    pub fn resolve_symlink_and_copy(&self, src: &Path, dst: &Path) {
+        self.copy_link_internal(src, dst, true);
+    }
+
     /// Links a file from `src` to `dst`.
     /// Attempts to use hard links if possible, falling back to copying.
     /// You can neither rely on this being a copy nor it being a link,