Skip to content

Commit 1da3457

Browse files
authored
build: use pixi for managing build toolchains (#322)
1 parent cec13ec commit 1da3457

35 files changed

+3767
-1211
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SCM syntax highlighting & preventing 3-way merges
2+
pixi.lock merge=binary linguist-language=YAML linguist-generated=true -diff

.github/workflows/build-llvm.yml

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
name: build llvm
2+
3+
on:
4+
pull_request:
5+
# if you want to run this workflow, change the branch name to main,
6+
# if you want to turn off it, change it to non existent branch.
7+
branches: [main-turn-off]
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
# Windows
16+
- os: windows-2025
17+
llvm_mode: Debug
18+
lto: OFF
19+
- os: windows-2025
20+
llvm_mode: RelWithDebInfo
21+
lto: OFF
22+
- os: windows-2025
23+
llvm_mode: RelWithDebInfo
24+
lto: ON
25+
# Linux
26+
- os: ubuntu-24.04
27+
llvm_mode: Debug
28+
lto: OFF
29+
- os: ubuntu-24.04
30+
llvm_mode: RelWithDebInfo
31+
lto: OFF
32+
- os: ubuntu-24.04
33+
llvm_mode: RelWithDebInfo
34+
lto: ON
35+
# macOS
36+
- os: macos-15
37+
llvm_mode: Debug
38+
lto: OFF
39+
- os: macos-15
40+
llvm_mode: RelWithDebInfo
41+
lto: OFF
42+
- os: macos-15
43+
llvm_mode: RelWithDebInfo
44+
lto: ON
45+
46+
runs-on: ${{ matrix.os }}
47+
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v4
51+
52+
- name: Free Disk Space
53+
if: runner.os == 'Linux'
54+
uses: jlumbroso/free-disk-space@main
55+
56+
- name: Increase Swap Space
57+
if: runner.os == 'Linux'
58+
run: |
59+
echo "===== Initial Status ====="
60+
sudo swapon --show
61+
free -h
62+
63+
echo "===== Creating Swap File ====="
64+
sudo swapoff -a
65+
sudo fallocate -l 16G /mnt/swapfile
66+
sudo chmod 600 /mnt/swapfile
67+
sudo mkswap /mnt/swapfile
68+
sudo swapon /mnt/swapfile
69+
70+
echo "===== Final Status ====="
71+
sudo swapon --show
72+
free -h
73+
df -h
74+
75+
- name: Setup Pixi
76+
uses: prefix-dev/setup-pixi@v0.9.3
77+
with:
78+
pixi-version: v0.59.0
79+
environments: package
80+
activate-environment: true
81+
cache: true
82+
locked: true
83+
84+
- name: Clone llvm-project (21.1.4)
85+
shell: bash
86+
run: |
87+
git clone --branch llvmorg-21.1.4 --depth 1 https://github.com/llvm/llvm-project.git .llvm
88+
89+
- name: Build LLVM (install-distribution)
90+
shell: bash
91+
run: |
92+
pixi run build-llvm --llvm-src=.llvm --mode="${{ matrix.llvm_mode }}" --lto="${{ matrix.lto }}" --build-dir=build
93+
94+
- name: Build clice using installed LLVM
95+
shell: bash
96+
run: |
97+
cmake -B build -G Ninja \
98+
-DCMAKE_BUILD_TYPE=${{ matrix.llvm_mode }} \
99+
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain.cmake \
100+
-DCLICE_ENABLE_TEST=ON \
101+
-DCLICE_CI_ENVIRONMENT=ON \
102+
-DCLICE_ENABLE_LTO=${{ matrix.lto }} \
103+
-DLLVM_INSTALL_PATH=".llvm/build-install"
104+
cmake --build build
105+
106+
- name: Run tests
107+
shell: bash
108+
run: |
109+
EXE_EXT=""
110+
if [[ "${{ runner.os }}" == "Windows" ]]; then
111+
EXE_EXT=".exe"
112+
fi
113+
./build/bin/unit_tests${EXE_EXT} --test-dir="./tests/data"
114+
uv run --project tests pytest -s --log-cli-level=INFO tests/integration --executable=./build/bin/clice${EXE_EXT}
115+
116+
- name: Prune LLVM static libraries (Debug/RelWithDebInfo no LTO)
117+
if: matrix.llvm_mode == 'Debug' || (matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF')
118+
shell: bash
119+
run: |
120+
MANIFEST="pruned-libs-${{ matrix.os }}.json"
121+
echo "LLVM_PRUNED_MANIFEST=${MANIFEST}" >> "${GITHUB_ENV}"
122+
python3 scripts/prune-llvm-bin.py \
123+
--action discover \
124+
--install-dir ".llvm/build-install/lib" \
125+
--build-dir "build" \
126+
--max-attempts 60 \
127+
--sleep-seconds 60 \
128+
--manifest "${MANIFEST}"
129+
130+
- name: Upload pruned-libs manifest
131+
if: matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF'
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: llvm-pruned-libs-${{ matrix.os }}
135+
path: ${{ env.LLVM_PRUNED_MANIFEST }}
136+
if-no-files-found: error
137+
compression-level: 0
138+
139+
- name: Apply pruned-libs manifest (RelWithDebInfo + LTO)
140+
if: matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'ON'
141+
shell: bash
142+
env:
143+
GH_TOKEN: ${{ github.token }}
144+
run: |
145+
MANIFEST="pruned-libs-${{ matrix.os }}.json"
146+
python3 scripts/prune-llvm-bin.py \
147+
--action apply \
148+
--manifest "${MANIFEST}" \
149+
--install-dir ".llvm/build-install/lib" \
150+
--build-dir "build" \
151+
--gh-run-id "${{ github.run_id }}" \
152+
--gh-artifact "llvm-pruned-libs-${{ matrix.os }}" \
153+
--gh-download-dir "artifacts" \
154+
--max-attempts 60 \
155+
--sleep-seconds 60
156+
157+
- name: Package LLVM install directory
158+
shell: bash
159+
run: |
160+
MODE_TAG="releasedbg"
161+
if [[ "${{ matrix.llvm_mode }}" == "Debug" ]]; then
162+
MODE_TAG="debug"
163+
fi
164+
165+
ARCH="x64"
166+
PLATFORM="linux"
167+
TOOLCHAIN="gnu"
168+
if [[ "${{ matrix.os }}" == windows-* ]]; then
169+
PLATFORM="windows"
170+
TOOLCHAIN="msvc"
171+
elif [[ "${{ matrix.os }}" == macos-* ]]; then
172+
ARCH="arm64"
173+
PLATFORM="macos"
174+
TOOLCHAIN="clang"
175+
fi
176+
177+
SUFFIX=""
178+
if [[ "${{ matrix.lto }}" == "ON" ]]; then
179+
SUFFIX="-lto"
180+
fi
181+
if [[ "${{ matrix.llvm_mode }}" == "Debug" ]]; then
182+
SUFFIX="${SUFFIX}-asan"
183+
fi
184+
185+
ARCHIVE="${ARCH}-${PLATFORM}-${TOOLCHAIN}-${MODE_TAG}${SUFFIX}.tar.xz"
186+
187+
set -eo pipefail
188+
tar -C .llvm -cf - build-install | xz -T0 -9 -c > "${ARCHIVE}"
189+
echo "LLVM_INSTALL_ARCHIVE=${ARCHIVE}" >> "${GITHUB_ENV}"
190+
191+
- name: Upload LLVM install artifact
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: ${{ env.LLVM_INSTALL_ARCHIVE }}
195+
path: ${{ env.LLVM_INSTALL_ARCHIVE }}
196+
if-no-files-found: error

.github/workflows/cmake.yml

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- "src/**"
1010
- "tests/**"
1111
- "CMakeLists.txt"
12+
1213
pull_request:
1314
branches: [main]
1415
paths:
@@ -27,86 +28,42 @@ jobs:
2728
include:
2829
- os: windows-2025
2930
build_type: RelWithDebInfo
30-
cc: clang
31-
cxx: clang++
3231
- os: ubuntu-24.04
3332
build_type: Debug
34-
cc: clang-20
35-
cxx: clang++-20
3633
- os: macos-15
3734
build_type: Debug
38-
cc: clang
39-
cxx: clang++
4035

4136
runs-on: ${{ matrix.os }}
4237

4338
steps:
44-
- name: Setup dependencies (Windows)
45-
if: runner.os == 'Windows'
46-
uses: MinoruSekine/setup-scoop@v4.0.1
47-
with:
48-
buckets: main
49-
apps: ninja
50-
51-
- name: Setup dependencies (Linux)
52-
if: runner.os == 'Linux'
53-
run: |
54-
sudo apt update
55-
sudo apt install -y gcc-14 g++-14 libstdc++-14-dev
56-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
57-
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100
58-
sudo update-alternatives --set gcc /usr/bin/gcc-14
59-
sudo update-alternatives --set g++ /usr/bin/g++-14
60-
wget https://apt.llvm.org/llvm.sh
61-
chmod +x llvm.sh
62-
sudo ./llvm.sh 20 all
63-
sudo apt install -y cmake ninja-build
64-
65-
- name: Setup dependencies (MacOS)
66-
if: runner.os == 'macOS'
67-
env:
68-
HOMEBREW_NO_AUTO_UPDATE: 1
69-
run: |
70-
brew install llvm@20 lld@20
71-
7239
- name: Checkout repository
7340
uses: actions/checkout@v4
7441

75-
- name: Setup msvc sysroot for cmake
76-
if: runner.os == 'Windows'
77-
uses: ilammy/msvc-dev-cmd@v1
42+
- name: Setup Pixi
43+
uses: prefix-dev/setup-pixi@v0.9.3
44+
with:
45+
pixi-version: v0.59.0
46+
environments: develop
47+
activate-environment: true
48+
cache: true
49+
locked: true
7850

7951
- name: Build clice
8052
shell: bash
8153
run: |
82-
if [[ "${{ runner.os }}" == "macOS" ]]; then
83-
export SDKROOT=$(xcrun --show-sdk-path)
84-
export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH"
85-
fi
86-
8754
cmake -B build -G Ninja \
8855
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
89-
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
90-
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
56+
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain.cmake \
9157
-DCLICE_ENABLE_TEST=ON \
9258
-DCLICE_CI_ENVIRONMENT=ON
93-
9459
cmake --build build
9560
96-
- name: Install uv for integration tests
97-
uses: astral-sh/setup-uv@v6
98-
9961
- name: Run tests
10062
shell: bash
10163
run: |
10264
EXE_EXT=""
10365
if [[ "${{ runner.os }}" == "Windows" ]]; then
10466
EXE_EXT=".exe"
10567
fi
106-
107-
if [[ "${{ runner.os }}" == "macOS" ]]; then
108-
export PATH="/opt/homebrew/opt/llvm@20/bin:/opt/homebrew/opt/lld@20/bin:$PATH"
109-
fi
110-
11168
./build/bin/unit_tests${EXE_EXT} --test-dir="./tests/data"
11269
uv run --project tests pytest -s --log-cli-level=INFO tests/integration --executable=./build/bin/clice${EXE_EXT}

.github/workflows/docker.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

.github/workflows/upload-llvm.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: upload-llvm
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
pull_request:
8+
# if you want to run this workflow, change the branch name to main,
9+
# if you want to turn off it, change it to non existent branch.
10+
branches: [main-turn-off]
11+
12+
workflow_dispatch:
13+
inputs:
14+
workflow_id:
15+
description: "Workflow run ID to pull artifacts from"
16+
required: true
17+
type: string
18+
version:
19+
description: "Release version/tag to publish (e.g., v1.2.3)"
20+
required: true
21+
type: string
22+
23+
jobs:
24+
upload:
25+
runs-on: ubuntu-24.04
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Download artifacts from workflow
30+
env:
31+
GH_TOKEN: ${{ github.token }}
32+
run: scripts/download-llvm.sh "${{ inputs.workflow_id }}"
33+
34+
- name: Recreate release with artifacts
35+
env:
36+
GH_TOKEN: ${{ secrets.UPLOAD_LLVM }}
37+
TARGET_REPO: clice-io/clice-llvm
38+
run: python3 scripts/upload-llvm.py "${{ inputs.version }}" "${TARGET_REPO}" "${{ inputs.workflow_id }}"

0 commit comments

Comments
 (0)