Skip to content

update llvm-tools logic for dist and install steps #140932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,17 +1984,20 @@ impl Step for Assemble {
trace!("installing `{tool}`");
let tool_exe = exe(tool, target_compiler.host);
let src_path = llvm_bin_dir.join(&tool_exe);
// When using `download-ci-llvm`, some of the tools
// may not exist, so skip trying to copy them.
if src_path.exists() {
// 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));

// When using `download-ci-llvm`, some of the tools may not exist, so skip trying to copy them.
if !src_path.exists() && builder.config.llvm_from_ci {
eprintln!("{} does not exist; skipping copy", src_path.display());
continue;
}

// 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));
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,9 +2274,9 @@ impl Step for LlvmTools {

let target = self.target;

/* run only if llvm-config isn't used */
// Run only if a custom llvm-config is not used
if let Some(config) = builder.config.target_config.get(&target) {
if let Some(ref _s) = config.llvm_config {
if !builder.config.llvm_from_ci && config.llvm_config.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running any dist command when CI LLVM is enabled should IMO be a hard error. But that's a separate topic.

builder.info(&format!("Skipping LlvmTools ({target}): external LLVM"));
return None;
}
Expand All @@ -2294,6 +2294,12 @@ impl Step for LlvmTools {
let dst_bindir = format!("lib/rustlib/{}/bin", target.triple);
for tool in tools_to_install(&builder.paths) {
let exe = src_bindir.join(exe(tool, target));
// When using `download-ci-llvm`, some of the tools may not exist, so skip trying to copy them.
if !exe.exists() && builder.config.llvm_from_ci {
eprintln!("{} does not exist; skipping copy", exe.display());
continue;
}

tarball.add_file(&exe, &dst_bindir, FileType::Executable);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ install!((self, builder, _config),
);
}
};
LlvmTools, alias = "llvm-tools", Self::should_build(_config), only_hosts: true, {
LlvmTools, alias = "llvm-tools", _config.llvm_tools_enabled && _config.llvm_enabled(_config.build), only_hosts: true, {
if let Some(tarball) = builder.ensure(dist::LlvmTools { target: self.target }) {
install_sh(builder, "llvm-tools", self.compiler.stage, Some(self.target), &tarball);
} else {
Expand Down
Loading