Skip to content

Commit

Permalink
[CI] Build and cache seprate Clang and GCC builds of LLVM
Browse files Browse the repository at this point in the history
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:
itanium-cxx-abi/cxx-abi#141
  • Loading branch information
nandor committed Jun 1, 2022
1 parent 1e0fb29 commit 332c8ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
60 changes: 42 additions & 18 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/circt/images/circt-ci-build:20220216182244
strategy:
matrix:
compiler:
- cc: clang
cxx: clang++
- cc: gcc
cxx: g++
steps:
# Clone the CIRCT repo and its submodules. Do shallow clone to save clone
# time.
Expand All @@ -140,22 +147,22 @@ jobs:

- name: Get workflow spec hash
id: get-workflow-hash
run: echo "::set-output name=hash::$(md5sum $GITHUB_WORKSPACE/.github/workflows/buildAndTest.yml)"
run: echo "::set-output name=hash::$(md5sum $GITHUB_WORKSPACE/.github/workflows/buildAndTest.yml | awk '{print $1}')"

# Try to fetch LLVM from the cache.
- name: Cache LLVM
- name: Cache LLVM (${{ matrix.compiler.cc }})
id: cache-llvm
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 }}
key: ${{ runner.os }}-llvm-${{ steps.get-llvm-hash.outputs.hash }}-${{ steps.get-workflow-hash.outputs.hash }}-${{ matrix.compiler.cc }}-${{ matrix.compiler.cxx }}

# 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
run: utils/build-llvm.sh build install Release ${{ matrix.compiler.cc }} ${{ matrix.compiler.cxx }}


# Installing the results into the cache is an action which is automatically
Expand Down Expand Up @@ -224,21 +231,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.
Expand All @@ -257,12 +281,12 @@ jobs:
-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
Expand All @@ -275,12 +299,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
Expand Down
8 changes: 5 additions & 3 deletions utils/build-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
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
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 \
Expand Down

0 comments on commit 332c8ea

Please sign in to comment.