Skip to content

Commit

Permalink
Add Clang Toolchain to the CI
Browse files Browse the repository at this point in the history
This commit adds the clang toolchain to the CI. We turn the main jobs
into a test matrix that either runs with the clang, or gcc toolchain.

When using the gcc toolchain everything stays as-is. When using the
clang toolchain we use clang/clang++ as C/C++ compilers, respectively.
We also build `AnyBlob` using `-DANYBLOB_LIBCXX_COMPAT=1`, which ensures
that `libcxx` is used as a standard library.

In principle, the test matrix could be even bigger: we could build with
libcxx and gcc, and gnu c++ and clang. But we don't tests this for now.
  • Loading branch information
wagjamin authored and durner committed Nov 28, 2023
1 parent d4bb613 commit ab4be80
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 31 deletions.
35 changes: 35 additions & 0 deletions .github/actions/do-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Build AnyBlob"
description: "Build AnyBlob using either clang or gcc"
inputs:
clang-toolchain:
required: false
description: "Build with clang and use libcxx as the standard library"
default: false

runs:
using: "composite"
steps:
# CMake configuration option 1 - GCC toolchain
- name: Configure CMake
if: ${{ inputs.clang-toolchain == 'false' }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
shell: bash

# CMake configuration option 2 - Clang toolchain
- name: Configure CMake
if: ${{ inputs.clang-toolchain == 'true' }}
# Explicitly use clang-15. The runner comes with clang-13, 14, and 15.
# However, only clang-15 and up support `-Wno-unqualified-std-cast-call`.
run: |
sudo apt install libc++-15-dev libc++abi-15-dev
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_C_COMPILER=clang-15 \
-DCMAKE_CXX_COMPILER=clang++-15 \
-DANYBLOB_LIBCXX_COMPAT=1
shell: bash

# Build library and test binaries
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
shell: bash
11 changes: 11 additions & 0 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Install Dependencies"
description: "Installs dynamic libraries required by AnyBlob"

runs:
using: "composite"
steps:
# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
shell: bash

26 changes: 16 additions & 10 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ on:

env:
BUILD_TYPE: Debug
# False ASAN positives for alloc_dealloc_mismatch when running with clang
# https://github.com/llvm/llvm-project/issues/59432
ASAN_OPTIONS: alloc_dealloc_mismatch=0

jobs:
integration-test:
name: Integration Tests (Clang ${{ matrix.clang-toolchain }})
# Run on ubuntu
runs-on: ubuntu-latest
# Use both the GCC and Clang Toolchain
strategy:
matrix:
clang-toolchain: [true, false]

# Define the steps
steps:
Expand All @@ -39,17 +47,15 @@ jobs:
with:
submodules: true

# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
# Use action to install dependencies
- name: Install Dependencies
uses: ./.github/actions/install-deps

# CMake configuration
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# Build library and integration tester
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Use action to build
- name: Build AnyBlob
uses: ./.github/actions/do-build
with:
clang-toolchain: ${{ matrix.clang-toolchain }}

# Run the integration test
- name: Integration Test
Expand Down
30 changes: 18 additions & 12 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ on:

env:
BUILD_TYPE: Debug
# False ASAN positives for alloc_dealloc_mismatch when running with clang
# https://github.com/llvm/llvm-project/issues/59432
ASAN_OPTIONS: alloc_dealloc_mismatch=0

jobs:
uint-test:
unit-test:
name: Unit Tests (Clang ${{ matrix.clang-toolchain }})
# Run on ubuntu
runs-on: ubuntu-latest
# Use both the GCC and Clang Toolchain
strategy:
matrix:
clang-toolchain: [true, false]

# Define the steps
steps:
Expand All @@ -25,19 +33,17 @@ jobs:
with:
submodules: true

# Install dependencies
- name: Install dependencies
run: sudo apt update && sudo apt install liburing-dev openssl libssl-dev libjemalloc-dev lld
# Use action to install dependencies
- name: Install Dependencies
uses: ./.github/actions/install-deps

# CMake configuration
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

# Build library and tester
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
# Use action to build
- name: Build AnyBlob
uses: ./.github/actions/do-build
with:
clang-toolchain: ${{ matrix.clang-toolchain }}

# Run the unit test
# Run the unit tests
- name: Unit Test
working-directory: ${{github.workspace}}/build
run: ./tester
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ endif()

option(ANYBLOB_LIBCXX_COMPAT "Build AnyBlob in a way that's compatible with libcxx." OFF)
if (ANYBLOB_LIBCXX_COMPAT)
message("Building AnyBlob with libcxx")
# Update compiler flags to use libcxx as standard library.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -stdlib=libc++")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -stdlib=libc++")
Expand Down Expand Up @@ -123,7 +124,6 @@ add_library(AnyBlob STATIC ${SRC_CPP} ${INCLUDE_HPP})
target_link_libraries(AnyBlob PUBLIC OpenSSL::SSL Threads::Threads ${LIBURING_LIBRARY} jemalloc)
target_include_directories(AnyBlob PUBLIC ${PROJECT_SOURCE_DIR}/include)
if (ANYBLOB_LIBCXX_COMPAT)
# For libcxx compat some files like the throughput resolver cannot be compiled at the moment.
target_compile_definitions(AnyBlob PRIVATE ANYBLOB_LIBCXX_COMPAT)
endif()

Expand Down
4 changes: 0 additions & 4 deletions test/unit/network/io_uring_socket_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Sadly, the include order matters here. PerfEvent depends on sstream but
// does not include the header.
#include <sstream>

#include "catch2/single_include/catch2/catch.hpp"
#include "cloud/aws_resolver.hpp"
#include "network/io_uring_socket.hpp"
Expand Down
4 changes: 0 additions & 4 deletions test/unit/network/send_receiver_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Sadly, the include order matters here. PerfEvent depends on sstream but
// does not include the header.
#include <sstream>

#include "catch2/single_include/catch2/catch.hpp"
#include "network/original_message.hpp"
#include "network/tasked_send_receiver.hpp"
Expand Down

0 comments on commit ab4be80

Please sign in to comment.