Skip to content

Commit

Permalink
chore: Build LLVM for multiple targets
Browse files Browse the repository at this point in the history
Apart from the x86_64 Linux build, cross compile also to Linux
arm64, macOS x86_64 and macoOS arm64.
  • Loading branch information
vadorovsky committed Oct 5, 2023
1 parent cdcb6bd commit e2b2ce1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ jobs:
if: matrix.llvm == 'source'
run: |
set -euxo pipefail
echo "${{ github.workspace }}/llvm-install/bin" >> $GITHUB_PATH
echo "${{ github.workspace }}/llvm-install/x86_64-linux-gnu/bin" >> $GITHUB_PATH
# LD_LIBRARY_PATH is needed because we're going to link everything dynamically below. This
# doesn't affect behavior, but greatly reduces disk usage.
echo "LD_LIBRARY_PATH=${{ github.workspace }}/llvm-install/lib" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=${{ github.workspace }}/llvm-install/x86_64-linux-gnu/lib" >> $GITHUB_ENV
# llvm-sys discovers link flags at build script time; these are cached by cargo. The cached
# flags may be incorrect when the cache is reused across LLVM versions.
Expand Down
34 changes: 29 additions & 5 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ on:

jobs:
llvm:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- target: aarch64-linux-gnu
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
runs-on: ${{ matrix.os }}
name: llvm
outputs:
cache-key: ${{ steps.cache-key.outputs.cache-key }}
Expand All @@ -30,8 +41,8 @@ jobs:
key: ${{ steps.cache-key.outputs.cache-key }}
lookup-only: true

- name: Install Tools
if: steps.cache-llvm.outputs.cache-hit != 'true'
- name: Install Tools (Linux)
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'ubuntu-latest'
run: |
set -euxo pipefail
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
Expand All @@ -43,6 +54,13 @@ jobs:
sudo apt update
sudo apt -y install cmake ninja-build clang lld
- name: Install Tools (macOS)
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'macos-latest'
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "/usr/local/bin/brew" >> $GITHUB_PATH
brew install cmake ninja
- name: Checkout LLVM Source
if: steps.cache-llvm.outputs.cache-hit != 'true'
uses: actions/checkout@v4
Expand All @@ -55,22 +73,28 @@ jobs:
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: |
set -euxo pipefail
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" \
-DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/llvm-install/${{ matrix.target }}" \
-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 \
-DLLVM_USE_LINKER=lld
$LLVM_USE_LINKER_OPTION
- name: Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
Expand Down

0 comments on commit e2b2ce1

Please sign in to comment.