Skip to content

Commit eb0a6a4

Browse files
committed
Build custom toolchains
1 parent b850356 commit eb0a6a4

File tree

6 files changed

+235
-1
lines changed

6 files changed

+235
-1
lines changed

.github/workflows/toolchain.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build toolchain
2+
3+
env:
4+
LLVM_REF: "cd708029e0b2869e80abe31ddb175f7c35361f90" # 19.1.7
5+
# GH Actions are dead slow, can't build two-stage
6+
CMAKE_CACHE: "SingleStage" # ToolchainCache
7+
STAGE: "" # stage2-
8+
9+
on:
10+
push:
11+
branches: ["main"]
12+
pull_request:
13+
branches: ["main"]
14+
jobs:
15+
toolchain-build:
16+
name: ${{ matrix.OS }} toolchain (${{ matrix.ARCH}})
17+
runs-on: ${{ matrix.RUNNER }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- ARCH: x86_64
23+
RUNNER: ubuntu-22.04
24+
OS: Linux
25+
- ARCH: aarch64
26+
RUNNER: ubuntu-22.04-arm
27+
OS: Linux
28+
- ARCH: aarch64
29+
RUNNER: macos-latest
30+
OS: Darwin
31+
steps:
32+
- uses: actions/checkout@v5
33+
- uses: hendrikmuhs/[email protected]
34+
with:
35+
max-size: "5000MB"
36+
- uses: actions/checkout@v5
37+
with:
38+
repository: 'llvm/llvm-project'
39+
ref: ${{ env.LLVM_REF }}
40+
path: 'llvm'
41+
- name: Install deps
42+
if: matrix.OS == 'Linux'
43+
run: |
44+
sudo apt-get install ninja-build
45+
- name: Build toolchain
46+
run: |
47+
mkdir build.dir
48+
cmake -G Ninja \
49+
-B build.dir \
50+
-C ${{ env.CMAKE_CACHE }}.cmake \
51+
llvm/llvm \
52+
-DCMAKE_INSTALL_PREFIX=${{ matrix.OS }}-${{ matrix.ARCH }}.toolchain
53+
cmake --build build.dir --target ${{ env.STAGE }}distribution
54+
cmake --build build.dir --target ${{ env.STAGE }}install-distribution
55+
- name: Package toolchain
56+
run: |
57+
tar -cvzf \
58+
${{ matrix.OS }}-${{ matrix.ARCH }}.toolchain.tar.gz \
59+
${{ matrix.OS }}-${{ matrix.ARCH }}.toolchain
60+
tar cvfJ \
61+
${{ matrix.OS }}-${{ matrix.ARCH }}.toolchain.tar.xz \
62+
${{ matrix.OS }}-${{ matrix.ARCH }}.toolchain
63+
- name: Upload toolchain
64+
uses: svenstaro/upload-release-action@v2
65+
with:
66+
repo_token: ${{ secrets.GITHUB_TOKEN }}
67+
file: "*.tar.*"
68+
tag: ${{ github.run_id }}
69+
overwrite: true
70+
file_glob: true
71+
target_commit: ${{ github.sha }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build.dir
2+
*.toolchain
3+
*.tar.gz
4+
*.tar.xz
5+

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# toolchains
1+
# toolchains
2+
3+
Custom LLVM toolchains for Mull.

SingleStage.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Based on clang/cmake/caches/DistributionExample-stage2.cmake
2+
3+
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
4+
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
5+
6+
set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
7+
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
8+
set(LLVM_CCACHE_BUILD ON CACHE BOOL "")
9+
set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")
10+
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
11+
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
12+
set(LLVM_STATIC_LINK_CXX_STDLIB ON CACHE BOOL "")
13+
14+
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
15+
16+
if(APPLE)
17+
set(libtool_darwin llvm-libtool-darwin)
18+
endif()
19+
20+
# setup toolchain
21+
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
22+
set(LLVM_TOOLCHAIN_TOOLS
23+
${libtool_darwin}
24+
clang-format
25+
clang-tidy
26+
llvm-ar
27+
llvm-dwp
28+
llvm-nm
29+
llvm-objcopy
30+
llvm-objdump
31+
llvm-profdata
32+
llvm-ranlib
33+
llvm-strip
34+
llvm-symbolizer
35+
clangd
36+
llvm-cov
37+
38+
CACHE STRING "")
39+
40+
set(LLVM_DISTRIBUTION_COMPONENTS
41+
clang
42+
LTO
43+
lld
44+
clang-format
45+
clang-resource-headers
46+
builtins
47+
runtimes
48+
${LLVM_TOOLCHAIN_TOOLS}
49+
CACHE STRING "")

ToolchainCache-stage2.cmake

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Based on clang/cmake/caches/DistributionExample-stage2.cmake
2+
3+
# This file sets up a CMakeCache for the second stage of a simple distribution
4+
# bootstrap build.
5+
6+
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
7+
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
8+
9+
set(LLVM_TARGETS_TO_BUILD X86;ARM;AArch64 CACHE STRING "")
10+
11+
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
12+
set(LLVM_CCACHE_BUILD ON CACHE BOOL "")
13+
set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")
14+
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
15+
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
16+
17+
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
18+
19+
if(APPLE)
20+
set(libtool_darwin llvm-libtool-darwin)
21+
endif()
22+
23+
# setup toolchain
24+
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
25+
set(LLVM_TOOLCHAIN_TOOLS
26+
${libtool_darwin}
27+
clang-format
28+
clang-tidy
29+
llvm-ar
30+
llvm-dwp
31+
llvm-nm
32+
llvm-objcopy
33+
llvm-objdump
34+
llvm-profdata
35+
llvm-ranlib
36+
llvm-strip
37+
llvm-symbolizer
38+
39+
CACHE STRING "")
40+
41+
set(LLVM_DISTRIBUTION_COMPONENTS
42+
clang
43+
LTO
44+
lld
45+
clang-format
46+
clang-resource-headers
47+
builtins
48+
runtimes
49+
${LLVM_TOOLCHAIN_TOOLS}
50+
CACHE STRING "")

ToolchainCache.cmake

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Based on clang/cmake/caches/DistributionExample.cmake
2+
# This file sets up a CMakeCache for a simple distribution bootstrap build.
3+
4+
# Enable LLVM projects and runtimes
5+
set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
6+
set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
7+
8+
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
9+
set(LLVM_CCACHE_BUILD ON CACHE BOOL "")
10+
set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")
11+
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
12+
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
13+
14+
# Only build the native target in stage1 since it is a throwaway build.
15+
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
16+
17+
# Optimize the stage1 compiler, but don't LTO it because that wastes time.
18+
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
19+
20+
# Setup vendor-specific settings.
21+
set(PACKAGE_VENDOR LLVM.org CACHE STRING "")
22+
23+
# Setting up the stage2 LTO option needs to be done on the stage1 build so that
24+
# the proper LTO library dependencies can be connected.
25+
set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")
26+
27+
if(NOT APPLE)
28+
# Since LLVM_ENABLE_LTO is ON we need a LTO capable linker
29+
set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
30+
endif()
31+
32+
# Expose stage2 targets through the stage1 build configuration.
33+
set(CLANG_BOOTSTRAP_TARGETS
34+
check-all
35+
check-llvm
36+
check-clang
37+
llvm-config
38+
test-suite
39+
test-depends
40+
llvm-test-depends
41+
clang-test-depends
42+
distribution
43+
install-distribution
44+
clang CACHE STRING "")
45+
46+
# Setup the bootstrap build.
47+
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
48+
49+
if(STAGE2_CACHE_FILE)
50+
set(CLANG_BOOTSTRAP_CMAKE_ARGS
51+
-C ${STAGE2_CACHE_FILE}
52+
CACHE STRING "")
53+
else()
54+
set(CLANG_BOOTSTRAP_CMAKE_ARGS
55+
-C ${CMAKE_CURRENT_LIST_DIR}/ToolchainCache-stage2.cmake
56+
CACHE STRING "")
57+
endif()

0 commit comments

Comments
 (0)