@@ -68,12 +68,33 @@ jobs:
6868 llvm : 21
6969 exclude-features : llvm-19,llvm-20,rust-llvm-19,rust-llvm-20
7070 platform :
71+ # Rust CI ships only one flavor of libLLVM, shared or static, per
72+ # target. Linux GNU targets come with shared ones. Apple and Linux
73+ # musl targets come with dynamic ones.
7174 - os : macos-latest
75+ static-target : aarch64-apple-darwin
76+ # Rust does not provide a shared libLLVM library on macOS,
77+ # therefore we exclude `default` and `rust-llvm-*`.
78+ # macOS does not provide static libc++ and zlib and the ones
79+ # provided by homebrew might be ABI-incompatible, therefore we
80+ # exclude `llvm-deps-link-static`.
81+ exclude-features : default,llvm-deps-link-static,rust-llvm-19,rust-llvm-20,rust-llvm-21
7282 - os : macos-15-intel
83+ static-target : x86_64-apple-darwin
84+ exclude-features : default,llvm-deps-link-static,rust-llvm-19,rust-llvm-20,rust-llvm-21
7385 - os : ubuntu-22.04
86+ shared-target : x86_64-unknown-linux-gnu
87+ static-target : x86_64-unknown-linux-musl
88+ # Link dependencies like libc++, zlib, zstd statically on Linux.
89+ llvm-features-static : llvm-deps-link-static
7490 - os : ubuntu-22.04-arm
91+ shared-target : aarch64-unknown-linux-gnu
92+ static-target : aarch64-unknown-linux-musl
93+ llvm-features-static : llvm-deps-link-static
7594 llvm-from :
7695 - packages
96+ - rust-ci-shared
97+ - rust-ci-static
7798 include :
7899 # Currently we build LLVM from source only for Linux x86_64.
79100 - toolchain :
@@ -83,13 +104,34 @@ jobs:
83104 platform :
84105 os : ubuntu-22.04
85106 llvm-from : source
107+ exclude :
108+ # Rust CI does not provide LLVM 19 anymore.
109+ - toolchain :
110+ llvm : 19
111+ llvm-from : rust-ci-shared
112+ - toolchain :
113+ llvm : 19
114+ llvm-from : rust-ci-static
115+ # There is no macOS target that Rust CI ships shared libraries for.
116+ - platform :
117+ os : macos-latest
118+ llvm-from : rust-ci-shared
119+ - platform :
120+ os : macos-15-intel
121+ llvm-from : rust-ci-shared
86122 name : os=${{ matrix.platform.os }} rustc=${{ matrix.toolchain.rust }} llvm-version=${{ matrix.toolchain.llvm }} llvm-from=${{ matrix.llvm-from }}
87123 needs : llvm
88124
89125 env :
90126 RUST_BACKTRACE : full
91- LLVM_FEATURES : llvm-${{ matrix.toolchain.llvm }}
92- LLVM_EXCLUDE_FEATURES : llvm-deps-link-static,llvm-link-static,no-llvm-linking
127+ # Features that have to be included for dynamic linking.
128+ LLVM_FEATURES_DYNAMIC : llvm-${{ matrix.toolchain.llvm }}
129+ # Features that have to be included for static linking.
130+ LLVM_FEATURES_STATIC : llvm-${{ matrix.toolchain.llvm }},llvm-link-static
131+ # Features that have to be excluded when running `cargo hack --feature-powerset`
132+ # and intending to link dynamically.
133+ LLVM_EXCLUDE_FEATURES_DYNAMIC : llvm-deps-link-static,llvm-link-static,no-llvm-linking
134+ RUSTC_LLVM_INSTALL_DIR : /tmp/rustc-llvm
93135
94136 steps :
95137 - uses : actions/checkout@v6
@@ -126,17 +168,28 @@ jobs:
126168 # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
127169 run : echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
128170
129- - name : Install LLVM (Linux, packages)
130- if : matrix.llvm-from == 'packages' && runner.os == 'Linux'
171+ - name : Add LLVM APT repository
172+ if : runner.os == 'Linux'
131173 run : |
132174 set -euxo pipefail
133175 wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
134176 echo -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.toolchain.llvm }} main | sudo tee /etc/apt/sources.list.d/llvm.list
135-
136177 sudo apt update
178+
179+ - name : Install LLVM (Linux, packages)
180+ if : matrix.llvm-from == 'packages' && runner.os == 'Linux'
181+ run : |
182+ set -euxo pipefail
137183 sudo apt -y install llvm-${{ matrix.toolchain.llvm }}-dev
138184 echo /usr/lib/llvm-${{ matrix.toolchain.llvm }}/bin >> $GITHUB_PATH
139185
186+ - name : Install FileCheck (Linux)
187+ if : (matrix.llvm-from == 'rust-ci-shared' || matrix.llvm-from == 'rust-ci-static') && runner.os == 'Linux'
188+ run : |
189+ set -euxo pipefail
190+ sudo apt -y install llvm-${{ matrix.toolchain.llvm }}-tools
191+ echo /usr/lib/llvm-${{ matrix.toolchain.llvm }}/bin >> $GITHUB_PATH
192+
140193 - name : Install LLVM (macOS, packages)
141194 if : matrix.llvm-from == 'packages' && runner.os == 'macOS'
142195 run : |
@@ -145,7 +198,31 @@ jobs:
145198 echo $(brew --prefix llvm@${{ matrix.toolchain.llvm }})/bin >> $GITHUB_PATH
146199 echo "DYLD_LIBRARY_PATH=$(brew --prefix llvm@${{ matrix.toolchain.llvm }})/lib" >> $GITHUB_ENV
147200
148- - name : Restore LLVM
201+ - name : Install LLVM from Rust CI
202+ if : matrix.llvm-from == 'rust-ci-shared' || matrix.llvm-from == 'rust-ci-static'
203+ run : |
204+ set -euxo pipefail
205+ mkdir -p $RUSTC_LLVM_INSTALL_DIR
206+ rustc_sha=$(cargo xtask rustc-llvm-commit --github-token ${{ secrets.GITHUB_TOKEN }})
207+ if [[ "${{ matrix.llvm-from }}" == "rust-ci-shared" ]]; then
208+ target="${{ matrix.platform['shared-target'] }}"
209+ else
210+ target="${{ matrix.platform['static-target'] }}"
211+ fi
212+ wget -q -O - "https://ci-artifacts.rust-lang.org/rustc-builds/$rustc_sha/rust-dev-nightly-$target.tar.xz" | \
213+ tar -xJ --strip-components 2 -C $RUSTC_LLVM_INSTALL_DIR
214+ echo "${RUSTC_LLVM_INSTALL_DIR}/bin" >> $GITHUB_PATH
215+ if [[ "${{ matrix.llvm-from }}" == "rust-ci-shared" ]]; then
216+ echo "LD_LIBRARY_PATH=${RUSTC_LLVM_INSTALL_DIR}/lib" >> $GITHUB_ENV
217+ fi
218+ # `FileCheck` binary shipped in musl tarballs is linked dynamically
219+ # to musl, we can't execute it on Ubuntu.
220+ if [[ "${{ runner.os }}" == "Linux"
221+ && "${{ matrix.llvm-from }}" == "rust-ci-static" ]]; then
222+ rm -f "${RUSTC_LLVM_INSTALL_DIR}/bin/FileCheck"
223+ fi
224+
225+ - name : Restore LLVM from our GitHub cache
149226 if : matrix.llvm-from == 'source'
150227 uses : actions/cache/restore@v4
151228 with :
@@ -172,17 +249,37 @@ jobs:
172249
173250 - uses : taiki-e/install-action@cargo-hack
174251
175- - name : Check
252+ - name : Check (dynamic linking, feature powerset)
253+ # Static linking in combination with `cargo hack --feature-powerset`
254+ # (multiple builds) increases the disk usage massively.
255+ if : matrix.llvm-from != 'rust-ci-static'
176256 run : |
177257 cargo hack check --feature-powerset \
178- --exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
179- --features ${{ env.LLVM_FEATURES }}
258+ --exclude-features \
259+ ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }},${{ matrix.platform.exclude-features }} \
260+ --features ${{ env.LLVM_FEATURES_DYNAMIC }}
261+
262+ - name : Check (static linking, single feature set)
263+ if : matrix.llvm-from == 'rust-ci-static'
264+ run : |
265+ cargo check --no-default-features \
266+ --features \
267+ ${{ env.LLVM_FEATURES_STATIC }},${{ matrix.platform.llvm-features-static }}
180268
181- - name : Build
269+ - name : Build (dynamic linking, feature powerset)
270+ if : matrix.llvm-from != 'rust-ci-static'
182271 run : |
183272 cargo hack build --feature-powerset \
184- --exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
185- --features ${{ env.LLVM_FEATURES }}
273+ --exclude-features \
274+ ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }},${{ matrix.platform.exclude-features }} \
275+ --features ${{ env.LLVM_FEATURES_DYNAMIC }}
276+
277+ - name : Build (static linking, single feature set)
278+ if : matrix.llvm-from == 'rust-ci-static'
279+ run : |
280+ cargo build --no-default-features \
281+ --features \
282+ ${{ env.LLVM_FEATURES_STATIC }},${{ matrix.platform.llvm-features-static }}
186283
187284 # Toolchains provided by rustup include standard library artifacts
188285 # only for Tier 1 targets, which do not include BPF targets.
@@ -192,11 +289,20 @@ jobs:
192289 # running compiler tests.
193290 #
194291 # `RUSTC_BOOTSTRAP` is needed to use `rustc-build-sysroot` on stable Rust.
195- - name : Test (sysroot built on demand)
292+ - name : Test (sysroot built on demand, dynamic linking)
293+ if : matrix.llvm-from != 'rust-ci-static'
196294 run : |
197295 RUSTC_BOOTSTRAP=1 cargo hack test --feature-powerset \
198- --exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
199- --features ${{ env.LLVM_FEATURES }}
296+ --exclude-features \
297+ ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }},${{ matrix.platform.exclude-features }} \
298+ --features ${{ env.LLVM_FEATURES_DYNAMIC }}
299+
300+ - name : Test (sysroot built on demand, static linking)
301+ if : matrix.llvm-from == 'rust-ci-static'
302+ run : |
303+ RUSTC_BOOTSTRAP=1 cargo test --no-default-features \
304+ --features \
305+ ${{ env.LLVM_FEATURES_STATIC }},${{ matrix.platform.llvm-features-static }}
200306
201307 # To make things easier for package maintainers, the step of building a
202308 # custom sysroot can be skipped by setting the `BPFEL_SYSROOT_DIR`
@@ -207,7 +313,7 @@ jobs:
207313 #
208314 # `RUSTC_BOOTSTRAP` is needed to make `xtask build-std` work on stable
209315 # Rust.
210- - name : Test (prebuilt BPF standard library)
316+ - name : Build BPF standard library
211317 run : |
212318 set -euxo pipefail
213319
@@ -217,10 +323,24 @@ jobs:
217323 --rustc-src "$RUSTC_SRC" \
218324 --sysroot-dir "$BPFEL_SYSROOT_DIR" \
219325 --target bpfel-unknown-none
326+ echo "BPFEL_SYSROOT_DIR=${BPFEL_SYSROOT_DIR}" >> $GITHUB_ENV
220327
328+ - name : Test (prebuilt BPF standard libary, dynamic linking)
329+ if : matrix.llvm-from != 'rust-ci-static'
330+ run : |
331+ set -euxo pipefail
221332 BPFEL_SYSROOT_DIR="$BPFEL_SYSROOT_DIR" cargo hack test --feature-powerset \
222- --exclude-features ${{ env.LLVM_EXCLUDE_FEATURES }},${{ matrix.toolchain.exclude-features }} \
223- --features ${{ env.LLVM_FEATURES }}
333+ --exclude-features \
334+ ${{ env.LLVM_EXCLUDE_FEATURES_DYNAMIC }},${{ matrix.toolchain.exclude-features }},${{ matrix.platform.exclude-features }} \
335+ --features ${{ env.LLVM_FEATURES_DYNAMIC }}
336+
337+ - name : Test (prebuilt BPF standard library, static linking)
338+ if : matrix.llvm-from == 'rust-ci-static'
339+ run : |
340+ set -euxo pipefail
341+ BPFEL_SYSROOT_DIR="$BPFEL_SYSROOT_DIR" cargo test --no-default-features \
342+ --features \
343+ ${{ env.LLVM_FEATURES_STATIC }},${{ matrix.platform.llvm-features-static }}
224344
225345 - uses : actions/checkout@v6
226346 if : runner.os == 'Linux' && matrix.toolchain.rust == 'nightly'
@@ -229,9 +349,16 @@ jobs:
229349 path : aya
230350 submodules : recursive
231351
232- - name : Install
233- if : runner.os == 'Linux' && matrix.toolchain.rust == 'nightly'
234- run : cargo install --path . --no-default-features --features ${{ env.LLVM_FEATURES }}
352+ - name : Install (dynamic linking)
353+ if : runner.os == 'Linux' && matrix.toolchain.rust == 'nightly' && matrix.llvm-from != 'rust-ci-static'
354+ run : |
355+ cargo install --path . --no-default-features --features \
356+ ${{ env.LLVM_FEATURES_DYNAMIC }}
357+
358+ - name : Install (static linking)
359+ if : runner.os == 'Linux' && matrix.toolchain.rust == 'nightly' && matrix.llvm-from == 'rust-ci-static'
360+ run : cargo install --path . --no-default-features --features \
361+ ${{ env.LLVM_FEATURES_STATIC }},${{ matrix.platform.llvm-features-static }}
235362
236363 - name : Run aya integration tests
237364 if : runner.os == 'Linux' && matrix.toolchain.rust == 'nightly'
0 commit comments