Skip to content

Commit 35354c9

Browse files
committed
ci: Build statically linked bpf-linker in CI
- Download LLVM builds from Rust CI. - Always link libLLVM statically. - For now, do it only for x86_64.
1 parent 90a5ae4 commit 35354c9

File tree

2 files changed

+72
-58
lines changed

2 files changed

+72
-58
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@ jobs:
4949

5050
build:
5151
runs-on: ubuntu-22.04
52+
container:
53+
image: alpine:3.20
5254
strategy:
5355
fail-fast: false
5456
matrix:
5557
rust:
5658
- stable
5759
- beta
5860
- nightly
59-
llvm:
60-
- 19
61-
- source
62-
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
61+
target:
62+
- x86_64-unknown-linux-musl
63+
name: rustc=${{ matrix.rust }} target=${{ matrix.target }}
6364
needs: llvm
6465

6566
env:
@@ -68,6 +69,12 @@ jobs:
6869
steps:
6970
- uses: actions/checkout@v4
7071

72+
- name: Install dependencies
73+
run: |
74+
set -euxo pipefail
75+
apk update
76+
apk add bash curl libgcc gcc
77+
7178
- name: Install Rust ${{ matrix.rust }}
7279
if: matrix.rust != 'nightly'
7380
uses: dtolnay/rust-toolchain@master
@@ -81,7 +88,7 @@ jobs:
8188
toolchain: ${{ matrix.rust }}
8289
components: rust-src
8390
# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15.
84-
targets: aarch64-unknown-linux-musl,x86_64-unknown-linux-musl
91+
targets: ${{ matrix.target }}-unknown-linux-musl
8592

8693
- uses: Swatinem/rust-cache@v2
8794

@@ -91,59 +98,33 @@ jobs:
9198
- name: Build (default features, no system LLVM)
9299
run: cargo build
93100

94-
- name: Install dependencies
95-
if: matrix.rust == 'nightly'
96-
# ubuntu-22.04 comes with clang 14[0] which doesn't include support for signed and 64bit
97-
# enum values which was added in clang 15[1].
98-
#
99-
# gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
100-
#
101-
# llvm provides llvm-objcopy which is used to build the BTF relocation tests.
102-
#
103-
# [0] https://github.com/actions/runner-images/blob/ubuntu22/20230724.1/images/linux/Ubuntu2204-Readme.md
104-
#
105-
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d
106-
run: |
107-
set -euxo pipefail
108-
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
109-
echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main | sudo tee /etc/apt/sources.list.d/llvm.list
110-
sudo apt update
111-
sudo apt -y install clang gcc-multilib
112-
113-
- name: Install LLVM
114-
if: matrix.llvm != 'source'
115-
run: |
116-
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
101+
# - name: Install dependencies
102+
# if: matrix.rust == 'nightly'
103+
# # ubuntu-22.04 comes with clang 14[0] which doesn't include support for signed and 64bit
104+
# # enum values which was added in clang 15[1].
105+
# #
106+
# # gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
107+
# #
108+
# # llvm provides llvm-objcopy which is used to build the BTF relocation tests.
109+
# #
110+
# # [0] https://github.com/actions/runner-images/blob/ubuntu22/20230724.1/images/linux/Ubuntu2204-Readme.md
111+
# #
112+
# # [1] https://github.com/llvm/llvm-project/commit/dc1c43d
113+
# run: |
114+
# set -euxo pipefail
115+
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
116+
# echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main | sudo tee /etc/apt/sources.list.d/llvm.list
117+
# sudo apt update
118+
# sudo apt -y install clang gcc-multilib
136119

137120
- name: Restore LLVM
138-
if: matrix.llvm == 'source'
139121
uses: actions/cache/restore@v4
140122
with:
141123
path: llvm-install
142124
key: ${{ needs.llvm.outputs.cache-key }}
143125
fail-on-cache-miss: true
144126

145127
- name: Add LLVM to PATH && LD_LIBRARY_PATH
146-
if: matrix.llvm == 'source'
147128
run: |
148129
set -euxo pipefail
149130
echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH
@@ -220,3 +201,7 @@ jobs:
220201
set -euxo pipefail
221202
sudo apt install -y locate qemu-system-{arm,x86}
222203
find test/.tmp -name 'vmlinuz-*' | RUSTFLAGS=-Cdebuginfo=line-directives-only xargs -t cargo xtask integration-test vm
204+
205+
- name: Setup tmate session
206+
if: ${{ failure() }}
207+
uses: mxschmitt/action-tmate@v3

.github/workflows/llvm.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,38 @@ on:
99
jobs:
1010
llvm:
1111
runs-on: ubuntu-22.04
12+
strategy:
13+
matrix:
14+
target:
15+
- x86_64-unknown-linux-musl
1216
name: llvm
1317
outputs:
1418
cache-key: ${{ steps.cache-key.outputs.cache-key }}
1519
steps:
20+
- name: Install Rust nightly
21+
uses: dtolnay/rust-toolchain@nightly
22+
23+
# We retrieve the commit hashes of two repositories:
24+
#
25+
# - rust-lang/rust - the Rust monorepo. Rust CI is using commit hashes
26+
# from the monorepo for annotating LLVM tarballs. We use it to download
27+
# the tarball.
28+
# - aya-rs/llvm-project - which is our fork of LLVM, kept in sync with
29+
# rust-lang/llvm-project. We use it in case we can't download LLVM
30+
# toolchain from Rust CI.
1631
- id: ls-remote
1732
run: |
1833
set -euxo pipefail
19-
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/19.1-2024-07-30 | cut -f1)
20-
echo "sha=$value" >> "$GITHUB_OUTPUT"
34+
# Get the partial SHA from Rust nightly.
35+
rustc_sha=$(rustc +nightly --version | grep -oE '[a-f0-9]{7,40}')
36+
# Get the full SHA from GitHub.
37+
rustc_sha=$(curl -s https://api.github.com/repos/rust-lang/rust/commits/$rustc_sha | jq -r '.sha')
38+
aya_llvm_sha=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/19.1-2024-07-30 | cut -f1)
39+
echo "rustc-sha=$rustc_sha" >> "$GITHUB_OUTPUT"
40+
echo "aya-llvm-sha=$aya_llvm_sha" >> "$GITHUB_OUTPUT"
2141
2242
- id: cache-key
23-
run: echo "cache-key=llvm-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT"
43+
run: echo "cache-key=llvm-${{ matrix.target }}-${{ steps.ls-remote.outputs.rustc-sha }}-1" >> "$GITHUB_OUTPUT"
2444

2545
- name: Cache
2646
id: cache-llvm
@@ -30,8 +50,17 @@ jobs:
3050
key: ${{ steps.cache-key.outputs.cache-key }}
3151
lookup-only: true
3252

33-
- name: Install Tools
53+
- name: Download LLVM from Rust CI
54+
id: download-llvm
3455
if: steps.cache-llvm.outputs.cache-hit != 'true'
56+
run: |
57+
set -euxo pipefail
58+
mkdir -p llvm-install
59+
wget -q -O - https://ci-artifacts.rust-lang.org/rustc-builds/${{ steps.ls-remote.outputs.rustc-sha }}/rust-dev-nightly-${{ matrix.target }}.tar.xz | \
60+
tar -xJ --strip-components 2 -C llvm-install
61+
62+
- name: Install Tools
63+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outcome != 'success'
3564
run: |
3665
set -euxo pipefail
3766
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
@@ -44,15 +73,15 @@ jobs:
4473
sudo apt -y install cmake ninja-build clang lld
4574
4675
- name: Checkout LLVM Source
47-
if: steps.cache-llvm.outputs.cache-hit != 'true'
76+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outcome != 'success'
4877
uses: actions/checkout@v4
4978
with:
5079
repository: aya-rs/llvm-project
51-
ref: ${{ steps.ls-remote.outputs.sha }}
80+
ref: ${{ steps.ls-remote.outputs.aya-llvm-sha }}
5281
path: llvm-project
5382

5483
- name: Configure LLVM
55-
if: steps.cache-llvm.outputs.cache-hit != 'true'
84+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outcome != 'success'
5685
run: |
5786
set -euxo pipefail
5887
cmake \
@@ -73,7 +102,7 @@ jobs:
73102
-DLLVM_USE_LINKER=lld
74103
75104
- name: Install LLVM
76-
if: steps.cache-llvm.outputs.cache-hit != 'true'
105+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outcome != 'success'
77106
env:
78107
# Create symlinks rather than copies to conserve disk space. At the time of this writing,
79108
# GitHub-hosted runners have 14GB of SSD space
@@ -85,7 +114,7 @@ jobs:
85114
run: cmake --build llvm-build --target install
86115

87116
- name: Rewrite LLVM Symlinks
88-
if: steps.cache-llvm.outputs.cache-hit != 'true'
117+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outcome != 'success'
89118
# Move targets over the symlinks that point to them.
90119
#
91120
# This whole dance would be simpler if CMake supported CMAKE_INSTALL_MODE=MOVE.

0 commit comments

Comments
 (0)