Skip to content

Commit 82d857e

Browse files
committed
ci: Specify target and static linking of C runtime explicitly
Without specifying the target, cargo uses the host target, which in case of Linux runners is `*-unknown-linux-gnu`. To test static linking to the full extent, use `*-unknown-linux-musl` targets. On top of that, make sure that libc and C runtime are actually linked statically by specifying `-C target-feature=+crt-static` rustflag. As of today, that's still a default option on the most of `*-musl` targets[0][1], but it's being phased out in favor of dynamic linking being the default option.[2][3][4] [0] https://github.com/rust-lang/rust/blob/672388edbee9e93c35e5fdf7dac818a6612a5103/compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_musl.rs#L19-L20 [1] https://github.com/rust-lang/rust/blob/672388edbee9e93c35e5fdf7dac818a6612a5103/compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_musl.rs#L17-L18 [2] rust-lang/compiler-team#422 [3] rust-lang/rust#133386 [4] rust-lang/rust#14451
1 parent f40697e commit 82d857e

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,15 @@ jobs:
313313
run: |
314314
echo "${RUSTC_LLVM_INSTALL_DIR_STATIC}/bin" >> $GITHUB_PATH
315315
316+
- name: Prepare sysroot
317+
if: runner.os == 'Linux'
318+
run: |
319+
set -euxo pipefail
320+
mkdir -p $SYSROOT_DIR
321+
wget -q -O - $(cargo xtask musl-sysroot-url) | \
322+
tar -xJ -C $SYSROOT_DIR --xattrs-include='*.*' --numeric-owner --wildcards './usr/lib/*'
323+
echo "CXXSTDLIB_PATH=$(dirname $(find $SYSROOT_DIR -name libstdc++.a))" >> $GITHUB_ENV
324+
316325
- name: Install static libraries (macOS)
317326
if: runner.os == 'macOS'
318327
# macOS does not provide any static libraries. Homebrew does provide
@@ -337,24 +346,31 @@ jobs:
337346
# (multiple builds) increases the disk usage massively. Therefore we
338347
# perform all static builds with only one fixed feature set.
339348
run: |
340-
cargo check --no-default-features --features \
341-
${{ env.LLVM_FEATURES_STATIC }}
349+
set -euxo pipefail
350+
# Link libc and C runtime statically.
351+
echo "RUSTFLAGS=-C target-feature=+crt-static" >> $GITHUB_ENV
352+
cargo check --no-default-features \
353+
--features ${{ env.LLVM_FEATURES_STATIC }} \
354+
--target ${{ matrix.platform.static-target }}
342355
343356
- name: Build (static linking, single feature set)
344357
run: |
345-
cargo build --no-default-features --features \
346-
${{ env.LLVM_FEATURES_STATIC }}
358+
cargo build --no-default-features \
359+
--features ${{ env.LLVM_FEATURES_STATIC }} \
360+
--target ${{ matrix.platform.static-target }}
347361
348362
- name: Test (sysroot built on demand, static linking)
349363
run: |
350-
RUSTC_BOOTSTRAP=1 cargo test --no-default-features --features \
351-
${{ env.LLVM_FEATURES_STATIC }}
364+
RUSTC_BOOTSTRAP=1 cargo test --no-default-features \
365+
--features ${{ env.LLVM_FEATURES_STATIC }} \
366+
--target ${{ matrix.platform.static-target }}
352367
353368
- name: Test (prebuilt BPF standard library, static linking)
354369
run: |
355370
BPFEL_SYSROOT_DIR="${{ github.workspace }}/bpf-sysroot" \
356-
cargo test --no-default-features --features \
357-
${{ env.LLVM_FEATURES_STATIC }}
371+
cargo test --no-default-features \
372+
--features ${{ env.LLVM_FEATURES_STATIC }} \
373+
--target ${{ matrix.platform.static-target }}
358374
359375
- name: Report disk usage
360376
if: ${{ always() }}

0 commit comments

Comments
 (0)