Skip to content

Commit

Permalink
ci: Build statically linked bpf-linker in CI
Browse files Browse the repository at this point in the history
- Download LLVM builds from Rust CI.
- Always link libLLVM statically.
- For now, do it only for x86_64.
  • Loading branch information
vadorovsky committed Aug 2, 2024
1 parent 6f4c969 commit 42e16f3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
34 changes: 12 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ on:

env:
CARGO_TERM_COLOR: always
LLVM_SHA: 0b5eb7ba7bd796fb39c8bb6acd9ef6c140f28b65
LLVM_SYS_191_PREFIX: /opt/rust-dev
LLVM_TARGET: x86_64-unknown-linux-musl

jobs:
llvm:
uses: ./.github/workflows/llvm.yml

lint-stable:
runs-on: ubuntu-22.04

Expand Down Expand Up @@ -55,18 +55,12 @@ jobs:
rust:
- stable
- beta
# TODO: unpin nightly. There was a regression in
# https://github.com/rust-lang/rust/compare/1cec373f6...becebb315 that causes
# tests/btf/assembly/anon_struct_c.rs to fail to link.
- nightly-2024-04-16
llvm:
- 18
- source
- nightly
name: rustc=${{ matrix.rust }} llvm=${{ matrix.llvm }}
needs: llvm

env:
RUST_BACKTRACE: full
RUSTFLAGS: -L /opt/rust-dev/lib

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -114,15 +108,11 @@ jobs:
sudo apt -y install clang gcc-multilib
- name: Install LLVM
if: matrix.llvm != 'source'
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
wget https://ci-artifacts.rust-lang.org/rustc-builds/${{ env.LLVM_SHA }}/rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz
tar -xpf rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz --strip-components 1 -C /opt
echo /opt/rust-dev/bin >> $GITHUB_PATH
- name: Restore LLVM
if: matrix.llvm == 'source'
Expand Down Expand Up @@ -152,14 +142,14 @@ 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 --features llvm-sys/force-static

- name: Build
run: cargo hack build --feature-powerset --features llvm-sys/force-dynamic
run: cargo hack build --feature-powerset --features llvm-sys/force-static

- name: Test
if: matrix.rust == 'nightly'
run: cargo hack test --feature-powerset --features llvm-sys/force-dynamic
run: cargo hack test --feature-powerset --features llvm-sys/force-static

- uses: actions/checkout@v4
if: matrix.rust == 'nightly'
Expand All @@ -170,7 +160,7 @@ jobs:

- name: Install
if: matrix.rust == 'nightly'
run: cargo install --path . --no-default-features --features llvm-sys/force-dynamic
run: cargo install --path . --no-default-features --features llvm-sys/force-static

# TODO: Remove this and run the integration tests on the local machine when they pass on 5.15.
- name: Download debian kernels
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- id: ls-remote
run: |
set -euxo pipefail
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/18.0-2024-02-13 | cut -f1)
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/19.1-2024-07-30 | cut -f1)
echo "sha=$value" >> "$GITHUB_OUTPUT"
- id: cache-key
Expand Down
23 changes: 9 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@ name: Release
on:
release:
types: [published]

env:
LLVM_SHA: 0b5eb7ba7bd796fb39c8bb6acd9ef6c140f28b65
LLVM_TARGET: x86_64-unknown-linux-musl

jobs:
llvm:
uses: ./.github/workflows/llvm.yml

upload-bins:
# TODO: Build for macos someday.
runs-on: ubuntu-22.04
needs: llvm
steps:
- name: Restore LLVM
uses: actions/cache/restore@v4
with:
path: llvm-install
key: ${{ needs.llvm.outputs.cache-key }}
fail-on-cache-miss: true

- name: Add LLVM to PATH
- name: Install LLVM
run: |
echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH
echo "$PATH"
set -euxo pipefail
wget https://ci-artifacts.rust-lang.org/rustc-builds/${{ env.LLVM_SHA }}/rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz
tar -xpf rust-dev-nightly-${{ env.LLVM_TARGET }}.tar.xz --strip -C /opt
echo /opt/rust-dev/bin >> $GITHUB_PATH
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
Expand Down
18 changes: 16 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ar = { version = "0.9.0" }
aya-rustc-llvm-proxy = { version = "0.9.2", optional = true }
gimli = { version = "0.30.0" }
libc = { version = "0.2.155" }
llvm-sys = { features = ["disable-alltargets-init"], version = "180.0.0-rc2" }
llvm-sys = { features = ["disable-alltargets-init"], version = "191.0.0-rc1" }
log = { version = "0.4.22" }
thiserror = { version = "1.0.61" }
tracing = "0.1"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ files with embedded bitcode (.o), optionally stored inside ar archives (.a).

## Installation

The linker requires LLVM 18. It can use the same LLVM used by the rust compiler,
The linker requires LLVM 19. It can use the same LLVM used by the rust compiler,
or it can use an external LLVM installation.

If your target is `aarch64-unknown-linux-gnu` (i.e. Linux on Apple Silicon) you
Expand All @@ -33,14 +33,14 @@ cargo install bpf-linker

### Using external LLVM

On Debian based distributions you need to install the `llvm-18-dev`, `libclang-18-dev`
and `libpolly-18-dev` packages. If your distro doesn't have them you can get them
On Debian based distributions you need to install the `llvm-19-dev`, `libclang-19-dev`
and `libpolly-19-dev` packages. If your distro doesn't have them you can get them
from the official LLVM repo at https://apt.llvm.org.

On rpm based distribution you need the `llvm-devel` and `clang-devel` packages.
If your distro doesn't have them you can get them from Fedora Rawhide.

Once you have installed LLVM 18 you can install the linker running:
Once you have installed LLVM 19 you can install the linker running:

```sh
cargo install bpf-linker --no-default-features
Expand Down

0 comments on commit 42e16f3

Please sign in to comment.