Skip to content

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

ci: Build statically linked bpf-linker in CI

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

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
build-type: native
- os: macos-13
target: x86_64-apple-darwin
build-type: native
- os: ubuntu-22.04
target: aarch64-unknown-linux-gnu
build-type: cross
- os: ubuntu-22.04
target: aarch64-unknown-linux-musl
build-type: cross
- os: ubuntu-22.04
target: riscv64gc-unknown-linux-gnu
build-type: cross
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
build-type: native
- os: ubuntu-22.04
target: x86_64-unknown-linux-musl
build-type: cross
name: rustc=${{ matrix.rust }} target=${{ matrix.target.target }}
needs: llvm
env:
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
- uses: Swatinem/rust-cache@v2
- name: Check (default features, no system LLVM)
if: matrix.build-type == 'native'
run: cargo check
- name: Build (default features, no system LLVM)
if: matrix.build-type == 'native'
run: cargo build
- name: Install btfdump
if: matrix.rust == 'nightly'
run: cargo install btfdump
- name: Install prerequisites
if: matrix.build-type == 'native' && matrix.rust == 'nightly'
# 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 gcc-multilib
echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
- name: Install prerequisites
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: 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
if: matrix.llvm == 'source'
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
if: matrix.build-type == 'native'
# Run cargo commands with `cargo hack` for native targets.
# Run cargo commands with `xtask` for all targets.
- name: Check
if: matrix.build-type == 'native'
run: cargo hack check --feature-powerset
- name: Check (xtask)
run: |
cargo xtask check \
--container-tag initial \
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
--pull always \
--target ${{ matrix.target.target }}
- name: Build
if: matrix.build-type == 'native'
run: cargo hack build --feature-powerset
- name: Build (xtask)
run: |
cargo xtask build \
--container-tag initial \
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
--pull always \
--target ${{ matrix.target.target }}
- name: Test
if: matrix.build-type == 'native' && matrix.rust == 'nightly'
run: cargo hack test --feature-powerset
- name: Test (xtask)
if: matrix.rust == 'nightly'
run: |
cargo xtask test \
--container-tag initial \
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
--pull always \
--target ${{ matrix.target.target }}
- uses: actions/checkout@v4
if: matrix.rust == 'nightly'
with:
repository: aya-rs/aya
path: aya
submodules: recursive
- name: Install
if: matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')
run: |
cargo xtask install \
--container-tag initial \
--pull always \
--target ${{ matrix.target.target }}
- 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