Skip to content

Commit 35f157e

Browse files
committed
ci: Build statically linked bpf-linker in CI
Build LLVM and bpf-linker with statically linked libLLVM for multiple architectures. Include the resulting build artifacts on the release pages, so they can be installed with `cargo binstall`
1 parent 858b0bb commit 35f157e

22 files changed

+1924
-254
lines changed

Diff for: .cargo/config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[alias]
2+
xtask = "run --package xtask --"

Diff for: .github/workflows/ci.yml

+81-35
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,38 @@ jobs:
4848
run: cargo fmt --all -- --check
4949

5050
build:
51-
# We don't use ubuntu-latest because we care about the apt packages available.
52-
runs-on: ubuntu-22.04
51+
runs-on: ${{ matrix.target.os }}
5352
strategy:
5453
fail-fast: false
5554
matrix:
5655
rust:
5756
- stable
5857
- beta
5958
- nightly
60-
llvm:
61-
- 19
62-
- source
63-
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
59+
# We don't use ubuntu-latest because we care about the apt packages available.
60+
target:
61+
- os: macos-14
62+
target: aarch64-apple-darwin
63+
build-type: native
64+
- os: macos-13
65+
target: x86_64-apple-darwin
66+
build-type: native
67+
- os: ubuntu-22.04
68+
target: aarch64-unknown-linux-gnu
69+
build-type: cross
70+
- os: ubuntu-22.04
71+
target: aarch64-unknown-linux-musl
72+
build-type: cross
73+
- os: ubuntu-22.04
74+
target: riscv64gc-unknown-linux-gnu
75+
build-type: cross
76+
- os: ubuntu-22.04
77+
target: x86_64-unknown-linux-gnu
78+
build-type: native
79+
- os: ubuntu-22.04
80+
target: x86_64-unknown-linux-musl
81+
build-type: cross
82+
name: rustc=${{ matrix.rust }} target=${{ matrix.target.target }}
6483
needs: llvm
6584

6685
env:
@@ -85,61 +104,48 @@ jobs:
85104
- uses: Swatinem/rust-cache@v2
86105

87106
- name: Check (default features, no system LLVM)
107+
if: matrix.build-type == 'native'
88108
run: cargo check
89109

90110
- name: Build (default features, no system LLVM)
111+
if: matrix.build-type == 'native'
91112
run: cargo build
92113

93114
- name: Install btfdump
94115
if: matrix.rust == 'nightly'
95116
run: cargo install btfdump
96117

97118
- name: Install prerequisites
98-
if: matrix.rust == 'nightly'
119+
if: matrix.rust == 'nightly' && runner.os == 'Linux' && startsWith(matrix.target.target, 'x86_64')
99120
# ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
100121
# enum values was added in clang 15[1] which isn't in `$PATH`.
101122
#
102123
# gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
103124
#
125+
# libelf is a dependency of libbpf.
126+
#
104127
# [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
105128
#
106129
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d
107130
run: |
108131
set -euxo pipefail
109132
sudo apt update
110-
sudo apt -y install gcc-multilib
133+
sudo apt -y install gcc-multilib libelf-dev
111134
echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
112135
113-
- name: Install LLVM
114-
if: matrix.llvm != 'source'
136+
- name: Install prerequisites
137+
if: runner.os == 'macOS'
138+
# We need system-wide LLVM only for FileCheck.
115139
run: |
116140
set -euxo pipefail
117-
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
118-
echo -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.llvm }} main | sudo tee /etc/apt/sources.list.d/llvm.list
119-
120-
sudo apt update
121-
# TODO(vadorovsky): Remove the requirement of libpolly.
122-
#
123-
# Packages from apt.llvm.org are being built all at once, with one
124-
# cmake build with superset of options, then different binaries and
125-
# libraries are being included in different packages.
126-
#
127-
# That results in `llvm-config --libname --link-static` mentioning
128-
# libpolly, even if it's not installed. The output of that command is
129-
# being used in build.rs of llvm-sys, so building llvm-sys on such
130-
# system is complaining about lack of libpolly.
131-
#
132-
# Hopefully that nightmare goes away once we switch to binstalls and
133-
# ditch the system LLVM option.
134-
sudo apt -y install llvm-${{ matrix.llvm }}-dev libpolly-${{ matrix.llvm }}-dev
135-
echo /usr/lib/llvm-${{ matrix.llvm }}/bin >> $GITHUB_PATH
141+
brew install llvm
142+
echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
136143
137144
- name: Restore LLVM
138-
if: matrix.llvm == 'source'
139145
uses: actions/cache/restore@v4
140146
with:
141147
path: llvm-install
142-
key: ${{ needs.llvm.outputs.cache-key }}
148+
key: ${{ needs.llvm.outputs[format('cache-key-{0}', matrix.target.target)] }}
143149
fail-on-cache-miss: true
144150

145151
- name: Add LLVM to PATH && LD_LIBRARY_PATH
@@ -160,17 +166,51 @@ jobs:
160166
cargo clean -p llvm-sys --release
161167
162168
- uses: taiki-e/install-action@cargo-hack
169+
if: matrix.build-type == 'native'
170+
171+
# Run cargo commands with `cargo hack` for native targets.
172+
# Run cargo commands with `xtask` for all targets.
163173

164174
- name: Check
175+
if: matrix.build-type == 'native'
165176
run: cargo hack check --feature-powerset
166177

178+
- name: Check (xtask)
179+
run: |
180+
cargo xtask check \
181+
--container-engine podman \
182+
--container-tag initial \
183+
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
184+
--pull always \
185+
--target ${{ matrix.target.target }}
186+
167187
- name: Build
188+
if: matrix.build-type == 'native'
168189
run: cargo hack build --feature-powerset
169190

191+
- name: Build (xtask)
192+
run: |
193+
cargo xtask build \
194+
--container-engine podman \
195+
--container-tag initial \
196+
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
197+
--pull always \
198+
--target ${{ matrix.target.target }}
199+
170200
- name: Test
171-
if: matrix.rust == 'nightly'
201+
if: matrix.build-type == 'native' && matrix.rust == 'nightly'
172202
run: cargo hack test --feature-powerset
173203

204+
- name: Test (xtask)
205+
if: matrix.rust == 'nightly'
206+
run: |
207+
cargo xtask test \
208+
--container-engine podman \
209+
--container-tag initial \
210+
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
211+
--pull always \
212+
--target ${{ matrix.target.target }}
213+
174214
- uses: actions/checkout@v4
175215
if: matrix.rust == 'nightly'
176216
with:
@@ -179,10 +219,16 @@ jobs:
179219
submodules: recursive
180220

181221
- name: Install
182-
if: matrix.rust == 'nightly'
183-
run: cargo install --path . --no-default-features
222+
if: matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.target == 'x86_64-unknown-linux-musl'
223+
run: |
224+
cargo xtask install \
225+
--container-engine podman \
226+
--container-tag initial \
227+
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
228+
--pull always \
229+
--target ${{ matrix.target.target }}
184230
185231
- name: Run aya integration tests
186-
if: matrix.rust == 'nightly'
232+
if: matrix.rust == 'nightly' && runner.os == 'Linux' && matrix.target.target == 'x86_64-unknown-linux-musl'
187233
working-directory: aya
188234
run: cargo xtask integration-test local

Diff for: .github/workflows/llvm.yml

+87-67
Original file line numberDiff line numberDiff line change
@@ -3,99 +3,119 @@ name: LLVM
33
on:
44
workflow_call:
55
outputs:
6-
cache-key:
7-
value: ${{ jobs.llvm.outputs.cache-key }}
6+
cache-key-aarch64-apple-darwin:
7+
value: ${{ jobs.llvm.outputs.cache-key-aarch64-apple-darwin }}
8+
cache-key-x86_64-apple-darwin:
9+
value: ${{ jobs.llvm.outputs.cache-key-x86_64-apple-darwin }}
10+
cache-key-aarch64-unknown-linux-gnu:
11+
value: ${{ jobs.llvm.outputs.cache-key-aarch64-unknown-linux-gnu }}
12+
cache-key-aarch64-unknown-linux-musl:
13+
value: ${{ jobs.llvm.outputs.cache-key-aarch64-unknown-linux-musl }}
14+
cache-key-riscv64gc-unknown-linux-gnu:
15+
value: ${{ jobs.llvm.outputs.cache-key-riscv64gc-unknown-linux-gnu }}
16+
cache-key-x86_64-unknown-linux-gnu:
17+
value: ${{ jobs.llvm.outputs.cache-key-x86_64-unknown-linux-gnu }}
18+
cache-key-x86_64-unknown-linux-musl:
19+
value: ${{ jobs.llvm.outputs.cache-key-x86_64-unknown-linux-musl }}
820

921
jobs:
1022
llvm:
11-
runs-on: ubuntu-22.04
12-
name: llvm
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
matrix:
26+
include:
27+
- os: macos-14
28+
target: aarch64-apple-darwin
29+
- os: macos-13
30+
target: x86_64-apple-darwin
31+
- os: ubuntu-22.04
32+
target: aarch64-unknown-linux-gnu
33+
- os: ubuntu-22.04
34+
target: aarch64-unknown-linux-musl
35+
- os: ubuntu-22.04
36+
target: riscv64gc-unknown-linux-gnu
37+
- os: ubuntu-22.04
38+
target: x86_64-unknown-linux-gnu
39+
- os: ubuntu-22.04
40+
target: x86_64-unknown-linux-musl
41+
name: llvm ${{ matrix.target }}
1342
outputs:
14-
cache-key: ${{ steps.cache-key.outputs.cache-key }}
43+
cache-key-aarch64-apple-darwin: ${{ steps.cache-key.outputs.cache-key-aarch64-apple-darwin }}
44+
cache-key-x86_64-apple-darwin: ${{ steps.cache-key.outputs.cache-key-x86_64-apple-darwin }}
45+
cache-key-aarch64-unknown-linux-gnu: ${{ steps.cache-key.outputs.cache-key-aarch64-unknown-linux-gnu }}
46+
cache-key-aarch64-unknown-linux-musl: ${{ steps.cache-key.outputs.cache-key-aarch64-unknown-linux-musl }}
47+
cache-key-riscv64gc-unknown-linux-gnu: ${{ steps.cache-key.outputs.cache-key-riscv64gc-unknown-linux-gnu }}
48+
cache-key-x86_64-unknown-linux-gnu: ${{ steps.cache-key.outputs.cache-key-x86_64-unknown-linux-gnu }}
49+
cache-key-x86_64-unknown-linux-musl: ${{ steps.cache-key.outputs.cache-key-x86_64-unknown-linux-musl }}
1550
steps:
51+
- uses: actions/checkout@v4
52+
1653
- id: ls-remote
1754
run: |
1855
set -euxo pipefail
1956
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/19.1-2024-09-17 | cut -f1)
2057
echo "sha=$value" >> "$GITHUB_OUTPUT"
2158
2259
- id: cache-key
23-
run: echo "cache-key=llvm-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT"
60+
run: echo "cache-key-${{ matrix.target }}=llvm-${{ matrix.target }}-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT"
2461

2562
- name: Cache
2663
id: cache-llvm
2764
uses: actions/cache@v4
2865
with:
2966
path: llvm-install
30-
key: ${{ steps.cache-key.outputs.cache-key }}
67+
key: ${{ steps.cache-key.outputs[format('cache-key-{0}', matrix.target)] }}
3168
lookup-only: true
3269

33-
- name: Install Tools
34-
if: steps.cache-llvm.outputs.cache-hit != 'true'
70+
- name: Free disk space
71+
if: steps.cache-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
3572
run: |
3673
set -euxo pipefail
37-
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
38-
gpg --dearmor - | \
39-
sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
40-
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ jammy main' | \
41-
sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null
42-
43-
sudo apt update
44-
sudo apt -y install cmake ninja-build clang lld
74+
sudo apt -y remove \
75+
azure-cli \
76+
'^aspnetcore-.*' \
77+
'^dotnet-.*' \
78+
firefox \
79+
'^google-cloud-.*' \
80+
'^google-chrome-*' \
81+
'^imagemagick.*' \
82+
java-common \
83+
kubectl \
84+
'^libmagick.*' \
85+
'^libmono.*' \
86+
'^libnginx.*' \
87+
'^microsoft-edge.*' \
88+
'^mongodb-.*' \
89+
mono-devel \
90+
'^mysql-.*' \
91+
'^php.*' \
92+
powershell \
93+
'^r-.*'
94+
sudo rm -rf \
95+
/opt/ghc \
96+
/opt/hostedtoolcache \
97+
/usr/lib/jvm \
98+
/usr/local/.ghcup \
99+
/usr/local/aws* \
100+
/usr/local/bin/{aliyun,azcopy,bicep,helm,minikube,oc,occopy,packer,pulumi*,stack,terraform} \
101+
/usr/local/julia* \
102+
/usr/local/lib/android \
103+
/usr/local/share/{chromium,powershell,vcpkg} \
104+
/usr/share/dotnet || true
105+
sudo docker image prune --all --force || true
45106
46-
- name: Checkout LLVM Source
47-
if: steps.cache-llvm.outputs.cache-hit != 'true'
48-
uses: actions/checkout@v4
49-
with:
50-
repository: aya-rs/llvm-project
51-
ref: ${{ steps.ls-remote.outputs.sha }}
52-
path: llvm-project
53-
54-
- name: Configure LLVM
55-
if: steps.cache-llvm.outputs.cache-hit != 'true'
107+
- name: Install dependencies
108+
if: steps.cache-llvm.outputs.cache-hit != 'true' && runner.os == 'macOS'
56109
run: |
57110
set -euxo pipefail
58-
cmake \
59-
-S llvm-project/llvm \
60-
-B llvm-build \
61-
-G Ninja \
62-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
63-
-DCMAKE_C_COMPILER=clang \
64-
-DCMAKE_CXX_COMPILER=clang++ \
65-
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/llvm-install" \
66-
-DLLVM_BUILD_LLVM_DYLIB=ON \
67-
-DLLVM_ENABLE_ASSERTIONS=ON \
68-
-DLLVM_ENABLE_PROJECTS= \
69-
-DLLVM_ENABLE_RUNTIMES= \
70-
-DLLVM_INSTALL_UTILS=ON \
71-
-DLLVM_LINK_LLVM_DYLIB=ON \
72-
-DLLVM_TARGETS_TO_BUILD=BPF \
73-
-DLLVM_USE_LINKER=lld
74-
75-
- name: Install LLVM
76-
if: steps.cache-llvm.outputs.cache-hit != 'true'
77-
env:
78-
# Create symlinks rather than copies to conserve disk space. At the time of this writing,
79-
# GitHub-hosted runners have 14GB of SSD space
80-
# (https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources).
81-
#
82-
# Since the LLVM build creates a bunch of symlinks (and this setting does not turn those
83-
# into symlinks-to-symlinks), use absolute symlinks so we can distinguish the two cases.
84-
CMAKE_INSTALL_MODE: ABS_SYMLINK
85-
run: cmake --build llvm-build --target install
111+
brew install cmake lld llvm ninja
112+
echo $(brew --prefix)/opt/llvm/bin >> $GITHUB_PATH
86113
87-
- name: Rewrite LLVM Symlinks
114+
- name: Build LLVM
88115
if: steps.cache-llvm.outputs.cache-hit != 'true'
89-
# Move targets over the symlinks that point to them.
90-
#
91-
# This whole dance would be simpler if CMake supported CMAKE_INSTALL_MODE=MOVE.
92116
run: |
93117
set -euxo pipefail
94-
find llvm-install -type l -execdir sh -eux -c '
95-
for link in "$@"; do
96-
target=$(readlink "$link")
97-
case $target in
98-
/*) mv "$target" "$link" ;;
99-
esac
100-
done
101-
' sh {} +
118+
cargo xtask build-llvm \
119+
--container-tag initial \
120+
--llvm-install-dir "${{ github.workspace }}/llvm-install" \
121+
--target "${{ matrix.target }}"

0 commit comments

Comments
 (0)