Skip to content

Commit d156b32

Browse files
committed
Auto merge of #133807 - mrkajetanp:ci-aarch64-opt-dist, r=<try>
ci: Enable opt-dist for dist-aarch64-linux builds Move the CI dist-aarch64-linux job to an aarch64 runner and enable optimised dist builds with the opt-dist pipeline. For the time being, disable bolt on aarch64 due to upstream bolt bugs. r? `@Kobzol` cc `@lqd` try-job: dist-aarch64-linux
2 parents c44b3d5 + 02b958d commit d156b32

File tree

8 files changed

+153
-56
lines changed

8 files changed

+153
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM ubuntu:22.04
2+
3+
WORKDIR /build
4+
5+
RUN apt-get update && \
6+
apt-get install -y pkg-config curl xz-utils wget unzip git make patch perl lbzip2 gcc g++ libc6-dev cmake python3 doxygen graphviz zstd libzstd-dev openssl libssl-dev
7+
8+
ENV PATH=/rustroot/bin:$PATH
9+
10+
WORKDIR /tmp
11+
COPY host-aarch64/dist-aarch64-linux/shared.sh /tmp/
12+
13+
ENV CC=gcc CXX=g++
14+
15+
# Build LLVM+Clang
16+
COPY host-aarch64/dist-aarch64-linux/build-clang.sh /tmp/
17+
RUN ./build-clang.sh
18+
ENV CC=clang CXX=clang++
19+
20+
COPY scripts/sccache.sh /scripts/
21+
RUN sh /scripts/sccache.sh
22+
23+
ENV PGO_HOST=aarch64-unknown-linux-gnu
24+
ENV HOSTS=aarch64-unknown-linux-gnu
25+
26+
ENV CPATH=/usr/include/aarch64-linux-gnu/:$CPATH
27+
28+
ENV RUST_CONFIGURE_ARGS \
29+
--build=aarch64-unknown-linux-gnu \
30+
--enable-full-tools \
31+
--enable-profiler \
32+
--enable-sanitizers \
33+
--enable-compiler-docs \
34+
--set target.aarch64-unknown-linux-gnu.linker=clang \
35+
--set target.aarch64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
36+
--set target.aarch64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib \
37+
--set llvm.link-shared=true \
38+
--set llvm.thin-lto=true \
39+
--set llvm.libzstd=true \
40+
--set llvm.ninja=false \
41+
--set rust.debug-assertions=false \
42+
--set rust.jemalloc \
43+
--set rust.use-lld=true \
44+
--set rust.lto=thin \
45+
--set rust.codegen-units=1
46+
47+
48+
ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \
49+
./build/$HOSTS/stage0-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \
50+
--host $HOSTS --target $HOSTS --include-default-paths build-manifest bootstrap
51+
52+
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=clang
53+
ENV DIST_SRC 1
54+
ENV DIST_REQUIRE_ALL_TOOLS 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
source shared.sh
6+
7+
# Try to keep the LLVM version here in sync with src/ci/scripts/install-clang.sh
8+
LLVM=llvmorg-19.1.5
9+
10+
mkdir llvm-project
11+
cd llvm-project
12+
13+
curl -L https://github.com/llvm/llvm-project/archive/$LLVM.tar.gz | \
14+
tar xzf - --strip-components=1
15+
16+
mkdir clang-build
17+
cd clang-build
18+
19+
# For whatever reason the default set of include paths for clang is different
20+
# than that of gcc. As a result we need to manually include our sysroot's
21+
# include path, /rustroot/include, to clang's default include path.
22+
INC="/rustroot/include:/usr/include"
23+
24+
# We need compiler-rt for the profile runtime (used later to PGO the LLVM build)
25+
# but sanitizers aren't currently building. Since we don't need those, just
26+
# disable them. BOLT is used for optimizing LLVM.
27+
hide_output \
28+
cmake ../llvm \
29+
-DCMAKE_BUILD_TYPE=Release \
30+
-DCMAKE_INSTALL_PREFIX=/rustroot \
31+
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
32+
-DCOMPILER_RT_BUILD_XRAY=OFF \
33+
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
34+
-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF \
35+
-DLLVM_TARGETS_TO_BUILD=AArch64 \
36+
-DLLVM_INCLUDE_BENCHMARKS=OFF \
37+
-DLLVM_INCLUDE_TESTS=OFF \
38+
-DLLVM_INCLUDE_EXAMPLES=OFF \
39+
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt;bolt" \
40+
-DC_INCLUDE_DIRS="$INC"
41+
42+
hide_output make -j$(nproc)
43+
hide_output make install
44+
45+
cd ../..
46+
rm -rf llvm-project
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
hide_output() {
3+
set +x
4+
on_err="
5+
echo ERROR: An error was encountered with the build.
6+
cat /tmp/build.log
7+
exit 1
8+
"
9+
trap "$on_err" ERR
10+
bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
11+
PING_LOOP_PID=$!
12+
"$@" &> /tmp/build.log
13+
trap - ERR
14+
kill $PING_LOOP_PID
15+
set -x
16+
}

src/ci/docker/host-x86_64/dist-aarch64-linux/Dockerfile

-32
This file was deleted.

src/ci/docker/host-x86_64/dist-aarch64-linux/aarch64-linux-gnu.defconfig

-10
This file was deleted.

src/ci/github-actions/jobs.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ auto:
128128
- image: aarch64-gnu-debug
129129
<<: *job-aarch64-linux
130130

131+
- image: dist-aarch64-linux
132+
env:
133+
CODEGEN_BACKENDS: llvm,cranelift
134+
<<: *job-aarch64-linux
135+
131136
- image: arm-android
132137
<<: *job-linux-4c
133138

134139
- image: armhf-gnu
135140
<<: *job-linux-4c
136141

137-
- image: dist-aarch64-linux
138-
env:
139-
CODEGEN_BACKENDS: llvm,cranelift
140-
<<: *job-linux-4c
141-
142142
- image: dist-android
143143
<<: *job-linux-4c
144144

src/tools/opt-dist/src/bolt.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Context;
22
use camino::{Utf8Path, Utf8PathBuf};
33

4+
use crate::environment::Environment;
45
use crate::exec::cmd;
56
use crate::training::BoltProfile;
67
use crate::utils::io::copy_file;
@@ -45,13 +46,21 @@ pub fn with_bolt_instrumented<F: FnOnce(&Utf8Path) -> anyhow::Result<R>, R>(
4546
}
4647

4748
/// Optimizes the file at `path` with BOLT in-place using the given `profile`.
48-
pub fn bolt_optimize(path: &Utf8Path, profile: &BoltProfile) -> anyhow::Result<()> {
49+
pub fn bolt_optimize(
50+
path: &Utf8Path,
51+
profile: &BoltProfile,
52+
env: &Environment,
53+
) -> anyhow::Result<()> {
4954
// Copy the artifact to a new location, so that we do not use the same input and output file.
5055
// BOLT cannot handle optimizing when the input and output is the same file, because it performs
5156
// in-place patching.
5257
let temp_path = tempfile::NamedTempFile::new()?.into_temp_path();
5358
copy_file(path, &temp_path)?;
5459

60+
// FIXME: cdsplit in llvm-bolt is currently broken on AArch64, drop this once it's fixed upstream
61+
let split_strategy =
62+
if env.host_tuple().starts_with("aarch64") { "profile2" } else { "cdsplit" };
63+
5564
cmd(&["llvm-bolt"])
5665
.arg(temp_path.display())
5766
.arg("-data")
@@ -65,7 +74,7 @@ pub fn bolt_optimize(path: &Utf8Path, profile: &BoltProfile) -> anyhow::Result<(
6574
// Split function code into hot and code regions
6675
.arg("-split-functions")
6776
// Split using best available strategy (three-way splitting, Cache-Directed Sort)
68-
.arg("-split-strategy=cdsplit")
77+
.arg(format!("-split-strategy={split_strategy}"))
6978
// Split as many basic blocks as possible
7079
.arg("-split-all-cold")
7180
// Move jump tables to a separate section

src/tools/opt-dist/src/main.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
146146
let target_triple =
147147
std::env::var("PGO_HOST").expect("PGO_HOST environment variable missing");
148148

149+
let is_aarch64 = target_triple.starts_with("aarch64");
150+
151+
let mut skip_tests = vec![
152+
// Fails because of linker errors, as of June 2023.
153+
"tests/ui/process/nofile-limit.rs".to_string(),
154+
];
155+
156+
if is_aarch64 {
157+
skip_tests.extend([
158+
// Those tests fail only inside of Docker on aarch64, as of December 2024
159+
"tests/ui/consts/promoted_running_out_of_memory_issue-130687.rs".to_string(),
160+
"tests/ui/consts/large_const_alloc.rs".to_string(),
161+
]);
162+
}
163+
149164
let checkout_dir = Utf8PathBuf::from("/checkout");
150165
let env = EnvironmentBuilder::default()
151166
.host_tuple(target_triple)
@@ -155,11 +170,9 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
155170
.artifact_dir(Utf8PathBuf::from("/tmp/tmp-multistage/opt-artifacts"))
156171
.build_dir(checkout_dir.join("obj"))
157172
.shared_llvm(true)
158-
.use_bolt(true)
159-
.skipped_tests(vec![
160-
// Fails because of linker errors, as of June 2023.
161-
"tests/ui/process/nofile-limit.rs".to_string(),
162-
])
173+
// FIXME: Enable bolt for aarch64 once it's fixed upstream. Broken as of December 2024.
174+
.use_bolt(!is_aarch64)
175+
.skipped_tests(skip_tests)
163176
.build()?;
164177

165178
(env, shared.build_args)
@@ -304,7 +317,8 @@ fn execute_pipeline(
304317
// the final dist build. However, when BOLT optimizes an artifact, it does so *in-place*,
305318
// therefore it will actually optimize all the hard links, which means that the final
306319
// packaged `libLLVM.so` file *will* be BOLT optimized.
307-
bolt_optimize(&llvm_lib, &llvm_profile).context("Could not optimize LLVM with BOLT")?;
320+
bolt_optimize(&llvm_lib, &llvm_profile, env)
321+
.context("Could not optimize LLVM with BOLT")?;
308322

309323
let rustc_lib = io::find_file_in_dir(&libdir, "librustc_driver", ".so")?;
310324

@@ -319,7 +333,7 @@ fn execute_pipeline(
319333
print_free_disk_space()?;
320334

321335
// Now optimize the library with BOLT.
322-
bolt_optimize(&rustc_lib, &rustc_profile)
336+
bolt_optimize(&rustc_lib, &rustc_profile, env)
323337
.context("Could not optimize rustc with BOLT")?;
324338

325339
// LLVM is not being cleared here, we want to use the BOLT-optimized LLVM

0 commit comments

Comments
 (0)