Skip to content

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

ci: Build statically linked bpf-linker in CI

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

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-latest
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-latest
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
# We don't use ubuntu-latest because we care about the apt packages available.
target:
- os: macos-14
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 qemu-user
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 musl-dev qemu-user
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 qemu-user
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 }} target=${{ matrix.target.target }}
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
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ matrix.rust }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rust-src
targets: ${{ matrix.target.target }}
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
if: runner.os == 'Linux'
# ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
# enum values was added in clang 15[1] which isn't in `$PATH`.
#
# gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
#
# [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
#
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d
run: |
set -euxo pipefail
sudo apt update
sudo apt -y install ${{ matrix.target.packages }}
echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
- name: Install dependencies
if: runner.os == 'macOS'
# We need system-wide LLVM only for FileCheck.
run: |
set -euxo pipefail
brew install llvm
echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
- 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-llvm)] }}
fail-on-cache-miss: true
- name: Point llvm-sys to the restored LLVM
run: |
set -euxo pipefail
rustflags="-L ${{ github.workspace }}/llvm-install/lib "
rustflags+=$(find lib/ -type f -name "*.a" -printf '%f\n' | \
sed -e 's/^lib//' -e 's/\.a$//' | \
sed 's/^/-l /' | paste -sd ' ')
echo "RUSTFLAGS=$rustflags" >> $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 --at-least-one-of llvm-sys/no-llvm-linking --feature-powerset
- name: Build
run: cargo hack build --at-least-one-of llvm-sys/no-llvm-linking --feature-powerset
- name: Test
if: matrix.rust == 'nightly'
run: cargo hack test --at-least-one-of llvm-sys/no-llvm-linking --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
- name: Run aya integration tests
if: matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')
working-directory: aya
run: cargo xtask integration-test local
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3