Skip to content

ci: Build statically linked bpf-linker in CI #1193

ci: Build statically linked bpf-linker in CI

ci: Build statically linked bpf-linker in CI #1193

Workflow file for this run

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-linux:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
rust:
- stable
- beta
- nightly
target:
- target: aarch64-unknown-linux-musl
container: alpine:3.20
llvm-proxy: false
- target: x86_64-unknown-linux-gnu
container: ubuntu:22.04
llvm-proxy: true
- target: x86_64-unknown-linux-musl
container: alpine:3.20
llvm-proxy: false
container:
image: ${{ matrix.target.container }}
name: rustc=${{ matrix.rust }} target=${{ matrix.target.target }}
needs: llvm
env:
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@v4
- name: Install dependencies
if: endsWith(matrix.target.target, 'gnu')
shell: bash
run: |
set -euxo pipefail
apt update
apt -y install clang curl linux-tools
- name: Install dependencies
if: endsWith(matrix.target.target, 'musl')
run: |
set -euxo pipefail
apk update
apk add bash bpftool clang curl dpkg git libgcc libstdc++-dev make musl-dev tar
- 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
# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15.
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: Restore LLVM
uses: actions/cache/restore@v4
with:
path: llvm-install
key: ${{ needs.llvm.outputs[format('cache-key-{0}', matrix.target.target)] }}
fail-on-cache-miss: true
- name: Add LLVM to PATH && LD_LIBRARY_PATH
shell: bash
run: |
set -euxo pipefail
# `${{ github.workspace }}` doesn't tell the truth when running inside
# containers. See https://github.com/actions/runner/issues/2058
# None of the workarounds works here, so let's just hard-code the full
# path of the decompressed cache...
echo "/__w/bpf-linker/bpf-linker/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=/__w/bpf-linker/bpf-linker/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
shell: bash
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' && matrix.target.llvm-proxy == true
run: cargo hack test --feature-powerset
# llvm-proxy doesn't work on musl environments.
- name: Test
if: matrix.rust == 'nightly' && matrix.target.llvm-proxy != true
run: cargo hack test --feature-powerset --exclude-features default,rust-llvm
- uses: actions/checkout@v4
if: matrix.rust == 'nightly'
with:
# TODO: Switch to the main Aya repo once fixes land there.
repository: vadorovsky/aya
ref: integration-tests-linker
path: aya
submodules: recursive
- name: Install
if: matrix.rust == 'nightly' && matrix.target.llvm-proxy == true
run: cargo install --path .
- name: Install
if: matrix.rust == 'nightly' && matrix.target.llvm-proxy != true
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' && matrix.target.llvm-proxy != true
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 https://ftp.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' && matrix.target.llvm-proxy != true
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 https://ftp.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' && matrix.target.llvm-proxy != true
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' && matrix.llvm.proxy == true
run: cargo xtask integration-test local
- name: Run aya integration tests
if: matrix.rust == 'nightly' && matrix.llvm.proxy != true
working-directory: aya
run: |
set -euxo pipefail
apk add file findutils-locate qemu-system-arm qemu-system-x86_64
find test/.tmp -name 'vmlinuz-*' | RUSTFLAGS=-Cdebuginfo=line-directives-only xargs -t cargo xtask integration-test vm
# build-macos:
# runs-on: macos-13
# strategy:
# fail-fast: false
# matrix:
# rust:
# - stable
# - beta
# - nightly