about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-16 18:46:11 +0100
committerGitHub <noreply@github.com>2025-01-16 18:46:11 +0100
commit6997ea2cf5f6271ea38b814e066a302d6d434e42 (patch)
tree85c0e10ce8b1c59537df438eef3a5675d411bbdd
parent701f1922ef58e33514dd44f654699d6ffdd6f4b3 (diff)
parentcde58dd5f781c3998d2421132854d2a833937e85 (diff)
downloadrust-6997ea2cf5f6271ea38b814e066a302d6d434e42.tar.gz
rust-6997ea2cf5f6271ea38b814e066a302d6d434e42.zip
Rollup merge of #135585 - onur-ozkan:135554, r=Kobzol
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.

Fixes https://github.com/rust-lang/rust/issues/135554
-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 4c4df922b37..fd9bf47234c 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -1777,7 +1777,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 ebe2c332258..482e23cd04c 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -1633,6 +1633,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,