name: CI
permissions:
contents: read
on:
workflow_dispatch:
push:
branches:
- main
paths: &trigger_paths
- ".cargo/**"
- "Cargo.toml"
- "Cargo.lock"
- "deny.toml"
- "rustfmt.toml"
- "fixtures/**"
- "crates/**"
- "src/**"
- ".github/workflows/ci.yml"
pull_request:
paths: *trigger_paths
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Lint dependencies
uses: EmbarkStudios/cargo-deny-action@bb137d7af7e4fb67e5f82a49c4fce4fad40782fe with:
rust-version: 1.88
clippy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust stable
uses: dtolnay/rust-toolchain@aad518f59d88bae90133242f9ddac7f8bbc5dddf with:
components: clippy,rustfmt
- name: Install native dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y libelf-dev zlib1g-dev build-essential protobuf-compiler
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 with:
add-job-id-key: false
save-if: false
key: clippy
- name: Run clippy
run: cargo clippy --workspace --all-targets -- -D warnings
style:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: Check style
run: cargo +nightly fmt --all -- --check
coverage:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Install Rust stable
uses: dtolnay/rust-toolchain@aad518f59d88bae90133242f9ddac7f8bbc5dddf with:
components: rustfmt
- uses: taiki-e/install-action@6887963ccf37a9ddcd8c5fa4baeb3e1e5fd61fa1 with:
tool: cargo-llvm-cov
- name: Install native dependencies
if: runner.os == 'Linux'
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
sudo apt-get update -y
sudo apt-get install -y build-essential autopoint gettext \
libelf-dev zlib1g-dev libseccomp-dev \
protobuf-compiler lcov libbpf-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-22 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-22 100
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-22 100
sudo update-alternatives --install /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-22 100
sudo update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-22 100
sudo update-alternatives --install /usr/bin/opt opt /usr/bin/opt-22 100
sudo update-alternatives --install /usr/bin/llc llc /usr/bin/llc-22 100
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 with:
add-job-id-key: false
key: coverage
- name: Generate code coverage (non-root)
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Run root-only tests
env:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: sudo -E env TRACEXEC_BPFCOV_OUTDIR=/tmp/bpfcov
run: cargo llvm-cov --all-features --workspace --lcov --output-path root-lcov.info -- --ignored
- name: Combine eBPF coverage
run: |
# List the generated eBPF coverage files for debugging purposes
echo "eBPF coverage files:"
find /tmp/bpfcov
# First, check if the eBPF coverage file contains invalid test names, e.g. '{{closure}}'
if ls /tmp/bpfcov | grep -q '{{closure}}'; then
echo "Error: eBPF coverage file contains invalid test names ({{closure}})"
exit 1
fi
# Then, combine the eBPF coverage files
find /tmp/bpfcov -name '*.lcov' -print0 | xargs -0 -I{} echo -a {} | xargs lcov -o ebpf.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f with:
token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info,root-lcov.info,ebpf.lcov
fail_ci_if_error: true
check_and_test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
job-name: check_and_test(x86_64, glibc, dynamic, default-features)
os-arch: amd64
target: x86_64-unknown-linux-gnu
arch: x86_64
libpath: usr/lib/x86_64-linux-gnu
no-default-features: false
- os: ubuntu-24.04
job-name: check_and_test(x86_64, glibc, dynamic, no-default-features)
os-arch: amd64
target: x86_64-unknown-linux-gnu
arch: x86_64
libpath: usr/lib/x86_64-linux-gnu
no-default-features: true
- os: ubuntu-24.04
job-name: check_and_test(x86_64, glibc, static, default-features)
os-arch: amd64
target: x86_64-unknown-linux-gnu
arch: x86_64
libpath: usr/lib/x86_64-linux-gnu
no-default-features: false
args: "-F static,vendored"
rust_flags: -C target-feature=+crt-static
static_libseccomp: true
- os: ubuntu-24.04
job-name: check_and_test(aarch64, glibc, dynamic, default-features)
os-arch: arm64
target: aarch64-unknown-linux-gnu
arch: aarch64
libpath: usr/lib/aarch64-linux-gnu
no-default-features: false
- os: ubuntu-24.04
job-name: check_and_test(aarch64, glibc, static, default-features)
os-arch: arm64
target: aarch64-unknown-linux-gnu
arch: aarch64
libpath: usr/lib/aarch64-linux-gnu
no-default-features: false
args: "-F static,vendored"
rust_flags: -C target-feature=+crt-static
static_libseccomp: true
- os: ubuntu-24.04
job-name: check_and_test(riscv64, glibc, dynamic, no-default-features)
os-arch: riscv64
target: riscv64gc-unknown-linux-gnu
arch: riscv64
libpath: usr/lib/riscv64-linux-gnu
args: "-F ebpf,vendored-libbpf"
no-default-features: true
- os: ubuntu-24.04
job-name: check_and_test(riscv64, glibc, static, no-default-features)
os-arch: riscv64
target: riscv64gc-unknown-linux-gnu
arch: riscv64
libpath: usr/lib/riscv64-linux-gnu
args: "-F ebpf,static,vendored"
no-default-features: true
rust_flags: -C target-feature=+crt-static
static_libseccomp: true
name: ${{ matrix.job-name }}
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: ${{ matrix.rust_flags }}
LIBSECCOMP_LINK_TYPE: ${{ matrix.static_libseccomp && 'static' || 'dylib' }}
LIBSECCOMP_LIB_PATH: ${{ matrix.static_libseccomp && format('/{0}', matrix.libpath) || '/this/path/does/not/exist' }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.88"
targets: ${{ matrix.target }}
components: rustfmt
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@129361238c06ff2cc1c4ca5c5d2217af441ffdf6 with:
target: ${{ matrix.target }}
- name: Add apt sources for ${{ matrix.os-arch }}
if: matrix.os-arch != 'amd64'
run: |
dpkg --add-architecture ${{ matrix.os-arch }}
release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
sed -i '/Types: deb/aArchitectures: amd64' /etc/apt/sources.list.d/ubuntu.sources
printf 'deb [arch=${{ matrix.os-arch }}] http://ports.ubuntu.com/ %s main restricted\n' \
$release $release-updates $release-security \
>> /etc/apt/sources.list
shell: sudo sh -e {0}
- name: Install build dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y build-essential autopoint gettext libelf-dev zlib1g-dev \
libelf-dev:${{ matrix.os-arch }} zlib1g-dev:${{ matrix.os-arch }} \
protobuf-compiler
sudo apt-get install -y libseccomp-dev:${{ matrix.os-arch }}
if ! [ "${{ matrix.static_libseccomp }}" = "true" ]; then
sudo apt-get install -y libseccomp2:${{ matrix.os-arch }}
fi
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 with:
add-job-id-key: false
key: ${{ matrix.target }}
- name: Run cargo build with default features
run: env RUSTFLAGS="$RUSTFLAGS -D warnings" cargo build --workspace --bins --tests --target ${{ matrix.target }} ${{ matrix.args }}
env:
RUST_BACKTRACE: full
- name: Run cargo test with default features
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-unknown-linux-musl'
run: cargo test --workspace --target ${{ matrix.target }} ${{ matrix.args }}
env:
RUST_BACKTRACE: full
- name: Run root-only tests
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: cargo test --workspace --target ${{ matrix.target }} ${{ matrix.args }} -- --ignored
env:
RUST_BACKTRACE: full
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER: sudo -E