Skip to content

Commit 558d43b

Browse files
onur-ozkancuviper
authored andcommitted
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 <[email protected]> (cherry picked from commit cde58dd)
1 parent 900ed0b commit 558d43b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,13 @@ impl Step for Assemble {
18001800
// When using `download-ci-llvm`, some of the tools
18011801
// may not exist, so skip trying to copy them.
18021802
if src_path.exists() {
1803-
builder.copy_link(&src_path, &libdir_bin.join(&tool_exe));
1803+
// There is a chance that these tools are being installed from an external LLVM.
1804+
// Use `Builder::resolve_symlink_and_copy` instead of `Builder::copy_link` to ensure
1805+
// we are copying the original file not the symlinked path, which causes issues for
1806+
// tarball distribution.
1807+
//
1808+
// See https://github.com/rust-lang/rust/issues/135554.
1809+
builder.resolve_symlink_and_copy(&src_path, &libdir_bin.join(&tool_exe));
18041810
}
18051811
}
18061812
}

src/bootstrap/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,14 @@ Executed at: {executed_at}"#,
16811681
paths
16821682
}
16831683

1684+
/// Copies a file from `src` to `dst`.
1685+
///
1686+
/// If `src` is a symlink, `src` will be resolved to the actual path
1687+
/// and copied to `dst` instead of the symlink itself.
1688+
pub fn resolve_symlink_and_copy(&self, src: &Path, dst: &Path) {
1689+
self.copy_link_internal(src, dst, true);
1690+
}
1691+
16841692
/// Links a file from `src` to `dst`.
16851693
/// Attempts to use hard links if possible, falling back to copying.
16861694
/// You can neither rely on this being a copy nor it being a link,

0 commit comments

Comments
 (0)