Skip to content

Commit fb80d2b

Browse files
committed
Auto merge of #99967 - Mark-Simulacrum:download-llvm-ci, r=jyn514
Download, rather than sccache-cache, LLVM in CI My hope/expectation is that we can do better than sccache in CI for cached builds -- currently it looks like on macOS those still take upwards of 10-11 minutes, which is a significant amount of time that we could potentially cut. This enables this mode for all non-dist builders; this should avoid any problems with the artifacts we distribute, while also providing for faster test builders (since they'll make use of PGO'd LLVM on the platforms we do that on, which is hopefully a nice win). It slightly increases the chance of test builders starting to fail only after a PR is merged (if PGO changes runtime behavior), but that should hopefully never happen, so I think this is worthwhile. Measurements on the PR for apple-1 don't show any noticeable improvement in CI times, but those can be pretty noisy -- I'm inclined to land this since it *should* pretty much always be better and we can reconsider if that ever turns out not to be the case.
2 parents 878aef7 + d7b91c3 commit fb80d2b

File tree

20 files changed

+182
-48
lines changed

20 files changed

+182
-48
lines changed

.github/workflows/ci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -391,24 +391,28 @@ jobs:
391391
env:
392392
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --set llvm.allow-old-toolchain"
393393
SCRIPT: make ci-mingw-subset-1
394+
NO_DOWNLOAD_CI_LLVM: 1
394395
CUSTOM_MINGW: 1
395396
os: windows-latest-xl
396397
- name: i686-mingw-2
397398
env:
398399
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --set llvm.allow-old-toolchain"
399400
SCRIPT: make ci-mingw-subset-2
401+
NO_DOWNLOAD_CI_LLVM: 1
400402
CUSTOM_MINGW: 1
401403
os: windows-latest-xl
402404
- name: x86_64-mingw-1
403405
env:
404406
SCRIPT: make ci-mingw-subset-1
405407
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler --set llvm.allow-old-toolchain"
408+
NO_DOWNLOAD_CI_LLVM: 1
406409
CUSTOM_MINGW: 1
407410
os: windows-latest-xl
408411
- name: x86_64-mingw-2
409412
env:
410413
SCRIPT: make ci-mingw-subset-2
411414
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-profiler --set llvm.allow-old-toolchain"
415+
NO_DOWNLOAD_CI_LLVM: 1
412416
CUSTOM_MINGW: 1
413417
os: windows-latest-xl
414418
- name: dist-x86_64-msvc
@@ -433,6 +437,7 @@ jobs:
433437
- name: dist-i686-mingw
434438
env:
435439
RUST_CONFIGURE_ARGS: "--build=i686-pc-windows-gnu --enable-full-tools --enable-profiler --set llvm.allow-old-toolchain"
440+
NO_DOWNLOAD_CI_LLVM: 1
436441
SCRIPT: python x.py dist
437442
CUSTOM_MINGW: 1
438443
DIST_REQUIRE_ALL_TOOLS: 1
@@ -441,6 +446,7 @@ jobs:
441446
env:
442447
SCRIPT: python x.py dist
443448
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler --set llvm.allow-old-toolchain"
449+
NO_DOWNLOAD_CI_LLVM: 1
444450
CUSTOM_MINGW: 1
445451
DIST_REQUIRE_ALL_TOOLS: 1
446452
os: windows-latest-xl

src/bootstrap/config.rs

+2-37
Original file line numberDiff line numberDiff line change
@@ -990,42 +990,7 @@ impl Config {
990990
config.llvm_from_ci = match llvm.download_ci_llvm {
991991
Some(StringOrBool::String(s)) => {
992992
assert!(s == "if-available", "unknown option `{}` for download-ci-llvm", s);
993-
// This is currently all tier 1 targets and tier 2 targets with host tools
994-
// (since others may not have CI artifacts)
995-
// https://doc.rust-lang.org/rustc/platform-support.html#tier-1
996-
// FIXME: this is duplicated in bootstrap.py
997-
let supported_platforms = [
998-
// tier 1
999-
"aarch64-unknown-linux-gnu",
1000-
"i686-pc-windows-gnu",
1001-
"i686-pc-windows-msvc",
1002-
"i686-unknown-linux-gnu",
1003-
"x86_64-unknown-linux-gnu",
1004-
"x86_64-apple-darwin",
1005-
"x86_64-pc-windows-gnu",
1006-
"x86_64-pc-windows-msvc",
1007-
// tier 2 with host tools
1008-
"aarch64-apple-darwin",
1009-
"aarch64-pc-windows-msvc",
1010-
"aarch64-unknown-linux-musl",
1011-
"arm-unknown-linux-gnueabi",
1012-
"arm-unknown-linux-gnueabihf",
1013-
"armv7-unknown-linux-gnueabihf",
1014-
"mips-unknown-linux-gnu",
1015-
"mips64-unknown-linux-gnuabi64",
1016-
"mips64el-unknown-linux-gnuabi64",
1017-
"mipsel-unknown-linux-gnu",
1018-
"powerpc-unknown-linux-gnu",
1019-
"powerpc64-unknown-linux-gnu",
1020-
"powerpc64le-unknown-linux-gnu",
1021-
"riscv64gc-unknown-linux-gnu",
1022-
"s390x-unknown-linux-gnu",
1023-
"x86_64-unknown-freebsd",
1024-
"x86_64-unknown-illumos",
1025-
"x86_64-unknown-linux-musl",
1026-
"x86_64-unknown-netbsd",
1027-
];
1028-
supported_platforms.contains(&&*config.build.triple)
993+
crate::native::is_ci_llvm_available(&config, llvm_assertions.unwrap_or(false))
1029994
}
1030995
Some(StringOrBool::Bool(b)) => b,
1031996
None => false,
@@ -1176,14 +1141,14 @@ impl Config {
11761141

11771142
if config.llvm_from_ci {
11781143
let triple = &config.build.triple;
1144+
let ci_llvm_bin = config.ci_llvm_root().join("bin");
11791145
let mut build_target = config
11801146
.target_config
11811147
.entry(config.build)
11821148
.or_insert_with(|| Target::from_triple(&triple));
11831149

11841150
check_ci_llvm!(build_target.llvm_config);
11851151
check_ci_llvm!(build_target.llvm_filecheck);
1186-
let ci_llvm_bin = config.out.join(&*config.build.triple).join("ci-llvm/bin");
11871152
build_target.llvm_config = Some(ci_llvm_bin.join(exe("llvm-config", config.build)));
11881153
build_target.llvm_filecheck = Some(ci_llvm_bin.join(exe("FileCheck", config.build)));
11891154
}

src/bootstrap/native.rs

+80-9
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,20 @@ pub fn prebuilt_llvm_config(
114114
Err(Meta { stamp, build_llvm_config, out_dir, root: root.into() })
115115
}
116116

117-
pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
118-
let config = &builder.config;
119-
if !config.llvm_from_ci {
120-
return;
121-
}
117+
/// This retrieves the LLVM sha we *want* to use, according to git history.
118+
pub(crate) fn detect_llvm_sha(config: &crate::config::Config) -> String {
122119
let mut rev_list = config.git();
123120
rev_list.args(&[
124121
PathBuf::from("rev-list"),
125-
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
122+
format!("--author={}", config.stage0_metadata.config.git_merge_commit_email).into(),
126123
"-n1".into(),
127124
"--first-parent".into(),
128125
"HEAD".into(),
129126
"--".into(),
130-
builder.src.join("src/llvm-project"),
131-
builder.src.join("src/bootstrap/download-ci-llvm-stamp"),
127+
config.src.join("src/llvm-project"),
128+
config.src.join("src/bootstrap/download-ci-llvm-stamp"),
132129
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
133-
builder.src.join("src/version"),
130+
config.src.join("src/version"),
134131
]);
135132
let llvm_sha = output(&mut rev_list);
136133
let llvm_sha = llvm_sha.trim();
@@ -143,8 +140,82 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
143140
panic!();
144141
}
145142

143+
llvm_sha.to_owned()
144+
}
145+
146+
/// Returns whether the CI-found LLVM is currently usable.
147+
///
148+
/// This checks both the build triple platform to confirm we're usable at all,
149+
/// and then verifies if the current HEAD matches the detected LLVM SHA head,
150+
/// in which case LLVM is indicated as not available.
151+
pub(crate) fn is_ci_llvm_available(config: &crate::config::Config, asserts: bool) -> bool {
152+
// This is currently all tier 1 targets and tier 2 targets with host tools
153+
// (since others may not have CI artifacts)
154+
// https://doc.rust-lang.org/rustc/platform-support.html#tier-1
155+
let supported_platforms = [
156+
// tier 1
157+
"aarch64-unknown-linux-gnu",
158+
"i686-pc-windows-gnu",
159+
"i686-pc-windows-msvc",
160+
"i686-unknown-linux-gnu",
161+
"x86_64-unknown-linux-gnu",
162+
"x86_64-apple-darwin",
163+
"x86_64-pc-windows-gnu",
164+
"x86_64-pc-windows-msvc",
165+
// tier 2 with host tools
166+
"aarch64-apple-darwin",
167+
"aarch64-pc-windows-msvc",
168+
"aarch64-unknown-linux-musl",
169+
"arm-unknown-linux-gnueabi",
170+
"arm-unknown-linux-gnueabihf",
171+
"armv7-unknown-linux-gnueabihf",
172+
"mips-unknown-linux-gnu",
173+
"mips64-unknown-linux-gnuabi64",
174+
"mips64el-unknown-linux-gnuabi64",
175+
"mipsel-unknown-linux-gnu",
176+
"powerpc-unknown-linux-gnu",
177+
"powerpc64-unknown-linux-gnu",
178+
"powerpc64le-unknown-linux-gnu",
179+
"riscv64gc-unknown-linux-gnu",
180+
"s390x-unknown-linux-gnu",
181+
"x86_64-unknown-freebsd",
182+
"x86_64-unknown-illumos",
183+
"x86_64-unknown-linux-musl",
184+
"x86_64-unknown-netbsd",
185+
];
186+
if !supported_platforms.contains(&&*config.build.triple) {
187+
return false;
188+
}
189+
190+
let triple = &*config.build.triple;
191+
if (triple == "aarch64-unknown-linux-gnu" || triple.contains("i686")) && asserts {
192+
// No alt builder for aarch64-unknown-linux-gnu today.
193+
return false;
194+
}
195+
196+
if crate::util::CiEnv::is_ci() {
197+
let llvm_sha = detect_llvm_sha(config);
198+
let head_sha = output(config.git().arg("rev-parse").arg("HEAD"));
199+
let head_sha = head_sha.trim();
200+
if llvm_sha == head_sha {
201+
eprintln!(
202+
"Detected LLVM as non-available: running in CI and modified LLVM in this change"
203+
);
204+
return false;
205+
}
206+
}
207+
208+
true
209+
}
210+
211+
pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
212+
let config = &builder.config;
213+
if !config.llvm_from_ci {
214+
return;
215+
}
146216
let llvm_root = config.ci_llvm_root();
147217
let llvm_stamp = llvm_root.join(".llvm-stamp");
218+
let llvm_sha = detect_llvm_sha(&config);
148219
let key = format!("{}{}", llvm_sha, config.llvm_assertions);
149220
if program_out_of_date(&llvm_stamp, &key) && !config.dry_run {
150221
download_ci_llvm(builder, &llvm_sha);

src/bootstrap/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ impl CiEnv {
258258
}
259259
}
260260

261+
pub fn is_ci() -> bool {
262+
Self::current() != CiEnv::None
263+
}
264+
261265
/// If in a CI environment, forces the command to run with colors.
262266
pub fn force_coloring_in_ci(self, cmd: &mut Command) {
263267
if self != CiEnv::None {

src/ci/docker/host-x86_64/arm-android/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ ENV PATH=$PATH:/android/sdk/platform-tools
2929

3030
ENV TARGETS=arm-linux-androideabi
3131

32+
# We are intentionally allowing an old toolchain on this builder (and that's
33+
# incompatible with LLVM downloads today).
34+
ENV NO_DOWNLOAD_CI_LLVM 1
35+
3236
ENV RUST_CONFIGURE_ARGS --arm-linux-androideabi-ndk=/android/ndk/arm-14 \
3337
--set llvm.allow-old-toolchain
3438

src/ci/docker/host-x86_64/armhf-gnu/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ RUN curl -O https://ci-mirrors.rust-lang.org/rustc/vexpress-v2p-ca15-tc1.dtb
7878
COPY scripts/sccache.sh /scripts/
7979
RUN sh /scripts/sccache.sh
8080

81+
COPY static/gitconfig /etc/gitconfig
82+
8183
ENV RUST_CONFIGURE_ARGS --qemu-armhf-rootfs=/tmp/rootfs
8284
ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target arm-unknown-linux-gnueabihf
8385

src/ci/docker/host-x86_64/i686-gnu-nopt/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ RUN mkdir -p /config
2727
RUN echo "[rust]" > /config/nopt-std-config.toml
2828
RUN echo "optimize = false" >> /config/nopt-std-config.toml
2929

30+
# We are intentionally allowing an old toolchain on this builder (and that's
31+
# incompatible with LLVM downloads today).
32+
ENV NO_DOWNLOAD_CI_LLVM 1
33+
3034
ENV RUST_CONFIGURE_ARGS --build=i686-unknown-linux-gnu --disable-optimize-tests \
3135
--set llvm.allow-old-toolchain
3236
ENV SCRIPT python3 ../x.py test --stage 0 --config /config/nopt-std-config.toml library/std \

src/ci/docker/host-x86_64/i686-gnu/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ RUN sh /scripts/sccache.sh
2323
COPY scripts/cmake.sh /scripts/
2424
RUN /scripts/cmake.sh
2525

26+
# We are intentionally allowing an old toolchain on this builder (and that's
27+
# incompatible with LLVM downloads today).
28+
ENV NO_DOWNLOAD_CI_LLVM 1
2629
ENV RUST_CONFIGURE_ARGS --build=i686-unknown-linux-gnu \
2730
--set llvm.allow-old-toolchain
2831
# Exclude some tests that are unlikely to be platform specific, to speed up

src/ci/docker/host-x86_64/test-various/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ WORKDIR /
3030
COPY scripts/sccache.sh /scripts/
3131
RUN sh /scripts/sccache.sh
3232

33+
# We are disabling CI LLVM since this builder needs to build LLD, which is
34+
# currently unsupported when downloading pre-built LLVM.
35+
ENV NO_DOWNLOAD_CI_LLVM 1
36+
3337
ENV RUST_CONFIGURE_ARGS \
3438
--musl-root-x86_64=/usr/local/x86_64-linux-musl \
3539
--set build.nodejs=/node-v15.14.0-linux-x64/bin/node \

src/ci/docker/host-x86_64/wasm32/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ ENV TARGETS=wasm32-unknown-emscripten
4848
# Use -O1 optimizations in the link step to reduce time spent optimizing.
4949
ENV EMCC_CFLAGS=-O1
5050

51+
COPY static/gitconfig /etc/gitconfig
52+
5153
# Emscripten installation is user-specific
5254
ENV NO_CHANGE_USER=1
5355

src/ci/docker/host-x86_64/x86_64-gnu-aux/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ RUN sh /scripts/sccache.sh
2626
COPY scripts/cmake.sh /scripts/
2727
RUN /scripts/cmake.sh
2828

29+
# We are intentionally allowing an old toolchain on this builder (and that's
30+
# incompatible with LLVM downloads today).
31+
ENV NO_DOWNLOAD_CI_LLVM 1
32+
2933
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu \
3034
--set llvm.allow-old-toolchain
3135
ENV RUST_CHECK_TARGET check-aux

src/ci/docker/host-x86_64/x86_64-gnu-debug/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ RUN sh /scripts/sccache.sh
3131
ENV RUSTBUILD_FORCE_CLANG_BASED_TESTS 1
3232
ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
3333

34+
# llvm.use-linker conflicts with downloading CI LLVM
35+
ENV NO_DOWNLOAD_CI_LLVM 1
36+
3437
ENV RUST_CONFIGURE_ARGS \
3538
--build=x86_64-unknown-linux-gnu \
3639
--enable-debug \

src/ci/docker/host-x86_64/x86_64-gnu-distcheck/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ RUN sh /scripts/sccache.sh
2222
COPY scripts/cmake.sh /scripts/
2323
RUN /scripts/cmake.sh
2424

25+
# We are intentionally allowing an old toolchain on this builder (and that's
26+
# incompatible with LLVM downloads today).
27+
ENV NO_DOWNLOAD_CI_LLVM 1
28+
2529
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu --set rust.ignore-git=false \
2630
--set llvm.allow-old-toolchain
2731
ENV SCRIPT python3 ../x.py --stage 2 test distcheck

src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2626
COPY scripts/sccache.sh /scripts/
2727
RUN sh /scripts/sccache.sh
2828

29-
# using llvm-link-shared due to libffi issues -- see #34486
29+
# We are disabling CI LLVM since this builder is intentionally using a host
30+
# LLVM, rather than the typical src/llvm-project LLVM.
31+
ENV NO_DOWNLOAD_CI_LLVM 1
32+
33+
# Using llvm-link-shared due to libffi issues -- see #34486
3034
ENV RUST_CONFIGURE_ARGS \
3135
--build=x86_64-unknown-linux-gnu \
3236
--llvm-root=/usr/lib/llvm-13 \

src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ RUN apt-get update && \
3737
COPY scripts/sccache.sh /scripts/
3838
RUN sh /scripts/sccache.sh
3939

40-
# using llvm-link-shared due to libffi issues -- see #34486
40+
# We are disabling CI LLVM since this builder is intentionally using a host
41+
# LLVM, rather than the typical src/llvm-project LLVM.
42+
ENV NO_DOWNLOAD_CI_LLVM 1
43+
44+
# Using llvm-link-shared due to libffi issues -- see #34486
4145
ENV RUST_CONFIGURE_ARGS \
4246
--build=x86_64-unknown-linux-gnu \
4347
--llvm-root=/usr/lib/llvm-13 \

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/
8080
# the local version of the package is different than the one used by the CI.
8181
RUN npm install -g browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true
8282

83+
# We are intentionally allowing an old toolchain on this builder (and that's
84+
# incompatible with LLVM downloads today).
85+
ENV NO_DOWNLOAD_CI_LLVM 1
86+
8387
ENV RUST_CONFIGURE_ARGS \
8488
--set llvm.allow-old-toolchain \
8589
--build=x86_64-unknown-linux-gnu \

src/ci/docker/static/gitconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[safe]
2+
directory = *

0 commit comments

Comments
 (0)