chore: Build bpf-linker and LLVM for multiple targets #2
Workflow file for this run
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
name: LLVM | ||
on: | ||
workflow_call: | ||
# NOTE(vadorovsky): Unfortunately, Github Actions don't support matrix | ||
# strategy in `on` section. So we have to specify outputs by hand. | ||
outputs: | ||
cache-key-llvm-aarch64-unknown-linux-musl: | ||
value: ${{ jobs.llvm.outputs.cache-key-llvm-aarch64-unknown-linux-musl }} | ||
cache-key-llvm-aarch64-apple-darwin: | ||
value: ${{ jobs.llvm.outputs.cache-key-llvm-aarch64-apple-darwin }} | ||
cache-key-llvm-x86_64-unknown-linux-musl: | ||
value: ${{ jobs.llvm.outputs.cache-key-llvm-x86_64-unknown-linux-musl }} | ||
cache-key-llvm-x86_64-apple-darwin: | ||
value: ${{ jobs.llvm.outputs.cache-key-llvm-x86_64-apple-darwin }} | ||
jobs: | ||
llvm: | ||
strategy: | ||
matrix: | ||
include: | ||
- target: aarch64-unknown-linux-musl | ||
os: ubuntu-latest | ||
- target: aarch64-apple-darwin | ||
os: macos-latest | ||
- target: x86_64-unknown-linux-musl | ||
os: ubuntu-latest | ||
- target: x86_64-apple-darwin | ||
os: macos-latest | ||
runs-on: ${{ matrix.os }} | ||
name: llvm | ||
outputs: | ||
cache-key-llvm-aarch64-unknown-linux-musl: ${{ steps.cache-key-llvm.outputs.cache-key-llvm-aarch64-unknown-linux-musl }} | ||
cache-key-llvm-aarch64-apple-darwin: ${{ steps.cache-key-llvm.outputs.cache-key-llvm-aarch64-apple-darwin }} | ||
cache-key-llvm-x86_64-unknown-linux-musl: ${{ steps.cache-key-llvm.outputs.cache-key-llvm-x86_64-unknown-linux-musl }} | ||
cache-key-llvm-x86_64-apple-darwin: ${{ steps.cache-key-llvm.outputs.cache-key-llvm-x86_64-apple-darwin }} | ||
steps: | ||
- id: ls-remote | ||
run: | | ||
set -euxo pipefail | ||
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/17.0-2023-09-19 | cut -f1) | ||
echo "sha=$value" >> "$GITHUB_OUTPUT" | ||
- id: cache-key-llvm | ||
run: echo "cache-key-llvm-${{ matrix.target }}=llvm-${{ matrix.target }}-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT" | ||
- name: Cache | ||
id: cache-llvm | ||
uses: actions/cache@v3 | ||
with: | ||
path: llvm-install | ||
key: ${{ steps.cache-key-llvm.outputs[format('cache-key-llvm-{0}', matrix.target)] }} | ||
lookup-only: true | ||
- name: Install Tools (Linux) | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') | ||
run: | | ||
set -euxo pipefail | ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \ | ||
gpg --dearmor - | \ | ||
sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null | ||
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | \ | ||
sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null | ||
sudo apt update | ||
sudo apt -y install cmake ninja-build clang lld | ||
- name: Install Tools (macOS) | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' && startsWith(matrix.os, 'macos-latest') | ||
run: | | ||
set -euxo pipefail | ||
brew install cmake ninja | ||
- name: Checkout LLVM Source | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: aya-rs/llvm-project | ||
ref: ${{ steps.ls-remote.outputs.sha }} | ||
path: llvm-project | ||
- name: Configure LLVM | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
run: | | ||
set -euxo pipefail | ||
# NOTE(vadorovsky): Linking with lld doesn't seem to work on macOS. | ||
# Not sure if it's a problem of lld in general or just the one coming | ||
# from Homebrew. | ||
# So far, linking with Apple ld doesn't seem to be significantly | ||
# slow, so it's more important to enforce usage of lld on Linux, where | ||
# it's much faster than musl ld. | ||
LLVM_USE_LINKER_OPTION="" | ||
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | ||
LLVM_USE_LINKER_OPTION="-DLLVM_USE_LINKER=lld" | ||
fi | ||
cmake \ | ||
-S llvm-project/llvm \ | ||
-B llvm-build \ | ||
-G Ninja \ | ||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DCMAKE_CXX_COMPILER=clang++ \ | ||
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/llvm-install" \ | ||
-DLLVM_BUILD_LLVM_DYLIB=ON \ | ||
-DLLVM_DEFAULT_TARGET_TRIPLE="${{ matrix.target }}" \ | ||
-DLLVM_ENABLE_ASSERTIONS=ON \ | ||
-DLLVM_ENABLE_PROJECTS= \ | ||
-DLLVM_ENABLE_RUNTIMES= \ | ||
-DLLVM_HOST_TRIPLE="${{ matrix.target }}" \ | ||
-DLLVM_INSTALL_UTILS=ON \ | ||
-DLLVM_LINK_LLVM_DYLIB=ON \ | ||
-DLLVM_TARGETS_TO_BUILD=BPF \ | ||
$LLVM_USE_LINKER_OPTION | ||
- name: Install LLVM | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
env: | ||
# Create symlinks rather than copies to conserve disk space. At the time of this writing, | ||
# GitHub-hosted runners have 14GB of SSD space | ||
# (https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources). | ||
# | ||
# Since the LLVM build creates a bunch of symlinks (and this setting does not turn those | ||
# into symlinks-to-symlinks), use absolute symlinks so we can distinguish the two cases. | ||
CMAKE_INSTALL_MODE: ABS_SYMLINK | ||
run: cmake --build llvm-build --target install | ||
- name: Setup tmate session | ||
if: ${{ failure() }} | ||
uses: mxschmitt/action-tmate@v3 | ||
- name: Rewrite LLVM Symlinks | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
# Move targets over the symlinks that point to them. | ||
# | ||
# This whole dance would be simpler if CMake supported CMAKE_INSTALL_MODE=MOVE. | ||
run: | | ||
set -euxo pipefail | ||
find llvm-install -type l -execdir sh -eux -c ' | ||
for link in "$@"; do | ||
target=$(readlink "$link") | ||
case $target in | ||
/*) mv "$target" "$link" ;; | ||
esac | ||
done | ||
' sh {} + | ||
runtimes: | ||
strategy: | ||
matrix: | ||
include: | ||
- target: aarch64-unknown-linux-musl | ||
os: ubuntu-latest | ||
- target: aarch64-apple-darwin | ||
os: macos-latest | ||
- target: x86_64-unknown-linux-musl | ||
os: ubuntu-latest | ||
- target: x86_64-apple-darwin | ||
os: macos-latest | ||
runs-on: ${{ matrix.os }} | ||
name: runtimes | ||
outputs: | ||
cache-key-runtimes-aarch64-unknown-linux-musl: ${{ steps.cache-key-runtimes.outputs.cache-key-runtimes-aarch64-unknown-linux-musl }} | ||
cache-key-runtimes-aarch64-apple-darwin: ${{ steps.cache-key-runtimes.outputs.cache-key-runtimes-aarch64-apple-darwin }} | ||
cache-key-runtimes-x86_64-unknown-linux-musl: ${{ steps.cache-key-runtimes.outputs.cache-key-runtimes-x86_64-unknown-linux-musl }} | ||
cache-key-runtimes-x86_64-apple-darwin: ${{ steps.cache-key-runtimes.outputs.cache-key-runtimes-x86_64-apple-darwin }} | ||
steps: | ||
- id: ls-remote | ||
run: | | ||
set -euxo pipefail | ||
value=$(git ls-remote https://github.com/aya-rs/llvm-project.git refs/heads/rustc/17.0-2023-09-19 | cut -f1) | ||
echo "sha=$value" >> "$GITHUB_OUTPUT" | ||
- id: cache-key-runtimes | ||
run: echo "cache-key-runtimes-${{ matrix.target }}=runtimes-${{ matrix.target }}-${{ steps.ls-remote.outputs.sha }}-1" >> "$GITHUB_OUTPUT" | ||
- name: Cache | ||
id: cache-runtimes | ||
uses: actions/cache@v3 | ||
with: | ||
path: runtimes-install | ||
key: ${{ steps.cache-key-runtimes.outputs[format('cache-key-runtimes-{0}', matrix.target)] }} | ||
lookup-only: true | ||
- name: Install Tools | ||
if: steps.cache-runtimes.outputs.cache-hit != 'true' && startsWith(matrix.os, 'ubuntu') | ||
run: | | ||
set -euxo pipefail | ||
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \ | ||
gpg --dearmor - | \ | ||
sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null | ||
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | \ | ||
sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null | ||
sudo apt update | ||
sudo apt -y install cmake ninja-build clang lld | ||
- name: Install Tools (macOS) | ||
if: steps.cache-runtimes.outputs.cache-hit != 'true' && startsWith(matrix.os, 'macos-latest') | ||
run: | | ||
set -euxo pipefail | ||
brew install cmake ninja | ||
- name: Checkout LLVM Source | ||
if: steps.cache-runtimes.outputs.cache-hit != 'true' | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: aya-rs/llvm-project | ||
ref: ${{ steps.ls-remote.outputs.sha }} | ||
path: llvm-project | ||
- name: Configure runtimes | ||
if: steps.cache-runtimes.outputs.cache-hit != 'true' | ||
run: | | ||
set -euxo pipefail | ||
# NOTE(vadorovsky): Linking with lld doesn't seem to work on macOS. | ||
# Not sure if it's a problem of lld in general or just the one coming | ||
# from Homebrew. | ||
# So far, linking with Apple ld doesn't seem to be significantly | ||
# slow, so it's more important to enforce usage of lld on Linux, where | ||
# it's much faster than musl ld. | ||
CMAKE_EXE_LINKER_FLAGS_OPTION="" | ||
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then | ||
CMAKE_EXE_LINKER_FLAGS_OPTION="-DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld" | ||
fi | ||
cmake \ | ||
-S llvm-project/runtimes \ | ||
-B runtimes-build \ | ||
-G Ninja \ | ||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ | ||
-DCMAKE_C_COMPILER=clang \ | ||
-DCMAKE_C_COMPILER_TARGET="${{ matrix.target }}" \ | ||
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/runtimes-install" \ | ||
-DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx;compiler-rt" \ | ||
$CMAKE_EXE_LINKER_FLAGS_OPTION | ||
- name: Install runtimes | ||
if: steps.cache-runtimes.outputs.cache-hit != 'true' | ||
run: cmake --build runtimes-build --target install | ||
- name: Setup tmate session | ||
if: ${{ failure() }} | ||
uses: mxschmitt/action-tmate@v3 |