-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Add workflow to build and issue static binaries
The workflow builds natively for amd64 with LLVM library and use emulation to build for arm64 with LLVM as well. The result are two static binaries with their respective compressed archives. Signed-off-by: Mahe Tardy <[email protected]>
- Loading branch information
Showing
1 changed file
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
name: Build and release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
|
||
env: | ||
# https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.0 | ||
LLVM_arm64: clang+llvm-15.0.0-aarch64-linux-gnu | ||
LLVM_amd64: clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4 | ||
|
||
jobs: | ||
build: | ||
name: Build static bpftool binary | ||
runs-on: ubuntu-22.04 | ||
env: | ||
TARGETARCH: ${{ matrix.arch }} | ||
strategy: | ||
matrix: | ||
arch: [arm64, amd64] | ||
|
||
steps: | ||
# arm64 build only needs curl to download the LLVM archive | ||
- name: Install dependencies (arm64) | ||
if: matrix.arch == 'arm64' | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y curl file | ||
# amd64 needs curl and the dependencies to build bpftool | ||
- name: Install dependencies (amd64) | ||
if: matrix.arch == 'amd64' | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y curl file git llvm clang gcc pkg-config zlib1g-dev libelf-dev libcap-dev binutils | ||
- name: Download and extract compiled LLVM release | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
env: | ||
LLVM: ${{ env[format('LLVM_{0}', matrix.arch)] }} | ||
run: | | ||
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/${{ env.LLVM }}.tar.xz -O | ||
tar xvf ${{ env.LLVM }}.tar.xz | ||
- name: Checkout bpftool code | ||
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f | ||
with: | ||
submodules: recursive | ||
path: 'bpftool' | ||
|
||
- name: Build static bpftool natively for amd64 | ||
if: matrix.arch == 'amd64' | ||
working-directory: 'bpftool' | ||
env: | ||
LLVM: ${{ env[format('LLVM_{0}', matrix.arch)] }} | ||
run: make -j $(nproc) -C src V=1 \ | ||
EXTRA_CFLAGS=--static \ | ||
LLVM_CONFIG="${GITHUB_WORKSPACE}/${{ env.LLVM }}/bin/llvm-config" \ | ||
LLVM_STRIP="${GITHUB_WORKSPACE}/${{ env.LLVM }}/bin/llvm-strip" | ||
|
||
- name: Strip binary (amd64) | ||
if: matrix.arch == 'amd64' | ||
run: strip bpftool/src/bpftool | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 | ||
if: matrix.arch == 'arm64' | ||
with: | ||
platforms: arm64 | ||
|
||
# The emulated build leverage Docker and Ubuntu 22.04 container image | ||
# distribution to have all the needed arm64 packages. | ||
- name: Build static bpftool for arm64 with emulation | ||
if: matrix.arch == 'arm64' | ||
env: | ||
LLVM: ${{ env[format('LLVM_{0}', matrix.arch)] }} | ||
run: | | ||
docker run --platform linux/arm64 --rm -v $(pwd):/build ubuntu:22.04 \ | ||
bash -c "apt-get update && \ | ||
apt-get install -y make pkg-config libelf-dev libcap-dev clang gcc llvm binutils && \ | ||
cd build/bpftool && \ | ||
LLVM_CONFIG=../../${{ env.LLVM }}/bin/llvm-config EXTRA_CFLAGS=--static make -j V=1 -C src && \ | ||
strip src/bpftool" | ||
- name: Test bpftool binary | ||
working-directory: 'bpftool/src' | ||
run: | | ||
file ./bpftool | ||
./bpftool 2>&1 | grep -q Usage | ||
./bpftool -p version | \ | ||
tee /dev/stderr | \ | ||
jq --exit-status ".features | .llvm" | ||
ldd ./bpftool 2>&1 | \ | ||
tee /dev/stderr | \ | ||
grep -q 'not a dynamic executable' | ||
- name: Upload Artifact | ||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce | ||
with: | ||
name: ${{ format('bpftool_{0}', matrix.arch) }} | ||
path: bpftool/src/bpftool | ||
|
||
draft-release: | ||
name: Create a draft release | ||
runs-on: ubuntu-22.04 | ||
needs: build | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Download artifacts from build | ||
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a | ||
|
||
- name: Rename binaries and compress | ||
run: | | ||
tar -C bpftool_amd64 -I 'gzip -9' -cvf bpftool-${{ github.ref_name }}-amd64.tar.gz bpftool | ||
tar -C bpftool_arm64 -I 'gzip -9' -cvf bpftool-${{ github.ref_name }}-arm64.tar.gz bpftool | ||
mv bpftool_amd64/bpftool bpftool-amd64 | ||
mv bpftool_arm64/bpftool bpftool-arm64 | ||
- name: Create draft release and add artifacts | ||
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 | ||
with: | ||
draft: true | ||
files: bpftool* |