ci: Build statically linked bpf-linker in CI #1225
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
- 'feature/**' | |
pull_request: | |
branches: | |
- main | |
- 'feature/**' | |
schedule: | |
- cron: 00 4 * * * | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
llvm: | |
uses: ./.github/workflows/llvm.yml | |
lint-stable: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: stable | |
components: clippy, rust-src | |
- name: Run clippy | |
run: cargo clippy --features llvm-sys/no-llvm-linking --all-targets --workspace -- --deny warnings | |
lint-nightly: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: nightly | |
components: rustfmt, rust-src | |
- name: Check formatting | |
run: cargo fmt --all -- --check | |
build: | |
runs-on: ${{ matrix.target.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
rust: | |
- stable | |
- beta | |
- nightly | |
target: | |
- os: macos-13 | |
target: aarch64-apple-darwin | |
target-llvm: aarch64-apple-darwin | |
- os: macos-13 | |
target: x86_64-apple-darwin | |
target-llvm: x86_64-apple-darwin | |
# We use the GNU builds of LLVM both for GNU and musl builds of | |
# bpf-linker - it doesn't affect the type of libc being picked by | |
# Cargo and musl Rust toolchains come with their own copies of | |
# libc.a. | |
- os: ubuntu-22.04 | |
packages: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross | |
target: aarch64-unknown-linux-gnu | |
target-llvm: aarch64-linux-gnu | |
- os: ubuntu-22.04 | |
packages: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross | |
target: aarch64-unknown-linux-musl | |
target-llvm: aarch64-linux-gnu | |
- os: ubuntu-22.04 | |
packages: gcc-riscv64-linux-gnu g++-riscv64-linux-gnu libc6-dev-riscv64-cross | |
target: riscv64gc-unknown-linux-gnu | |
target-llvm: riscv64-linux-gnu | |
- os: ubuntu-22.04 | |
packages: | |
target: x86_64-unknown-linux-gnu | |
target-llvm: x86_64-linux-gnu | |
- os: ubuntu-22.04 | |
packages: | |
target: x86_64-unknown-linux-musl | |
target-llvm: x86_64-linux-gnu | |
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }} | |
needs: llvm | |
env: | |
CARGO_BUILD_TARGET: ${{ matrix.target.target }} | |
# We use the GNU sysroot as an LD path both for GNU and musl builds of | |
# bpf-linker - the user-space emulator and the path are used only for | |
# executing `llvm-config` and test binaries. | |
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64 -L /usr/aarch64-linux-gnu | |
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUNNER: qemu-aarch64 -L /usr/aarch64-linux-gnu | |
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER: qemu-aarch64 -L /usr/riscv64-linux-gnu | |
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_RUNNER: qemu-aarch64 -L /usr/riscv64-linux-gnu | |
LLVM_SYS_CROSS_LD_PREFIX: /usr/${{ matrix.target.target-llvm }} | |
RUST_BACKTRACE: full | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust ${{ matrix.rust }} | |
if: matrix.rust != 'nightly' | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ matrix.rust }} | |
- name: Install Rust ${{ matrix.rust }} | |
if: matrix.rust == 'nightly' | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ matrix.rust }} | |
components: rust-src | |
targets: ${{ matrix.target.target }} | |
- uses: Swatinem/rust-cache@v2 | |
- name: Check (default features, no system LLVM) | |
run: cargo check | |
- name: Build (default features, no system LLVM) | |
run: cargo build | |
- name: Install dependencies | |
if: matrix.rust == 'nightly' | |
# ubuntu-22.04 comes with clang 14[0] which doesn't include support for signed and 64bit | |
# enum values which was added in clang 15[1]. | |
# | |
# gcc-multilib provides at least <asm/types.h> which is referenced by libbpf. | |
# | |
# llvm provides llvm-objcopy which is used to build the BTF relocation tests. | |
# | |
# [0] https://github.com/actions/runner-images/blob/ubuntu22/20230724.1/images/linux/Ubuntu2204-Readme.md | |
# | |
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d | |
run: | | |
set -euxo pipefail | |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc | |
echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main | sudo tee /etc/apt/sources.list.d/llvm.list | |
sudo apt update | |
sudo apt -y install \ | |
clang \ | |
gcc-multilib \ | |
${{ matrix.target.packages }} | |
- name: Restore LLVM | |
uses: actions/cache/restore@v4 | |
with: | |
path: llvm-install | |
key: ${{ needs.llvm.outputs[format('cache-key-{0}', matrix.target.target-llvm)] }} | |
fail-on-cache-miss: true | |
- name: Add LLVM to PATH && LD_LIBRARY_PATH | |
run: | | |
set -euxo pipefail | |
echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH | |
# LD_LIBRARY_PATH is needed because we're going to link everything dynamically below. This | |
# doesn't affect behavior, but greatly reduces disk usage. | |
echo "LD_LIBRARY_PATH=${{ github.workspace }}/llvm-install/lib" >> $GITHUB_ENV | |
# llvm-sys discovers link flags at build script time; these are cached by cargo. The cached | |
# flags may be incorrect when the cache is reused across LLVM versions. | |
- name: Bust llvm-sys cache | |
run: | | |
set -euxo pipefail | |
cargo clean -p llvm-sys | |
cargo clean -p llvm-sys --release | |
- uses: taiki-e/install-action@cargo-hack | |
- name: Check | |
run: cargo hack check --feature-powerset | |
- name: Build | |
run: cargo hack build --feature-powerset | |
- name: Test | |
if: matrix.rust == 'nightly' | |
run: cargo hack test --feature-powerset | |
- uses: actions/checkout@v4 | |
if: matrix.rust == 'nightly' | |
with: | |
repository: aya-rs/aya | |
path: aya | |
submodules: recursive | |
- name: Install | |
if: matrix.rust == 'nightly' | |
run: cargo install --path . --no-default-features | |
# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15. | |
- name: Download debian kernels | |
if: matrix.rust == 'nightly' && runner.arch == 'ARM64' | |
working-directory: aya | |
run: | | |
set -euxo pipefail | |
mkdir -p test/.tmp/debian-kernels/arm64 | |
printf '%s\0' \ | |
linux-image-6.1.0-16-cloud-arm64-unsigned_6.1.67-1_arm64.deb \ | |
| xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/arm64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{} | |
# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15. | |
- name: Download debian kernels | |
if: matrix.rust == 'nightly' && runner.arch == 'X64' | |
working-directory: aya | |
run: | | |
set -euxo pipefail | |
mkdir -p test/.tmp/debian-kernels/amd64 | |
printf '%s\0' \ | |
linux-image-6.1.0-16-cloud-amd64-unsigned_6.1.67-1_amd64.deb \ | |
| xargs -0 -t -P0 -I {} wget -nd -nv -P test/.tmp/debian-kernels/amd64 ftp://ftp.us.debian.org/debian/pool/main/l/linux/{} | |
# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15. | |
- name: Extract debian kernels | |
if: matrix.rust == 'nightly' | |
working-directory: aya | |
run: | | |
set -euxo pipefail | |
find test/.tmp -name '*.deb' -print0 | xargs -t -0 -I {} \ | |
sh -c "dpkg --fsys-tarfile {} | tar -C test/.tmp --wildcards --extract '*vmlinuz*' --file -" | |
- name: Run aya integration tests | |
if: matrix.rust == 'nightly' | |
working-directory: aya | |
run: | | |
set -euxo pipefail | |
sudo apt install -y locate qemu-system-{arm,x86} | |
find test/.tmp -name 'vmlinuz-*' | RUSTFLAGS=-Cdebuginfo=line-directives-only xargs -t cargo xtask integration-test vm |