Skip to content

Commit 752c0f5

Browse files
Rollup merge of rust-lang#104748 - lqd:download_lld, r=jyn514
Ensure `lld` is supported with `download-ci-llvm` This PR: - ensures LLD's step in bootstrap's dist, but it's not strictly necessary since dist will already package it when it's present. - makes bootstrap's `native::LLD` step support using the packaged `ci-llvm/bin/lld`, instead of building it from source (which would most likely not be available today, nor in the future where `download-ci-llvm = if-available` is the default). If I understand correctly, `--enable-full-tools` will also enable `rust.lld`, and this is why LLD is already packaged today in the `rust-dev` component on the main targets (and why `-Zgcc-ld=lld` does work there). That means it's likely that this PR will not be able to land before I've reworked and landed rust-lang#101792: if LLD is available in `download-ci-llvm`, the `needs-rust-lld` tests should start being executed on the x64 macOS test builders, and CI would fail today. I've tested locally that building with `download-ci-llvm = true` and `lld = true` with the LLVM submodule unregistered was successful, and that `rust-lld` and the various `lld-wrapper`s are present and `-Zgcc-ld=lld` works as well, on a few different platforms: - `x86_64-unknown-linux-gnu` - `aarch64-apple-darwin` - `x86_64-pc-windows-msvc` (with `-Clinker=rust-lld` rather than `-Zgcc-ld=lld`) - `x86_64-apple-darwin`, with the `MACOSX_DEPLOYMENT_TARGET` workaround for rust-lang#101653 I don't think we really need to bump the `download-ci-llvm-stamp` in this case, since `./build/$triple/ci-llvm/bin/lld` is present on all the above targets already, but have added it mechanically, and it should probably be removed to avoid unnecessary downloads/churn. Fixes rust-lang#98340 Supersedes rust-lang#100010
2 parents c757267 + e0f5c6d commit 752c0f5

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/bootstrap/dist.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,9 @@ impl Step for RustDev {
20672067

20682068
builder.ensure(crate::native::Llvm { target });
20692069

2070+
// We want to package `lld` to use it with `download-ci-llvm`.
2071+
builder.ensure(crate::native::Lld { target });
2072+
20702073
let src_bindir = builder.llvm_out(target).join("bin");
20712074
// If updating this list, you likely want to change
20722075
// src/bootstrap/download-ci-llvm-stamp as well, otherwise local users

src/bootstrap/download-ci-llvm-stamp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Change this file to make users of the `download-ci-llvm` configuration download
22
a new version of LLVM from CI, even if the LLVM submodule hasn’t changed.
33

4-
Last change is for: https://github.com/rust-lang/rust/pull/102790
4+
Last change is for: https://github.com/rust-lang/rust/pull/104748

src/bootstrap/native.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ impl LdFlags {
6363
}
6464
}
6565

66-
// This returns whether we've already previously built LLVM.
67-
//
68-
// It's used to avoid busting caches during x.py check -- if we've already built
69-
// LLVM, it's fine for us to not try to avoid doing so.
70-
//
71-
// This will return the llvm-config if it can get it (but it will not build it
72-
// if not).
66+
/// This returns whether we've already previously built LLVM.
67+
///
68+
/// It's used to avoid busting caches during x.py check -- if we've already built
69+
/// LLVM, it's fine for us to not try to avoid doing so.
70+
///
71+
/// This will return the llvm-config if it can get it (but it will not build it
72+
/// if not).
7373
pub fn prebuilt_llvm_config(
7474
builder: &Builder<'_>,
7575
target: TargetSelection,
@@ -823,8 +823,21 @@ impl Step for Lld {
823823
}
824824
let target = self.target;
825825

826-
let LlvmResult { llvm_config, llvm_cmake_dir } =
827-
builder.ensure(Llvm { target: self.target });
826+
let LlvmResult { llvm_config, llvm_cmake_dir } = builder.ensure(Llvm { target });
827+
828+
// The `dist` step packages LLD next to LLVM's binaries for download-ci-llvm. The root path
829+
// we usually expect here is `./build/$triple/ci-llvm/`, with the binaries in its `bin`
830+
// subfolder. We check if that's the case, and if LLD's binary already exists there next to
831+
// `llvm-config`: if so, we can use it instead of building LLVM/LLD from source.
832+
let ci_llvm_bin = llvm_config.parent().unwrap();
833+
if ci_llvm_bin.is_dir() && ci_llvm_bin.file_name().unwrap() == "bin" {
834+
let lld_path = ci_llvm_bin.join(exe("lld", target));
835+
if lld_path.exists() {
836+
// The following steps copying `lld` as `rust-lld` to the sysroot, expect it in the
837+
// `bin` subfolder of this step's out dir.
838+
return ci_llvm_bin.parent().unwrap().to_path_buf();
839+
}
840+
}
828841

829842
let out_dir = builder.lld_out(target);
830843
let done_stamp = out_dir.join("lld-finished-building");

0 commit comments

Comments
 (0)