## Summary
This PR adds cross-compilation support for three new target platforms,
upgrades LLVM to 21.1.8, and overhauls the CI pipelines around
cross-builds and testing.
## Cross-compilation
New target triples accepted via `-DCLICE_TARGET_TRIPLE=...`:
| Target triple | Host | Output |
|---|---|---|
| `x86_64-apple-darwin` | macos-15 (arm64) | macOS x64 |
| `aarch64-linux-gnu` | ubuntu-24.04 (x64) | Linux arm64 |
| `aarch64-pc-windows-msvc` | windows-2025 (x64) | Windows arm64 |
- `cmake/toolchain.cmake` — maps `CLICE_TARGET_TRIPLE` to
`CMAKE_SYSTEM_NAME`/`CMAKE_SYSTEM_PROCESSOR`/compiler `--target`; picks
up conda aarch64 sysroot when cross-compiling Linux.
- `cmake/llvm.cmake` — forwards target platform/arch to `setup-llvm.py`
so the right prebuilt LLVM is downloaded for the target.
- `CMakeLists.txt` — uses a host-side `flatc` from `PATH` under
`CMAKE_CROSSCOMPILING` instead of the in-tree target build.
- `pixi.toml`:
- Adds `osx-64`, `linux-aarch64`, `win-arm64` platforms.
- New environments: `cross-macos-x64`, `cross-linux-aarch64` (adds
`gcc_linux-aarch64` + `sysroot_linux-aarch64`), `cross-windows-arm64`.
- New lightweight `test-run` env used on native ARM/x64 runners to
execute cross-built artifacts (pulls in upstream clang+lld on macOS so
tests don't fall back to Apple clang).
- `scripts/activate_cross_linux.sh` — exports `CONDA_PREFIX`-relative
paths for the aarch64 toolchain.
- `scripts/build-llvm.py` — `--target-triple` support and a
`build_native_tools()` helper that produces host `llvm-tblgen` /
`clang-tblgen` needed when cross-compiling LLVM itself.
## LLVM upgrade 21.1.4 → 21.1.8
- `cmake/package.cmake` bumps `setup_llvm("21.1.8")`.
- `config/llvm-manifest.json` regenerated with 6 new cross-compiled
entries and a new `arch` field on every entry so lookup is `(version,
platform, arch, lto, build_type)`.
- `scripts/setup-llvm.py` — honours the new `arch` field when resolving
artifacts.
- `scripts/update-llvm-version.py` (new) — single-call version bump
across `package.cmake` + manifest.
- `scripts/validate-llvm-components.py` (new) — scans the LLVM source
tree for library targets and diffs them against
`scripts/llvm-components.json` to catch stale/misspelled component names
before a build.
- `scripts/llvm-components.json` (new) — explicit allow-list of required
LLVM/Clang library targets used by `build-llvm.py`.
## CI changes
- `.github/workflows/build-llvm.yml`:
- Adds `workflow_dispatch` with `llvm_version`, `skip_upload`, `skip_pr`
inputs.
- Matrix extended with the 6 cross-compile entries (2 per new platform:
RelWithDebInfo ± LTO).
- `build clice` / test / prune steps gated on `!matrix.target_triple`
for cross-builds; cross-built LTO entries apply the native prune
manifest (arch-independent).
- Cross-compiled binary architecture is verified with `file(1)`.
- New `upload` job triggered by `workflow_dispatch` pushes artifacts to
`clice-io/clice-llvm` and hands the manifest off to the next job.
- `.github/workflows/test-cmake.yml`:
- Build matrix gains three `build_only: true` cross entries that upload
`bin/` + `lib/` artifacts.
- New `test-cross` job runs on native `macos-15-intel`,
`ubuntu-24.04-arm`, `windows-11-arm` runners, downloads the cross-built
artifacts, and runs unit / integration / smoke tests under the
`test-run` pixi env.
- Cache keys now include `target_triple` so native and cross builds
don't collide.
- `.github/workflows/publish-clice.yml`:
- Three additional release artifacts for the new targets
(`clice-x86_64-macos-darwin`, `clice-aarch64-linux-gnu`,
`clice-aarch64-windows-msvc`), each with a matching `-symbol` archive.
## Compatibility
- All existing native builds and tests are preserved; cross entries are
additive.
- `Debug` + ASAN remains disabled on Windows (`llvm_mode == Debug && os
== windows-*` no longer appends `-asan`).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
447 lines
15 KiB
YAML
447 lines
15 KiB
YAML
name: build llvm
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
llvm_version:
|
|
description: "LLVM version to build (e.g., 21.1.8)"
|
|
required: true
|
|
type: string
|
|
skip_upload:
|
|
description: "Skip upload and PR creation (build-only mode)"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
skip_pr:
|
|
description: "Skip PR creation (upload only, no PR)"
|
|
required: false
|
|
type: boolean
|
|
default: false
|
|
pull_request:
|
|
# if you want to run this workflow, change the branch name to main,
|
|
# if you want to turn off it, change it to non existent branch.
|
|
branches: [main-turn-off]
|
|
|
|
jobs:
|
|
build:
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
# Native builds
|
|
- os: windows-2025
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
- os: windows-2025
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
- os: ubuntu-24.04
|
|
llvm_mode: Debug
|
|
lto: OFF
|
|
- os: ubuntu-24.04
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
- os: ubuntu-24.04
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
- os: macos-15
|
|
llvm_mode: Debug
|
|
lto: OFF
|
|
- os: macos-15
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
- os: macos-15
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
|
|
# Cross-compilation builds
|
|
# macOS x64 (from arm64 macos-15)
|
|
- os: macos-15
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
target_triple: x86_64-apple-darwin
|
|
- os: macos-15
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
target_triple: x86_64-apple-darwin
|
|
|
|
# Linux aarch64 (from x64 ubuntu-24.04)
|
|
- os: ubuntu-24.04
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
target_triple: aarch64-linux-gnu
|
|
pixi_env: cross-linux-aarch64
|
|
- os: ubuntu-24.04
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
target_triple: aarch64-linux-gnu
|
|
pixi_env: cross-linux-aarch64
|
|
|
|
# Windows arm64 (from x64 windows-2025)
|
|
- os: windows-2025
|
|
llvm_mode: RelWithDebInfo
|
|
lto: OFF
|
|
target_triple: aarch64-pc-windows-msvc
|
|
pixi_env: cross-windows-arm64
|
|
- os: windows-2025
|
|
llvm_mode: RelWithDebInfo
|
|
lto: ON
|
|
target_triple: aarch64-pc-windows-msvc
|
|
pixi_env: cross-windows-arm64
|
|
|
|
runs-on: ${{ matrix.os }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Free Disk Space
|
|
if: runner.os == 'Linux'
|
|
uses: jlumbroso/free-disk-space@main
|
|
|
|
- name: Increase Swap Space
|
|
if: runner.os == 'Linux'
|
|
run: |
|
|
echo "===== Initial Status ====="
|
|
sudo swapon --show
|
|
free -h
|
|
|
|
echo "===== Creating Swap File ====="
|
|
sudo swapoff -a
|
|
sudo fallocate -l 16G /mnt/swapfile
|
|
sudo chmod 600 /mnt/swapfile
|
|
sudo mkswap /mnt/swapfile
|
|
sudo swapon /mnt/swapfile
|
|
|
|
echo "===== Final Status ====="
|
|
sudo swapon --show
|
|
free -h
|
|
df -h
|
|
|
|
- uses: ./.github/actions/setup-pixi
|
|
with:
|
|
environments: ${{ matrix.pixi_env || 'package' }}
|
|
|
|
- name: Clone llvm-project
|
|
shell: bash
|
|
run: |
|
|
VERSION="${{ inputs.llvm_version || '21.1.8' }}"
|
|
echo "Cloning LLVM ${VERSION}..."
|
|
git clone --branch "llvmorg-${VERSION}" --depth 1 https://github.com/llvm/llvm-project.git .llvm
|
|
|
|
- name: Validate distribution components
|
|
shell: bash
|
|
run: |
|
|
python3 scripts/validate-llvm-components.py \
|
|
--llvm-src=.llvm \
|
|
--components-file=scripts/llvm-components.json
|
|
|
|
- name: Build LLVM (install-distribution)
|
|
shell: bash
|
|
run: |
|
|
ENV="${{ matrix.pixi_env || 'package' }}"
|
|
EXTRA_ARGS=""
|
|
if [[ -n "${{ matrix.target_triple }}" ]]; then
|
|
EXTRA_ARGS="--target-triple=${{ matrix.target_triple }}"
|
|
fi
|
|
pixi run -e "$ENV" build-llvm \
|
|
--llvm-src=.llvm \
|
|
--mode="${{ matrix.llvm_mode }}" \
|
|
--lto="${{ matrix.lto }}" \
|
|
--build-dir=build \
|
|
${EXTRA_ARGS}
|
|
|
|
- name: Build clice using installed LLVM
|
|
if: ${{ !matrix.target_triple }}
|
|
shell: bash
|
|
run: |
|
|
pixi run cmake-config ${{ matrix.llvm_mode }} ON -- \
|
|
"-DCLICE_ENABLE_LTO=${{ matrix.lto }}" \
|
|
"-DLLVM_INSTALL_PATH=.llvm/build-install"
|
|
pixi run cmake-build ${{ matrix.llvm_mode }}
|
|
|
|
- name: Build clice using installed LLVM (cross-compile)
|
|
if: ${{ matrix.target_triple }}
|
|
shell: bash
|
|
run: |
|
|
ENV="${{ matrix.pixi_env || 'package' }}"
|
|
pixi run -e "$ENV" cmake-config ${{ matrix.llvm_mode }} ON -- \
|
|
"-DCLICE_ENABLE_LTO=${{ matrix.lto }}" \
|
|
"-DCLICE_TARGET_TRIPLE=${{ matrix.target_triple }}" \
|
|
"-DLLVM_INSTALL_PATH=.llvm/build-install"
|
|
pixi run -e "$ENV" cmake-build ${{ matrix.llvm_mode }}
|
|
|
|
- name: Verify cross-compiled binary architecture
|
|
if: ${{ matrix.target_triple && runner.os != 'Windows' }}
|
|
shell: bash
|
|
run: |
|
|
BINARY="build/${{ matrix.llvm_mode }}/bin/clice"
|
|
echo "Binary info:"
|
|
file "$BINARY"
|
|
case "${{ matrix.target_triple }}" in
|
|
aarch64-linux-gnu) file "$BINARY" | grep -q "aarch64" ;;
|
|
x86_64-apple-darwin) file "$BINARY" | grep -q "x86_64" ;;
|
|
esac
|
|
|
|
- name: Upload cross-compiled clice for functional test
|
|
if: ${{ matrix.target_triple && matrix.lto == 'OFF' }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: cross-clice-${{ matrix.target_triple }}-${{ matrix.llvm_mode }}
|
|
path: |
|
|
build/${{ matrix.llvm_mode }}/bin/
|
|
build/${{ matrix.llvm_mode }}/lib/
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
- name: Run tests
|
|
if: ${{ !matrix.target_triple }}
|
|
shell: bash
|
|
run: pixi run test ${{ matrix.llvm_mode }}
|
|
|
|
# Prune is only supported for native builds (requires linking clice to test).
|
|
# Cross-compiled targets reuse the native prune manifest of the same OS.
|
|
- name: Prune LLVM static libraries (Debug/RelWithDebInfo no LTO)
|
|
if: (!matrix.target_triple) && (matrix.llvm_mode == 'Debug' || (matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF'))
|
|
shell: bash
|
|
run: |
|
|
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
|
echo "LLVM_PRUNED_MANIFEST=${MANIFEST}" >> "${GITHUB_ENV}"
|
|
python3 scripts/prune-llvm-bin.py \
|
|
--action discover \
|
|
--install-dir ".llvm/build-install/lib" \
|
|
--build-dir "build/${{ matrix.llvm_mode }}" \
|
|
--max-attempts 60 \
|
|
--sleep-seconds 60 \
|
|
--manifest "${MANIFEST}"
|
|
|
|
- name: Upload pruned-libs manifest
|
|
if: (!matrix.target_triple) && matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'OFF'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: llvm-pruned-libs-${{ matrix.os }}
|
|
path: ${{ env.LLVM_PRUNED_MANIFEST }}
|
|
if-no-files-found: error
|
|
compression-level: 0
|
|
|
|
- name: Apply pruned-libs manifest (RelWithDebInfo + LTO, native only)
|
|
if: (!matrix.target_triple) && matrix.llvm_mode == 'RelWithDebInfo' && matrix.lto == 'ON'
|
|
shell: bash
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
|
python3 scripts/prune-llvm-bin.py \
|
|
--action apply \
|
|
--manifest "${MANIFEST}" \
|
|
--install-dir ".llvm/build-install/lib" \
|
|
--build-dir "build/${{ matrix.llvm_mode }}" \
|
|
--gh-run-id "${{ github.run_id }}" \
|
|
--gh-artifact "llvm-pruned-libs-${{ matrix.os }}" \
|
|
--gh-download-dir "artifacts" \
|
|
--max-attempts 60 \
|
|
--sleep-seconds 60
|
|
|
|
# For cross-compiled LTO builds, apply the native prune manifest.
|
|
# The unused library set is arch-independent (same API surface).
|
|
- name: Apply pruned-libs manifest (cross-compile + LTO)
|
|
if: matrix.target_triple && matrix.lto == 'ON'
|
|
shell: bash
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
MANIFEST="pruned-libs-${{ matrix.os }}.json"
|
|
python3 scripts/prune-llvm-bin.py \
|
|
--action apply \
|
|
--manifest "${MANIFEST}" \
|
|
--install-dir ".llvm/build-install/lib" \
|
|
--build-dir "build/${{ matrix.llvm_mode }}" \
|
|
--gh-run-id "${{ github.run_id }}" \
|
|
--gh-artifact "llvm-pruned-libs-${{ matrix.os }}" \
|
|
--gh-download-dir "artifacts" \
|
|
--max-attempts 60 \
|
|
--sleep-seconds 60
|
|
|
|
- name: Package LLVM install directory
|
|
shell: bash
|
|
run: |
|
|
MODE_TAG="releasedbg"
|
|
if [[ "${{ matrix.llvm_mode }}" == "Debug" ]]; then
|
|
MODE_TAG="debug"
|
|
fi
|
|
|
|
# Determine arch/platform/toolchain from target triple or runner OS
|
|
if [[ -n "${{ matrix.target_triple }}" ]]; then
|
|
case "${{ matrix.target_triple }}" in
|
|
x86_64-apple-darwin)
|
|
ARCH="x64"; PLATFORM="macos"; TOOLCHAIN="clang" ;;
|
|
aarch64-linux-gnu)
|
|
ARCH="aarch64"; PLATFORM="linux"; TOOLCHAIN="gnu" ;;
|
|
aarch64-pc-windows-msvc)
|
|
ARCH="aarch64"; PLATFORM="windows"; TOOLCHAIN="msvc" ;;
|
|
esac
|
|
else
|
|
ARCH="x64"
|
|
PLATFORM="linux"
|
|
TOOLCHAIN="gnu"
|
|
if [[ "${{ matrix.os }}" == windows-* ]]; then
|
|
PLATFORM="windows"
|
|
TOOLCHAIN="msvc"
|
|
elif [[ "${{ matrix.os }}" == macos-* ]]; then
|
|
ARCH="arm64"
|
|
PLATFORM="macos"
|
|
TOOLCHAIN="clang"
|
|
fi
|
|
fi
|
|
|
|
SUFFIX=""
|
|
if [[ "${{ matrix.lto }}" == "ON" ]]; then
|
|
SUFFIX="-lto"
|
|
fi
|
|
if [[ "${{ matrix.llvm_mode }}" == "Debug" && "${{ matrix.os }}" != windows-* ]]; then
|
|
SUFFIX="${SUFFIX}-asan"
|
|
fi
|
|
|
|
ARCHIVE="${ARCH}-${PLATFORM}-${TOOLCHAIN}-${MODE_TAG}${SUFFIX}.tar.xz"
|
|
|
|
set -eo pipefail
|
|
tar -C .llvm -cf - build-install | xz -T0 -9 -c > "${ARCHIVE}"
|
|
echo "LLVM_INSTALL_ARCHIVE=${ARCHIVE}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Upload LLVM install artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: ${{ env.LLVM_INSTALL_ARCHIVE }}
|
|
path: ${{ env.LLVM_INSTALL_ARCHIVE }}
|
|
if-no-files-found: error
|
|
|
|
test-cross:
|
|
needs: build
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- os: macos-15-intel
|
|
llvm_mode: RelWithDebInfo
|
|
target_triple: x86_64-apple-darwin
|
|
- os: ubuntu-24.04-arm
|
|
llvm_mode: RelWithDebInfo
|
|
target_triple: aarch64-linux-gnu
|
|
- os: windows-11-arm
|
|
llvm_mode: RelWithDebInfo
|
|
target_triple: aarch64-pc-windows-msvc
|
|
runs-on: ${{ matrix.os }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: ./.github/actions/setup-pixi
|
|
with:
|
|
environments: test-run
|
|
|
|
- name: Download cross-compiled clice
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: cross-clice-${{ matrix.target_triple }}-${{ matrix.llvm_mode }}
|
|
path: build/${{ matrix.llvm_mode }}/
|
|
|
|
- name: Make binaries executable
|
|
if: runner.os != 'Windows'
|
|
run: chmod +x build/${{ matrix.llvm_mode }}/bin/*
|
|
|
|
- name: Run tests
|
|
run: pixi run -e test-run test ${{ matrix.llvm_mode }}
|
|
|
|
upload:
|
|
needs: build
|
|
if: ${{ !cancelled() && inputs.llvm_version && !inputs.skip_upload }}
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download all build artifacts
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: scripts/download-llvm.sh "${{ github.run_id }}"
|
|
|
|
- name: Upload to clice-llvm
|
|
env:
|
|
GH_TOKEN: ${{ secrets.UPLOAD_LLVM }}
|
|
TARGET_REPO: clice-io/clice-llvm
|
|
run: python3 scripts/upload-llvm.py "${{ inputs.llvm_version }}" "${TARGET_REPO}" "${{ github.run_id }}"
|
|
|
|
- name: Save manifest for update-clice job
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: llvm-manifest-final
|
|
path: artifacts/llvm-manifest.json
|
|
if-no-files-found: error
|
|
compression-level: 0
|
|
|
|
update-clice:
|
|
needs: upload
|
|
if: ${{ !inputs.skip_pr }}
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download manifest
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: llvm-manifest-final
|
|
path: .
|
|
|
|
- name: Update manifest and version
|
|
run: |
|
|
python3 scripts/update-llvm-version.py \
|
|
--version "${{ inputs.llvm_version }}" \
|
|
--manifest-src llvm-manifest.json \
|
|
--manifest-dest config/llvm-manifest.json \
|
|
--package-cmake cmake/package.cmake
|
|
|
|
- name: Create or update PR
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
VERSION="${{ inputs.llvm_version }}"
|
|
BRANCH="chore/update-llvm-${VERSION}"
|
|
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
|
RELEASE_URL="https://github.com/clice-io/clice-llvm/releases/tag/${VERSION}"
|
|
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git checkout -b "${BRANCH}"
|
|
git add config/llvm-manifest.json cmake/package.cmake
|
|
git commit -m "chore: update LLVM to ${VERSION}"
|
|
git push --force-with-lease origin "${BRANCH}"
|
|
|
|
# Check if PR already exists for this branch
|
|
EXISTING_PR=$(gh pr list --head "${BRANCH}" --json number --jq '.[0].number // empty')
|
|
|
|
BODY="$(cat <<EOF
|
|
## Summary
|
|
- Update LLVM prebuilt binaries to version ${VERSION}
|
|
- Updated \`config/llvm-manifest.json\` with new SHA256 hashes
|
|
- Updated \`cmake/package.cmake\` version string
|
|
|
|
**Artifacts:** [clice-llvm release](${RELEASE_URL})
|
|
**Build:** [workflow run](${RUN_URL})
|
|
|
|
> Auto-generated by build-llvm workflow
|
|
EOF
|
|
)"
|
|
|
|
if [[ -n "${EXISTING_PR}" ]]; then
|
|
echo "Updating existing PR #${EXISTING_PR}"
|
|
gh pr edit "${EXISTING_PR}" --body "${BODY}"
|
|
else
|
|
gh pr create \
|
|
--title "chore: update LLVM to ${VERSION}" \
|
|
--body "${BODY}" \
|
|
--base main
|
|
fi
|