Skip to content

Commit

Permalink
Initial import of clang-format build (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaun authored Dec 16, 2024
1 parent 3eb0597 commit e7f2fe6
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Build LLVM

on:
workflow_dispatch:
inputs:
version:
description: 'LLVM version to build'
default: '18.1.8'

permissions:
contents: write

env:
LLVM_VERSION: ${{ inputs.version }}
LLVM_TARGETS: 'clang-format'
LLVM_BINS: 'clang-format'
LLVM_LIBS: ''
ZIG_VERSION: '0.14.0-dev.1651+ffd071f55'
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create Github release
run: |
gh release create -R ${{ github.repository }} llvm-$LLVM_VERSION || true
env:
GITHUB_TOKEN: ${{ github.TOKEN }}
build:
needs: create-release
strategy:
matrix:
platform:
- os: darwin-arm64
runner: macos-latest
toolchain: default
BIN_SUFFIX: ''
SO_SUFFIX: '${{ inputs.version }}.dylib'
STATIC_LIB_SUFFIX: 'a'
LLVM_TARGETS_TO_BUILD: 'ARM'
- os: linux-amd64
runner: ubuntu-latest
toolchain: default
BIN_SUFFIX: ''
SO_SUFFIX: 'so.${{ inputs.version }}'
STATIC_LIB_SUFFIX: 'a'
LLVM_TARGETS_TO_BUILD: 'X86'
- os: linux-arm64
runner: ubuntu-latest
toolchain: zig-linux-arm64
BIN_SUFFIX: ''
SO_SUFFIX: 'so.${{ inputs.version }}'
STATIC_LIB_SUFFIX: 'a'
LLVM_TARGETS_TO_BUILD: 'ARM'
- os: windows-amd64
runner: windows-latest
toolchain: default
TAR_ARGS: '--exclude=*/clang/test/Driver/Inputs/* --exclude=*/libcxx/test/std/input.output/filesystems/Inputs/static_test_env/* --exclude=*/libclc/amdgcn-mesa3d'
BIN_SUFFIX: '.exe'
SO_SUFFIX: 'dll'
STATIC_LIB_SUFFIX: 'lib'
LLVM_TARGETS_TO_BUILD: 'X86'
runs-on: ${{ matrix.platform.runner }}
name: ${{ matrix.platform.os }}
steps:
- uses: actions/checkout@v4
- name: Setup for macOS
if: runner.os == 'macOS'
run: |
brew install cmake ninja
- name: Setup for Linux
if: runner.os == 'Linux'
run: |
sudo apt-get install -y cmake ninja-build
- name: Setup for Windows
if: runner.os == 'Windows'
run: |
choco install cmake ninja curl
- name: Get zig toolchain
if: startsWith(matrix.platform.toolchain, 'zig')
run: |
curl -L https://ziglang.org/builds/zig-linux-x86_64-$ZIG_VERSION.tar.xz -o zig.tar.xz
mkdir zig
tar -C zig --strip-components=1 -xJf zig.tar.xz
cd zig
pwd >> $GITHUB_PATH
- name: Get llvm
shell: bash
run: |
curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/llvm-project-$LLVM_VERSION.src.tar.xz -o llvm.tar.xz
mkdir llvm
tar -C llvm --strip-components=1 ${{ matrix.platform.TAR_ARGS }} -xJf llvm.tar.xz
- name: Generate build files
shell: bash
run: |
cd llvm
cmake -B build llvm -GNinja \
-DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/build/llvm/${{ matrix.platform.toolchain }}.cmake \
$(cat $GITHUB_WORKSPACE/build/llvm/common.args) \
-DLLVM_TARGETS_TO_BUILD=${{ matrix.platform.LLVM_TARGETS_TO_BUILD }}
- name: Build targets
shell: bash
run: |
cd llvm/build
ninja $LLVM_TARGETS
- name: Upload products
shell: bash
run: |
cd llvm/build/bin
for BIN in $LLVM_BINS; do
FILENAME=llvm-$LLVM_VERSION-${{ matrix.platform.os }}-$BIN${{ matrix.platform.BIN_SUFFIX }}
mv $BIN${{ matrix.platform.BIN_SUFFIX }} $FILENAME
gh release upload -R ${{ github.repository }} llvm-$LLVM_VERSION $FILENAME || true
done
cd ../lib
for LIB in $LLVM_LIBS; do
FILENAME=llvm-$LLVM_VERSION-${{ matrix.platform.os }}-$LIB.${{ matrix.platform.SO_SUFFIX }}
mv $LIB.${{ matrix.platform.SO_SUFFIX }} $FILENAME
gh release upload -R ${{ github.repository }} llvm-$LLVM_VERSION $FILENAME || true
done
env:
GITHUB_TOKEN: ${{ github.TOKEN }}


6 changes: 6 additions & 0 deletions build/llvm/common.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_PROJECTS=clang
-DBUILD_SHARED_LIBS=OFF
-DLLDB_ENABLE_PYTHON=0
-DLLDB_INCLUDE_TESTS=0

1 change: 1 addition & 0 deletions build/llvm/default.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# An empty CMake toolchain file to use when we're not cross-compiling
14 changes: 14 additions & 0 deletions build/llvm/zig-linux-arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tell CMake to cross compile
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# Set up Zig toolchain
set(CMAKE_C_COMPILER "${CMAKE_CURRENT_LIST_DIR}/../zig-toolchain/cc" -target aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER "${CMAKE_CURRENT_LIST_DIR}/../zig-toolchain/c++" -target aarch64-linux-gnu)
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/../zig-toolchain/ar")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/../zig-toolchain/ranlib")

# Tell llvm it is being built for another platform
set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-linux-gnu CACHE INTERNAL "" FORCE)

1 change: 1 addition & 0 deletions build/zig-toolchain/ar
1 change: 1 addition & 0 deletions build/zig-toolchain/c++
1 change: 1 addition & 0 deletions build/zig-toolchain/cc
1 change: 1 addition & 0 deletions build/zig-toolchain/ranlib
3 changes: 3 additions & 0 deletions build/zig-toolchain/zig-tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

zig $(basename $0) "$@"

0 comments on commit e7f2fe6

Please sign in to comment.