Skip to content

Commit 329e41a

Browse files
committed
feat: add macos LLVM build
1 parent f694570 commit 329e41a

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

.github/workflows/build-llvm.yaml

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,39 @@ jobs:
1313
name: Build LLVM
1414
strategy:
1515
matrix:
16-
# os: [ubuntu-20.04, macos-11, windows-2019]
17-
os: [ubuntu-20.04]
16+
# os: [ubuntu-20.04, macos-12, windows-2019]
17+
os: [ubuntu-20.04, macos-14]
1818
runs-on: ${{ matrix.os }}
19-
permissions:
20-
contents: write # for creating releases
21-
container:
22-
# Intentionally old ubuntu version with old glibc.
23-
image: ubuntu:18.04
2419
steps:
2520
- name: checkout
2621
uses: actions/checkout@v3
27-
28-
# Install build dependencies.
29-
- run: "apt update && apt install -y clang git wget build-essential python3 unzip"
30-
# cmake from package manager is to old for the LLVM build.
31-
- run: "wget https://github.com/Kitware/CMake/releases/download/v3.30.0-rc2/cmake-3.30.0-rc2-linux-x86_64.sh"
32-
- run: "chmod +x cmake-*.sh"
33-
- run: "./cmake-*.sh --skip-license --prefix=/usr"
34-
# ninja from the package manager is to old for the LLVM build.
35-
- run: "wget https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-linux.zip"
36-
- run: "unzip ninja-linux.zip -d /usr/bin/"
22+
- if: contains(matrix.os, 'ubuntu')
23+
run: "sudo apt update && sudo apt install -y ninja-build"
24+
- if: contains(matrix.os, 'macos')
25+
run: "brew install ninja"
3726
# Build and package LLVM.
38-
- run: "./build-llvm-libs.sh"
39-
- uses: actions/upload-artifact@v3
27+
- run: "./build-llvm-libs.sh llvm-static-libs-${{ matrix.os }}.tar.gz"
28+
- uses: actions/upload-artifact@v4
4029
with:
41-
name: llvm-static-libs
42-
path: llvm-static-libs.tar.gz
43-
- name: create release
44-
id: create-release
45-
uses: actions/create-release@v1
46-
env:
47-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
name: llvm-static-libs-${{ matrix.os }}
31+
path: llvm-static-libs-${{ matrix.os }}.tar.gz
32+
33+
create_release:
34+
name: Create release
35+
runs-on: ubuntu-latest
36+
needs: [build_llvm]
37+
permissions:
38+
contents: write # for creating releases
39+
steps:
40+
- name: Download Artifacts
41+
uses: actions/download-artifact@v4
4842
with:
49-
tag_name: ${{ inputs.tag }}
50-
release_name: ${{ inputs.tag }}
51-
draft: false
52-
prerelease: true
53-
- name: upload linux artifact
54-
uses: actions/upload-release-asset@v1
55-
env:
56-
GITHUB_TOKEN: ${{ github.token }}
43+
pattern: llvm-static-libs-*
44+
merge-multiple: true
45+
- name: Create Release
46+
uses: softprops/action-gh-release@v2
5747
with:
58-
upload_url: ${{ steps.create-release.outputs.upload_url }}
59-
asset_path: ./llvm-static-libs.tar.xz
60-
asset_name: llvm-static-linux-amd64.tar.xz
61-
asset_content_type: application/gzip
48+
name: LLVM tooling libraries ${{ inputs.tag }}
49+
tag_name: ${{ inputs.tag }}
50+
files: llvm-static-libs-*
51+
fail_on_unmatched_files: true

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ set(CMAKE_BUILD_TYPE Release)
1717

1818
set(LLVM_PROJECT_TARGET external.llvm-project)
1919

20+
if (NOT(DEFINED LLVM_TARGETS_TO_BUILD))
21+
message(FATAL_ERROR "You must set LLVM_TARGETS_TO_BUILD variable with -DLLVM_TARGETS_TO_BUILD=<X86|AArch64>.")
22+
endif()
23+
2024
include(ExternalProject)
2125
ExternalProject_Add(${LLVM_PROJECT_TARGET}
2226
PREFIX ${LLVM_PROJECT_TARGET}
@@ -37,7 +41,7 @@ ExternalProject_Add(${LLVM_PROJECT_TARGET}
3741
-DLLVM_ENABLE_PROJECTS=clang
3842
-DLLVM_ENABLE_RTTI=ON
3943
-DLLVM_ENABLE_PIC=OFF
40-
-DLLVM_TARGETS_TO_BUILD=X86
44+
-DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD}
4145
-DLLVM_BUILD_TOOLS=OFF
4246
-DLLVM_BUILD_TESTS=OFF
4347
-DLLVM_ENABLE_TERMINFO=OFF

build-llvm-libs.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
44
BUILD_DIR="$SCRIPT_DIR/build"
55
LLVM_BUILD_DIR="$BUILD_DIR/external.llvm-project"
66

7+
OUTPUT_FILE=llvm-static-libs.tar.xz
8+
if [ "$#" -eq 1 ]
9+
then
10+
OUTPUT_FILE=$1
11+
fi
12+
13+
CC=clang
14+
CXX=clang++
15+
16+
TARGET_PLATFORM=X86
17+
if [ "$(uname)" == "Darwin" ]; then
18+
# On Mac we only support the new apple silicon architecture.
19+
TARGET_PLATFORM=AArch64
20+
fi
21+
722
cd "$SCRIPT_DIR"
8-
mkdir -p build
9-
cmake -B build -GNinja .
23+
mkdir -p $BUILD_DIR
24+
25+
cmake -B build -GNinja -DLLVM_TARGETS_TO_BUILD=${TARGET_PLATFORM} .
1026
cmake --build build
1127

1228
# Pack everything we need into a tar archive.
1329
# We only need the header files, static libraries and add
1430
# a CMake file that makes it easy to link libclangTooling.
1531
cp $SCRIPT_DIR/cmake/CMakeLists.txt $LLVM_BUILD_DIR
1632
cd $LLVM_BUILD_DIR
17-
tar -czvf "$SCRIPT_DIR/llvm-static-libs.tar.xz" include/ lib/*.a CMakeLists.txt
33+
tar -czvf "$SCRIPT_DIR/$OUTPUT_FILE" include/ lib/*.a CMakeLists.txt

0 commit comments

Comments
 (0)