Skip to content

Commit 7a507e8

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 7a507e8

File tree

3 files changed

+72
-56
lines changed

3 files changed

+72
-56
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414

1515
env:
1616
CARGO_TERM_COLOR: always
17+
LLVM_TARGET: x86_64-unknown-linux-musl
1718

1819
jobs:
1920
llvm:
@@ -56,10 +57,9 @@ jobs:
5657
- stable
5758
- beta
5859
- nightly
59-
llvm:
60-
- 19
61-
- source
62-
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
60+
target:
61+
- x86_64-unknown-linux-musl
62+
name: rustc=${{ matrix.rust }} target=${{ matrix.target }}
6363
needs: llvm
6464

6565
env:
@@ -81,7 +81,7 @@ jobs:
8181
toolchain: ${{ matrix.rust }}
8282
components: rust-src
8383
# 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
84+
targets: ${{ matrix.target }}
8585

8686
- uses: Swatinem/rust-cache@v2
8787

@@ -91,59 +91,36 @@ jobs:
9191
- name: Build (default features, no system LLVM)
9292
run: cargo build
9393

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
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+
# run: |
108+
# set -euxo pipefail
109+
# wget https://ci-artifacts.rust-lang.org/rustc-builds/${{ env.LLVM_SHA }}/rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz
110+
# set -euxo pipefail
111+
# wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
112+
# echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main | sudo tee /etc/apt/sources.list.d/llvm.list
113+
# sudo apt update
114+
# sudo apt -y install clang gcc-multilib
136115

137116
- name: Restore LLVM
138-
if: matrix.llvm == 'source'
139117
uses: actions/cache/restore@v4
140118
with:
141119
path: llvm-install
142120
key: ${{ needs.llvm.outputs.cache-key }}
143121
fail-on-cache-miss: true
144122

145123
- name: Add LLVM to PATH && LD_LIBRARY_PATH
146-
if: matrix.llvm == 'source'
147124
run: |
148125
set -euxo pipefail
149126
echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH

.github/workflows/llvm.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ 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 }}
@@ -20,7 +24,7 @@ jobs:
2024
echo "sha=$value" >> "$GITHUB_OUTPUT"
2125
2226
- id: cache-key
23-
run: echo "cache-key=llvm-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT"
27+
run: echo "cache-key=llvm-${{ matrix.target }}-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT"
2428

2529
- name: Cache
2630
id: cache-llvm
@@ -30,8 +34,29 @@ jobs:
3034
key: ${{ steps.cache-key.outputs.cache-key }}
3135
lookup-only: true
3236

37+
- name: Download LLVM from Rust CI
38+
id: download-llvm
39+
if: steps.cache-llvm.outputs.cache-hit != 'true'
40+
run:
41+
wget https://ci-artifacts.rust-lang.org/rustc-builds/${{ steps.ls-remote.outputs.sha }}/rust-dev-nightly-${{ matrix.target }}.tar.xz && \
42+
echo "download-llvm=success" << "$GITHUB_OUTPUT" || \
43+
echo "download-llvm=failure" << "$GITHUB_OUTPUT"
44+
3345
- name: Install Tools
3446
if: steps.cache-llvm.outputs.cache-hit != 'true'
47+
run:
48+
wget https://ci-artifacts.rust-lang.org/rustc-builds/${{ env.LLVM_SHA }}/rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz && \
49+
echo "success=true" << "$GITHUB_OUTPUT" || \
50+
echo "success=false" << "$GITHUB_OUTPUT"
51+
52+
- name: Save downloaded LLVM in cache
53+
if: steps.download-llvm.outputs.success == 'true'
54+
run: |
55+
set -euxo pipefail
56+
tar -xpf rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz --strip-components 1 -C llvm-install
57+
58+
- name: Install Tools
59+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outputs.success != 'true'
3560
run: |
3661
set -euxo pipefail
3762
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
@@ -44,15 +69,15 @@ jobs:
4469
sudo apt -y install cmake ninja-build clang lld
4570
4671
- name: Checkout LLVM Source
47-
if: steps.cache-llvm.outputs.cache-hit != 'true'
72+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outputs.success != 'true'
4873
uses: actions/checkout@v4
4974
with:
5075
repository: aya-rs/llvm-project
5176
ref: ${{ steps.ls-remote.outputs.sha }}
5277
path: llvm-project
5378

5479
- name: Configure LLVM
55-
if: steps.cache-llvm.outputs.cache-hit != 'true'
80+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outputs.success != 'true'
5681
run: |
5782
set -euxo pipefail
5883
cmake \
@@ -73,7 +98,7 @@ jobs:
7398
-DLLVM_USE_LINKER=lld
7499
75100
- name: Install LLVM
76-
if: steps.cache-llvm.outputs.cache-hit != 'true'
101+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outputs.success != 'true'
77102
env:
78103
# Create symlinks rather than copies to conserve disk space. At the time of this writing,
79104
# GitHub-hosted runners have 14GB of SSD space
@@ -85,7 +110,7 @@ jobs:
85110
run: cmake --build llvm-build --target install
86111

87112
- name: Rewrite LLVM Symlinks
88-
if: steps.cache-llvm.outputs.cache-hit != 'true'
113+
if: steps.cache-llvm.outputs.cache-hit != 'true' && steps.download-llvm.outputs.success != 'true'
89114
# Move targets over the symlinks that point to them.
90115
#
91116
# This whole dance would be simpler if CMake supported CMAKE_INSTALL_MODE=MOVE.

Cargo.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)