From e7f2fe64a2c02e7db4168c6cb1754a42bbb5efc8 Mon Sep 17 00:00:00 2001 From: Nicholas Paun Date: Mon, 16 Dec 2024 07:51:23 -0800 Subject: [PATCH] Initial import of clang-format build (#2) --- .github/workflows/llvm.yml | 124 +++++++++++++++++++++++++++++++ build/llvm/common.args | 6 ++ build/llvm/default.cmake | 1 + build/llvm/zig-linux-arm64.cmake | 14 ++++ build/zig-toolchain/ar | 1 + build/zig-toolchain/c++ | 1 + build/zig-toolchain/cc | 1 + build/zig-toolchain/ranlib | 1 + build/zig-toolchain/zig-tool.sh | 3 + 9 files changed, 152 insertions(+) create mode 100644 .github/workflows/llvm.yml create mode 100644 build/llvm/common.args create mode 100644 build/llvm/default.cmake create mode 100644 build/llvm/zig-linux-arm64.cmake create mode 120000 build/zig-toolchain/ar create mode 120000 build/zig-toolchain/c++ create mode 120000 build/zig-toolchain/cc create mode 120000 build/zig-toolchain/ranlib create mode 100755 build/zig-toolchain/zig-tool.sh diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml new file mode 100644 index 0000000..39b04db --- /dev/null +++ b/.github/workflows/llvm.yml @@ -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 }} + + diff --git a/build/llvm/common.args b/build/llvm/common.args new file mode 100644 index 0000000..02056ec --- /dev/null +++ b/build/llvm/common.args @@ -0,0 +1,6 @@ +-DCMAKE_BUILD_TYPE=Release +-DLLVM_ENABLE_PROJECTS=clang +-DBUILD_SHARED_LIBS=OFF +-DLLDB_ENABLE_PYTHON=0 +-DLLDB_INCLUDE_TESTS=0 + diff --git a/build/llvm/default.cmake b/build/llvm/default.cmake new file mode 100644 index 0000000..cea81b6 --- /dev/null +++ b/build/llvm/default.cmake @@ -0,0 +1 @@ +# An empty CMake toolchain file to use when we're not cross-compiling diff --git a/build/llvm/zig-linux-arm64.cmake b/build/llvm/zig-linux-arm64.cmake new file mode 100644 index 0000000..422db5b --- /dev/null +++ b/build/llvm/zig-linux-arm64.cmake @@ -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) + diff --git a/build/zig-toolchain/ar b/build/zig-toolchain/ar new file mode 120000 index 0000000..82cf569 --- /dev/null +++ b/build/zig-toolchain/ar @@ -0,0 +1 @@ +zig-tool.sh \ No newline at end of file diff --git a/build/zig-toolchain/c++ b/build/zig-toolchain/c++ new file mode 120000 index 0000000..82cf569 --- /dev/null +++ b/build/zig-toolchain/c++ @@ -0,0 +1 @@ +zig-tool.sh \ No newline at end of file diff --git a/build/zig-toolchain/cc b/build/zig-toolchain/cc new file mode 120000 index 0000000..82cf569 --- /dev/null +++ b/build/zig-toolchain/cc @@ -0,0 +1 @@ +zig-tool.sh \ No newline at end of file diff --git a/build/zig-toolchain/ranlib b/build/zig-toolchain/ranlib new file mode 120000 index 0000000..82cf569 --- /dev/null +++ b/build/zig-toolchain/ranlib @@ -0,0 +1 @@ +zig-tool.sh \ No newline at end of file diff --git a/build/zig-toolchain/zig-tool.sh b/build/zig-toolchain/zig-tool.sh new file mode 100755 index 0000000..caedca2 --- /dev/null +++ b/build/zig-toolchain/zig-tool.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +zig $(basename $0) "$@"