From eaf1a256bddbda8d605452967f2a1d4d685f9bc8 Mon Sep 17 00:00:00 2001 From: Nandor Licker Date: Sun, 29 May 2022 20:08:50 +0300 Subject: [PATCH] [CI] Build and cache seprate Clang and GCC builds of LLVM Code compiled with Clang cannot be linked with GCC due to incompatibilities related to lambda closure capture lists. This patch builds and caches LLVM with Clang to be used with the Clang Release build and with GCC to be used with the GCC Debug build of CIRCT. The ABI issue and a potential fix is being tracked here: https://github.com/itanium-cxx-abi/cxx-abi/issues/141 --- .github/workflows/buildAndTest.yml | 115 ++++++++++++++++++++++------- utils/build-llvm.sh | 8 +- 2 files changed, 95 insertions(+), 28 deletions(-) diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 0321ef13fdfd..0d86957e21a8 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -118,8 +118,8 @@ jobs: # Build the LLVM submodule then cache it. Do not rebuild if hit in the # cache. - build-llvm: - name: Build LLVM + build-llvm-clang: + name: Build LLVM (Clang) needs: sanity-check runs-on: ubuntu-latest container: @@ -143,25 +143,72 @@ jobs: run: echo "::set-output name=hash::$(md5sum $GITHUB_WORKSPACE/.github/workflows/buildAndTest.yml)" # Try to fetch LLVM from the cache. - - name: Cache LLVM - id: cache-llvm + - name: Cache LLVM (Clang) + id: cache-llvm-clang uses: actions/cache@v2 with: path: | - llvm/build - llvm/install - key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }} + llvm/build-clang + llvm/install-clang + key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}-clang # Build LLVM if we didn't hit in the cache. - name: Rebuild and Install LLVM - if: steps.cache-llvm.outputs.cache-hit != 'true' - run: utils/build-llvm.sh + if: steps.cache-llvm-clang.outputs.cache-hit != 'true' + run: utils/build-llvm.sh build-clang install-clang Release clang clang++ # Installing the results into the cache is an action which is automatically # added by the cache action above. - # --- end of build-llvm job. + # --- end of build-llvm-clang job. + + # Build the LLVM submodule then cache it. Do not rebuild if hit in the + # cache. + build-llvm-gcc: + name: Build LLVM (GCC) + needs: sanity-check + runs-on: ubuntu-latest + container: + image: ghcr.io/circt/images/circt-ci-build:20220216182244 + steps: + # Clone the CIRCT repo and its submodules. Do shallow clone to save clone + # time. + - name: Get CIRCT + uses: actions/checkout@v2 + with: + fetch-depth: 2 + submodules: "true" + + # Extract the LLVM submodule hash for use in the cache key. + - name: Get LLVM Hash + id: get-llvm-hash + run: echo "::set-output name=hash::$(git rev-parse @:./llvm)" + + - name: Get workflow spec hash + id: get-workflow-hash + run: echo "::set-output name=hash::$(md5sum $GITHUB_WORKSPACE/.github/workflows/buildAndTest.yml)" + + # Try to fetch LLVM from the cache. + - name: Cache LLVM (GCC) + id: cache-llvm-gcc + uses: actions/cache@v2 + with: + path: | + llvm/build-gcc + llvm/install-gcc + key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}-gcc + + # Build LLVM if we didn't hit in the cache. + - name: Rebuild and Install LLVM + if: steps.cache-llvm-gcc.outputs.cache-hit != 'true' + run: utils/build-llvm.sh build-gcc install-gcc Release gcc g++ + + + # Installing the results into the cache is an action which is automatically + # added by the cache action above. + + # --- end of build-llvm-clang job. # Configure CIRCT using LLVM's build system ("Unified" build). We do not actually build this configuration since it isn't as easy to cache LLVM artifacts in this mode. configure-circt-unified: @@ -194,7 +241,7 @@ jobs: # Build CIRCT and run its tests. build-circt: name: Build and Test - needs: build-llvm + needs: [build-llvm-clang, build-llvm-gcc] runs-on: ubuntu-latest container: image: ghcr.io/circt/images/circt-ci-build:20220216182244 @@ -224,21 +271,38 @@ jobs: run: echo "::set-output name=hash::$(md5sum $GITHUB_WORKSPACE/.github/workflows/buildAndTest.yml)" # Try to fetch LLVM from the cache. - - name: Cache LLVM - id: cache-llvm + - name: Cache LLVM (Clang) + id: cache-llvm-clang uses: actions/cache@v2 with: path: | - llvm/build - llvm/install - key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }} + llvm/build-clang + llvm/install-clang + key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}-clang # Build LLVM if we didn't hit in the cache. Even though we build it in # the previous job, there is a low chance that it'll have been evicted by # the time we get here. - - name: Rebuild and Install LLVM - if: steps.cache-llvm.outputs.cache-hit != 'true' - run: utils/build-llvm.sh + - name: Rebuild and Install LLVM (Clang) + if: steps.cache-llvm-clang.outputs.cache-hit != 'true' + run: utils/build-llvm.sh build-clang install-clang Release clang clang++ + + # Try to fetch LLVM from the cache. + - name: Cache LLVM (GCC) + id: cache-llvm-gcc + uses: actions/cache@v2 + with: + path: | + llvm/build-gcc + llvm/install-gcc + key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}-gcc + + # Build LLVM if we didn't hit in the cache. Even though we build it in + # the previous job, there is a low chance that it'll have been evicted by + # the time we get here. + - name: Rebuild and Install LLVM (GCC) + if: steps.cache-llvm-gcc.outputs.cache-hit != 'true' + run: utils/build-llvm.sh build-gcc install-gcc Release gcc g++ # -------- # Build and test CIRCT in both debug and release mode. @@ -253,16 +317,17 @@ jobs: run: | mkdir build_clang cd build_clang + ls ../llvm/install-clang/lib/cmake/mlir cmake .. \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=OFF \ - -DMLIR_DIR=../llvm/install/lib/cmake/mlir/ \ - -DLLVM_DIR=../llvm/install/lib/cmake/llvm/ \ + -DMLIR_DIR=`pwd`/../llvm/install-clang/lib/cmake/mlir \ + -DLLVM_DIR=`pwd`/../llvm/install-clang/lib/cmake/llvm \ -DLLVM_USE_LINKER=lld \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ - -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit \ + -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build-clang/bin/llvm-lit \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON make check-circt -j$(nproc) make circt-doc @@ -275,12 +340,12 @@ jobs: cmake .. \ -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_ASSERTIONS=ON \ - -DMLIR_DIR=../llvm/install/lib/cmake/mlir/ \ - -DLLVM_DIR=../llvm/install/lib/cmake/llvm/ \ + -DMLIR_DIR=`pwd`/../llvm/install-gcc/lib/cmake/mlir/ \ + -DLLVM_DIR=`pwd`/../llvm/install-gcc/lib/cmake/llvm/ \ -DLLVM_USE_LINKER=lld \ -DCMAKE_C_COMPILER=gcc \ -DCMAKE_CXX_COMPILER=g++ \ - -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build/bin/llvm-lit + -DLLVM_EXTERNAL_LIT=`pwd`/../llvm/build-gcc/bin/llvm-lit make check-circt -j$(nproc) make circt-doc diff --git a/utils/build-llvm.sh b/utils/build-llvm.sh index 2b959b477b63..2ce706845684 100755 --- a/utils/build-llvm.sh +++ b/utils/build-llvm.sh @@ -15,7 +15,9 @@ BUILD_DIR=${1:-"build"} INSTALL_DIR=${2:-"install"} BUILD_TYPE=${3:-"Release"} -EXTRA_ARGS=${@:4} +CC=${4:-"clang"} +CXX=${5:-"clang++"} +EXTRA_ARGS=${@:6} mkdir -p llvm/$BUILD_DIR mkdir -p llvm/$INSTALL_DIR @@ -23,8 +25,8 @@ cd llvm/$BUILD_DIR cmake ../llvm \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DCMAKE_C_COMPILER=clang \ - -DCMAKE_CXX_COMPILER=clang++ \ + -DCMAKE_C_COMPILER=$CC \ + -DCMAKE_CXX_COMPILER=$CXX \ -DCMAKE_INSTALL_PREFIX=../$INSTALL_DIR \ -DLLVM_BUILD_EXAMPLES=OFF \ -DLLVM_ENABLE_ASSERTIONS=ON \