From 4de7a86b1f838e2435321cfc547667b77b12c036 Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Tue, 3 Sep 2024 15:11:15 +0100 Subject: [PATCH 1/2] github workflow cross compiling for aarch64 Add support for building aarch64 llvm cache (currently only llvm 18,RelAssert) on github workflows. --- .github/actions/setup_ubuntu_build/action.yml | 6 +- .github/workflows/create_llvm.yml | 69 +++++++++++++++++-- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/.github/actions/setup_ubuntu_build/action.yml b/.github/actions/setup_ubuntu_build/action.yml index dc3d90a57..eebbdaa67 100644 --- a/.github/actions/setup_ubuntu_build/action.yml +++ b/.github/actions/setup_ubuntu_build/action.yml @@ -14,7 +14,9 @@ inputs: save: description: 'Save the build cache at the end - not for PR testing' default: false - + arch: + description: 'Architecture' + default: x86_64 runs: # We don't want a new docker just a list of steps, so mark as composite @@ -33,7 +35,7 @@ runs: uses: actions/cache/restore@v3 with: path: llvm_install/** - key: llvm-ubuntu-${{ inputs.ubuntu_version }}-v${{ inputs.llvm_version}}-${{ inputs.llvm_build_type }} + key: llvm-ubuntu-${{ inputs.ubuntu_version }}-${{ inputs.arch }}-v${{ inputs.llvm_version}}-${{ inputs.llvm_build_type }} fail-on-cache-miss: true # note the PR testing usage should set 'save' to false, to avoid PR testing creating new caches on a branch diff --git a/.github/workflows/create_llvm.yml b/.github/workflows/create_llvm.yml index a040fc3b5..98d3c75ea 100644 --- a/.github/workflows/create_llvm.yml +++ b/.github/workflows/create_llvm.yml @@ -6,6 +6,9 @@ on: - main paths: - '.github/workflows/create_llvm.yml' + pull_request: + paths: + - '.github/workflows/create_llvm.yml' workflow_dispatch: jobs: @@ -15,18 +18,33 @@ jobs: version: [17, 18] os: [ubuntu-22.04] build_type: [Release, RelAssert] + arch : [x86_64, aarch64] + exclude: + # For now just do latest llvm with aarch to reduce cache usage. + - arch: aarch64 + version: 17 + - arch: aarch64 + build_type: Release include: # We want to set flags related to particular matrix dimensions. To do this # we need to create default values first, and then against particular matrix # dimensions. # Note that we need to use RelAssert as the cache key matching can match Release against ReleaseAssert - os_flags: + - arch_flags: - build_type_flags: - - build_type: RelAssert - build_type_flags: -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON + - build_type_flags: -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON + build_type: RelAssert + - arch_flags: -DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/ock/platform/arm-linux/aarch64-toolchain.cmake" + -DLLVM_TARGET_ARCH=AArch64 + -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu + -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-unknown-linux-gnu + -DLLVM_TABLEGEN="$GITHUB_WORKSPACE/build_native/bin/llvm-tblgen" + -DCLANG_TABLEGEN="$GITHUB_WORKSPACE/build_native/bin/clang-tblgen" + arch: aarch64 - build_type: Release build_type_flags: -DCMAKE_BUILD_TYPE=Release - + runs-on: ${{ matrix.os }} steps: - name: Cache llvm @@ -35,23 +53,61 @@ jobs: with: path: llvm_install/** - key: llvm-${{ matrix.os }}-v${{ matrix.version }}-${{ matrix.build_type }} + key: llvm-${{ matrix.os }}-${{ matrix.arch }}-v${{ matrix.version }}-${{ matrix.build_type }} + + - name: show arch flags + if: steps.cache.outputs.cache-hit != 'true' + run: + echo ${{ matrix.arch_flags }} - - name: Checkout repo + - name: Checkout repo llvm if: steps.cache.outputs.cache-hit != 'true' uses: actions/checkout@v4 with: repository: llvm/llvm-project ref: release/${{matrix.version}}.x + - name: Checkout repo ock platform + if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch != 'x86_64' }} + uses: actions/checkout@v4 + with: + sparse-checkout: | + platform + path: ock + - name: Install Ninja if: steps.cache.outputs.cache-hit != 'true' uses: llvm/actions/install-ninja@main + - name: install aarch64 build tools + if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch == 'aarch64' }} + run: + sudo apt-get install --yes gcc-11-aarch64-linux-gnu g++-11-aarch64-linux-gnu + - name: Flags checker if: steps.cache.outputs.cache-hit != 'true' run: - echo Building on "${{ matrix.os }}" with os_flags "${{ matrix.os_flags}}" extra flags "${{ matrix.build_type_flags}}" and build_type "${{matrix.build_type}}" + echo Building on "${{ matrix.os }}" with os_flags "${{ matrix.os_flags}}" aarch "${{ matrix.arch }}"extra flags "${{ matrix.build_type_flags}}" and build_type "${{matrix.build_type}}" + + - name: cmake native for cross + if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch != 'x86_64' }} + run: + cmake llvm + -DLLVM_ENABLE_DIA_SDK=OFF + -DLLVM_ENABLE_ZLIB=FALSE + -DLLVM_ENABLE_ZSTD=FALSE + -DLLVM_ENABLE_Z3_SOLVER=FALSE + -DLLVM_ENABLE_PROJECTS="clang;lld" + -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;RISCV" + -Bbuild_native + -GNinja + ${{ matrix.build_type_flags }} + ${{ matrix.os_flags}} + + - name: build native for cross + if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch != 'x86_64' }} + run: + ninja -C build_native llvm-tblgen clang-tblgen llvm-config - name: Run cmake if: steps.cache.outputs.cache-hit != 'true' @@ -68,6 +124,7 @@ jobs: -GNinja ${{ matrix.build_type_flags }} ${{ matrix.os_flags}} + ${{ matrix.arch_flags}} - name: Run build on llvm if: steps.cache.outputs.cache-hit != 'true' From 8f40eff745ba748c441b3f730629ebd1d58d446c Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Thu, 12 Sep 2024 11:22:33 +0100 Subject: [PATCH 2/2] Updated after comments to simplify llvm cross build. --- .github/workflows/create_llvm.yml | 32 ++----------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/.github/workflows/create_llvm.yml b/.github/workflows/create_llvm.yml index 98d3c75ea..f53455336 100644 --- a/.github/workflows/create_llvm.yml +++ b/.github/workflows/create_llvm.yml @@ -36,11 +36,7 @@ jobs: - build_type_flags: -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON build_type: RelAssert - arch_flags: -DCMAKE_TOOLCHAIN_FILE="$GITHUB_WORKSPACE/ock/platform/arm-linux/aarch64-toolchain.cmake" - -DLLVM_TARGET_ARCH=AArch64 -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu - -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-unknown-linux-gnu - -DLLVM_TABLEGEN="$GITHUB_WORKSPACE/build_native/bin/llvm-tblgen" - -DCLANG_TABLEGEN="$GITHUB_WORKSPACE/build_native/bin/clang-tblgen" arch: aarch64 - build_type: Release build_type_flags: -DCMAKE_BUILD_TYPE=Release @@ -55,10 +51,6 @@ jobs: llvm_install/** key: llvm-${{ matrix.os }}-${{ matrix.arch }}-v${{ matrix.version }}-${{ matrix.build_type }} - - name: show arch flags - if: steps.cache.outputs.cache-hit != 'true' - run: - echo ${{ matrix.arch_flags }} - name: Checkout repo llvm if: steps.cache.outputs.cache-hit != 'true' @@ -82,32 +74,12 @@ jobs: - name: install aarch64 build tools if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch == 'aarch64' }} run: - sudo apt-get install --yes gcc-11-aarch64-linux-gnu g++-11-aarch64-linux-gnu + sudo apt-get install --yes g++-11-aarch64-linux-gnu - name: Flags checker if: steps.cache.outputs.cache-hit != 'true' run: - echo Building on "${{ matrix.os }}" with os_flags "${{ matrix.os_flags}}" aarch "${{ matrix.arch }}"extra flags "${{ matrix.build_type_flags}}" and build_type "${{matrix.build_type}}" - - - name: cmake native for cross - if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch != 'x86_64' }} - run: - cmake llvm - -DLLVM_ENABLE_DIA_SDK=OFF - -DLLVM_ENABLE_ZLIB=FALSE - -DLLVM_ENABLE_ZSTD=FALSE - -DLLVM_ENABLE_Z3_SOLVER=FALSE - -DLLVM_ENABLE_PROJECTS="clang;lld" - -DLLVM_TARGETS_TO_BUILD="X86;ARM;AArch64;RISCV" - -Bbuild_native - -GNinja - ${{ matrix.build_type_flags }} - ${{ matrix.os_flags}} - - - name: build native for cross - if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.arch != 'x86_64' }} - run: - ninja -C build_native llvm-tblgen clang-tblgen llvm-config + echo Building on "${{ matrix.os }}" with os_flags "${{ matrix.os_flags}}" arch "${{ matrix.arch }}"extra flags "${{ matrix.build_type_flags}}" and build_type "${{matrix.build_type}}" - name: Run cmake if: steps.cache.outputs.cache-hit != 'true'