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 May 30, 2022
1 parent 1e0fb29 commit eaf1a25
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 28 deletions.
115 changes: 90 additions & 25 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
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 eaf1a25

Please sign in to comment.