Skip to content

Commit bcf8683

Browse files
committed
ci: Test with LLVM downloaded from Rust CI
We are planning to use libLLVM from Rust CI to produce static binaries. This change makes sure that tests work with Rust's libLLVM artifacts. Rust CI ships only one flavor of libLLVM, shared or static, per target. Linux GNU targets come with shared ones. Apple and Linux musl targets come with dynamic ones. To save disk space, run `cargo hack --feature-powerset` only when shared libraries are used. Otherwise, run cargo with a single feature set.
1 parent 27cc226 commit bcf8683

File tree

1 file changed

+119
-21
lines changed

1 file changed

+119
-21
lines changed

.github/workflows/ci.yml

Lines changed: 119 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,24 @@ jobs:
6666
llvm: 21
6767
exclude-features: llvm-19,llvm-20,rust-llvm-19,rust-llvm-20
6868
platform:
69+
# Rust CI ships only one flavor of libLLVM, shared or static, per
70+
# target. Linux GNU targets come with shared ones. Apple and Linux
71+
# musl targets come with dynamic ones.
6972
- os: macos-latest
73+
static-target: aarch64-apple-darwin
7074
- os: macos-15-intel
75+
static-target: x86_64-apple-darwin
76+
linkage: static
7177
- os: ubuntu-22.04
78+
shared-target: x86_64-unknown-linux-gnu
79+
static-target: x86_64-unknown-linux-musl
7280
- os: ubuntu-22.04-arm
81+
shared-target: aarch64-unknown-linux-gnu
82+
static-target: aarch64-unknown-linux-musl
7383
llvm-from:
7484
- packages
85+
- rust-ci-shared
86+
- rust-ci-static
7587
include:
7688
# Currently we build LLVM from source only for Linux x86_64.
7789
- toolchain:
@@ -81,13 +93,34 @@ jobs:
8193
platform:
8294
os: ubuntu-22.04
8395
llvm-from: source
96+
exclude:
97+
# Rust CI does not provide LLVM 19 anymore.
98+
- toolchain:
99+
llvm: 19
100+
llvm-from: rust-ci-shared
101+
- toolchain:
102+
llvm: 19
103+
llvm-from: rust-ci-static
104+
# There is no macOS target that Rust CI ships shared libraries for.
105+
- platform:
106+
os: macos-latest
107+
llvm-from: rust-ci-shared
108+
- platform:
109+
os: macos-15-intel
110+
llvm-from: rust-ci-shared
84111
name: os=${{ matrix.platform.os }} rustc=${{ matrix.toolchain.rust }} llvm-version=${{ matrix.toolchain.llvm }} llvm-from=${{ matrix.llvm-from }}
85112
needs: llvm
86113

87114
env:
88115
RUST_BACKTRACE: full
89-
LLVM_FEATURES: llvm-${{ matrix.toolchain.llvm }}
90-
LLVM_EXCLUDE_FEATURES: deps-link-static,llvm-link-static,no-llvm-linking
116+
# Features that have to be included for dynamic linking.
117+
LLVM_FEATURES_DYNAMIC: llvm-${{ matrix.toolchain.llvm }}
118+
# Features that have to be included for static linking.
119+
LLVM_FEATURES_STATIC: llvm-${{ matrix.toolchain.llvm }},deps-link-static,llvm-link-static
120+
# Features that have to be excluded when running `cargo hack --feature-powerset`
121+
# and intending to link dynamically.
122+
LLVM_EXCLUDE_FEATURES_DYNAMIC: deps-link-static,llvm-link-static,no-llvm-linking
123+
RUSTC_LLVM_INSTALL_DIR: /tmp/rustc-llvm
91124

92125
steps:
93126
- uses: actions/checkout@v5
@@ -124,25 +157,51 @@ jobs:
124157
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d
125158
run: echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
126159

127-
- name: Install LLVM (Linux, packages)
128-
if: matrix.llvm-from == 'packages' && runner.os == 'Linux'
160+
- name: Add LLVM APT repository
161+
if: runner.os == 'Linux'
129162
run: |
130163
set -euxo pipefail
131164
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
132165
echo -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.toolchain.llvm }} main | sudo tee /etc/apt/sources.list.d/llvm.list
133-
134166
sudo apt update
167+
168+
- name: Install LLVM (Linux, packages)
169+
if: matrix.llvm-from == 'packages' && runner.os == 'Linux'
170+
run: |
171+
set -euxo pipefail
135172
sudo apt -y install llvm-${{ matrix.toolchain.llvm }}-dev
136173
echo /usr/lib/llvm-${{ matrix.toolchain.llvm }}/bin >> $GITHUB_PATH
137174
175+
- name: Install FileCheck (Linux)
176+
if: (matrix.llvm-from == 'rust-ci-shared' || matrix.llvm-from == 'rust-ci-static') && runner.os == 'Linux'
177+
run: |
178+
set -euxo pipefail
179+
sudo apt -y install llvm-${{ matrix.toolchain.llvm }}-tools
180+
echo /usr/lib/llvm-${{ matrix.toolchain.llvm }}/bin >> $GITHUB_PATH
181+
138182
- name: Install LLVM (macOS, packages)
139183
if: matrix.llvm-from == 'packages' && runner.os == 'macOS'
140184
run: |
141185
set -euxo pipefail
142186
brew install llvm@${{ matrix.toolchain.llvm }}
143187
echo $(brew --prefix llvm@${{ matrix.toolchain.llvm }})/bin >> $GITHUB_PATH
144188
145-
- name: Restore LLVM
189+
- name: Install LLVM from Rust CI
190+
if: matrix.llvm-from == 'rust-ci-shared' || matrix.llvm-from == 'rust-ci-static'
191+
run: |
192+
set -euxo pipefail
193+
mkdir -p $RUSTC_LLVM_INSTALL_DIR
194+
rustc_sha=$(cargo xtask rustc-llvm-commit --github-token ${{ secrets.GITHUB_TOKEN }})
195+
if [ "${{ matrix.llvm-from }}" = "rust-ci-shared" ]; then
196+
target="${{ matrix.platform['shared-target'] }}"
197+
else
198+
target="${{ matrix.platform['static-target'] }}"
199+
fi
200+
wget -q -O - "https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-$target.tar.xz" | \
201+
tar -xJ --strip-components 2 -C $RUSTC_LLVM_INSTALL_DIR
202+
echo "${RUSTC_LLVM_INSTALL_DIR}/bin" >> $GITHUB_PATH
203+
204+
- name: Restore LLVM from our GitHub cache
146205
if: matrix.llvm-from == 'source'
147206
uses: actions/cache/restore@v4
148207
with:
@@ -169,17 +228,33 @@ jobs:
169228
170229
- uses: taiki-e/install-action@cargo-hack
171230

172-
- name: Check
231+
- name: Check (dynamic linking, feature powerset)
232+
# Static linking in combination with `cargo hack --feature-powerset`
233+
# (multiple builds) increases the disk usage massively.
234+
if: matrix.llvm-from != 'rust-ci-static'
173235
run: |
174236
cargo hack check --feature-powerset \
175-
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
176-
--features ${{ env.LLVM_FEATURES }}
237+
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }} \
238+
--features ${{ env.LLVM_FEATURES_DYNAMIC }}
239+
240+
- name: Check (static linking, single feature set)
241+
if: matrix.llvm-from == 'rust-ci-static'
242+
run: |
243+
cargo check --no-default-features \
244+
--features ${{ env.LLVM_FEATURES_STATIC }}
177245
178-
- name: Build
246+
- name: Build (dynamic linking, feature powerset)
247+
if: matrix.llvm-from != 'rust-ci-static'
179248
run: |
180249
cargo hack build --feature-powerset \
181-
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
182-
--features ${{ env.LLVM_FEATURES }}
250+
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }} \
251+
--features ${{ env.LLVM_FEATURES_DYNAMIC }}
252+
253+
- name: Build (static linking, single feature set)
254+
if: matrix.llvm-from == 'rust-ci-static'
255+
run: |
256+
cargo build --no-default-features \
257+
--features ${{ env.LLVM_FEATURES_STATIC }}
183258
184259
# Toolchains provided by rustup include standard library artifacts
185260
# only for Tier 1 targets, which do not include BPF targets.
@@ -189,11 +264,18 @@ jobs:
189264
# running compiler tests.
190265
#
191266
# `RUSTC_BOOTSTRAP` is needed to use `rustc-build-sysroot` on stable Rust.
192-
- name: Test (sysroot built on demand)
267+
- name: Test (sysroot built on demand, dynamic linking)
268+
if: matrix.llvm-from != 'rust-ci-static'
193269
run: |
194270
RUSTC_BOOTSTRAP=1 cargo hack test --feature-powerset \
195-
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
196-
--features ${{ env.LLVM_FEATURES }}
271+
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }} \
272+
--features ${{ env.LLVM_FEATURES_DYNAMIC }}
273+
274+
- name: Test (sysroot built on demand, static linking)
275+
if: matrix.llvm-from == 'rust-ci-static'
276+
run: |
277+
RUSTC_BOOTSTRAP=1 cargo test --no-default-features \
278+
--features ${{ env.LLVM_FEATURES_STATIC }}
197279
198280
# To make things easier for package maintainers, the step of building a
199281
# custom sysroot can be skipped by setting the `BPFEL_SYSROOT_DIR`
@@ -204,7 +286,7 @@ jobs:
204286
#
205287
# `RUSTC_BOOTSTRAP` is needed to make `xtask build-std` work on stable
206288
# Rust.
207-
- name: Test (prebuilt BPF standard library)
289+
- name: Build BPF standard library
208290
run: |
209291
set -euxo pipefail
210292
@@ -214,10 +296,22 @@ jobs:
214296
--rustc-src "$RUSTC_SRC" \
215297
--sysroot-dir "$BPFEL_SYSROOT_DIR" \
216298
--target bpfel-unknown-none
299+
echo "BPFEL_SYSROOT_DIR=${BPFEL_SYSROOT_DIR}" >> $GITHUB_ENV
217300
301+
- name: Test (prebuilt BPF standard libary, dynamic linking)
302+
if: matrix.llvm-from != 'rust-ci-static'
303+
run: |
304+
set -euxo pipefail
218305
BPFEL_SYSROOT_DIR="$BPFEL_SYSROOT_DIR" cargo hack test --feature-powerset \
219-
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
220-
--features ${{ env.LLVM_FEATURES }}
306+
--exclude-features ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }} \
307+
--features ${{ env.LLVM_FEATURES_DYNAMIC }}
308+
309+
- name: Test (prebuilt BPF standard library, static linking)
310+
if: matrix.llvm-from == 'rust-ci-static'
311+
run: |
312+
set -euxo pipefail
313+
BPFEL_SYSROOT_DIR="$BPFEL_SYSROOT_DIR" cargo test --no-default-features \
314+
--features ${{ env.LLVM_FEATURES_STATIC }}
221315
222316
- uses: actions/checkout@v5
223317
if: matrix.toolchain.rust == 'nightly'
@@ -226,9 +320,13 @@ jobs:
226320
path: aya
227321
submodules: recursive
228322

229-
- name: Install
230-
if: matrix.toolchain.rust == 'nightly'
231-
run: cargo install --path . --no-default-features --features ${{ env.LLVM_FEATURES }}
323+
- name: Install (dynamic linking)
324+
if: matrix.toolchain.rust == 'nightly' && matrix.llvm-from != 'rust-ci-static'
325+
run: cargo install --path . --no-default-features --features ${{ env.LLVM_FEATURES_DYNAMIC }}
326+
327+
- name: Install (static linking)
328+
if: matrix.toolchain.rust == 'nightly' && matrix.llvm-from == 'rust-ci-static'
329+
run: cargo install --path . --no-default-features --features ${{ env.LLVM_FEATURES_STATIC }}
232330

233331
- name: Run aya integration tests
234332
if: matrix.toolchain.rust == 'nightly'

0 commit comments

Comments
 (0)