Skip to content

Commit

Permalink
chore: Build bpf-linker and LLVM for multiple targets
Browse files Browse the repository at this point in the history
Apart from the x86_64 Linux build, cross compile also to Linux
arm64, macOS x86_64 and macoOS arm64.
  • Loading branch information
vadorovsky committed Oct 27, 2023
1 parent 20e2bfd commit 1a368ba
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 52 deletions.
113 changes: 75 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,29 @@ jobs:
run: cargo fmt --all -- --check

build:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
rust:
- stable
- beta
- nightly
llvm:
- 17
- source
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
target:
- rust: aarch64-unknown-linux-musl
rustflags: -L ${{ github.workspace }}/runtimes-install/lib -L /usr/lib/aarch64-linux-musl -L /usr/lib/aarch64-linux-gnu
llvm: aarch64-unknown-linux-gnu
os: ubuntu-latest
- rust: aarch64-apple-darwin
llvm: aarch64-apple-darwin
os: macos-latest
- rust: x86_64-unknown-linux-musl
llvm: x86_64-unknown-linux-gnu
os: ubuntu-latest
- rust: x86_64-apple-darwin
llvm: x86_64-apple-darwin
os: macos-latest
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }} target=${{ matrix.target.rust }}
runs-on: ${{ matrix.target.os }}
needs: llvm

env:
Expand All @@ -85,52 +96,68 @@ jobs:

- uses: Swatinem/rust-cache@v2

- uses: taiki-e/setup-cross-toolchain-action@v1
if: startsWith(matrix.target.os, 'ubuntu')
with:
target: ${{ matrix.target.rust }}

- 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
if: startsWith(matrix.target.os, 'ubuntu') && startsWith(matrix.target.rust, 'aarch64')
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 sed -i 's/^deb /deb [arch=amd64] /g' /etc/apt/sources.list
sudo tee -a /etc/apt/sources.list << EOF
deb [arch=arm64] http://ports.ubuntu.com/ jammy main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ jammy-security main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ jammy-updates main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ jammy-backports main restricted universe multiverse
EOF
sudo dpkg --add-architecture arm64
sudo apt update
sudo apt -y install clang gcc-multilib
- name: Install LLVM
if: matrix.llvm != 'source'
sudo apt -y install \
musl-dev:arm64 \
libc++-dev:arm64 \
libtinfo-dev:arm64 \
libxml2-dev:arm64 \
libzstd-dev:arm64 \
zlib1g-dev:arm64
- name: Install dependencies
if: startsWith(matrix.target.os, 'ubuntu') && startsWith(matrix.target.rust, 'x86_64')
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 -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.llvm }} main | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt update
sudo apt -y install llvm-${{ matrix.llvm }}-dev
echo /usr/lib/llvm-${{ matrix.llvm }}/bin >> $GITHUB_PATH
sudo apt -y install \
musl-dev \
libc++-dev:arm64 \
libtinfo-dev:arm64 \
libxml2-dev:arm64 \
libzstd-dev:arm64 \
zlib1g-dev
- name: Restore LLVM
if: matrix.llvm == 'source'
uses: actions/cache/restore@v3
with:
path: llvm-install
key: ${{ needs.llvm.outputs.cache-key }}
key: ${{ needs.llvm.outputs[format('cache-key-llvm-{0}', matrix.target.rust)] }}
fail-on-cache-miss: true

- name: Restore runtimes
uses: actions/cache/restore@v3
with:
path: llvm-install
key: ${{ needs.llvm.outputs[format('cache-key-runtimes-{0}', matrix.target.rust)] }}
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
Expand All @@ -149,29 +176,39 @@ jobs:
- uses: taiki-e/install-action@cargo-hack

- name: Check
run: cargo hack check --feature-powerset --features llvm-sys/force-dynamic
run: cargo hack check --feature-powerset
env:
RUSTFLAGS: ${{ matrix.target.rustflags }}

- name: Build
run: cargo hack build --feature-powerset --features llvm-sys/force-dynamic
run: cargo hack build --feature-powerset
env:
RUSTFLAGS: ${{ matrix.target.rustflags }}

- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3

- name: Test
if: matrix.rust == 'nightly'
run: cargo hack test --feature-powerset --features llvm-sys/force-dynamic
run: cargo hack test --feature-powerset
env:
RUSTFLAGS: ${{ matrix.target.rustflags }}

- uses: actions/checkout@v4
if: matrix.rust == 'nightly'
if: startsWith(matrix.target.os, 'ubuntu') && matrix.rust == 'nightly'
with:
repository: aya-rs/aya
path: aya
submodules: recursive

- name: Install
if: matrix.rust == 'nightly'
if: startsWith(matrix.target.os, 'ubuntu') && matrix.rust == 'nightly'
run: cargo install --path . --no-default-features --features llvm-sys/force-dynamic

# 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'
if: startsWith(matrix.target.os, 'ubuntu') && matrix.rust == 'nightly' && runner.arch == 'ARM64'
working-directory: aya
run: |
set -euxo pipefail
Expand All @@ -182,7 +219,7 @@ jobs:
# 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'
if: startsWith(matrix.target.os, 'ubuntu') && matrix.rust == 'nightly' && runner.arch == 'X64'
working-directory: aya
run: |
set -euxo pipefail
Expand All @@ -193,15 +230,15 @@ jobs:
# 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'
if: startsWith(matrix.target.os, 'ubuntu') && 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'
if: startsWith(matrix.target.os, 'ubuntu') && matrix.rust == 'nightly'
working-directory: aya
run: |
set -euxo pipefail
Expand Down
Loading

0 comments on commit 1a368ba

Please sign in to comment.