From 2c7008501a49a9eae783148ff957879e87053b0d Mon Sep 17 00:00:00 2001 From: Dominic Koepke Date: Sat, 5 Oct 2024 22:22:52 +0200 Subject: [PATCH] Overhaul ci workflow (#43) --- .github/workflows/build.yml | 449 +++++++++++++++++++++++------------- 1 file changed, 293 insertions(+), 156 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2745cb196..71a1e231b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,8 +6,185 @@ on: branches: [main, development] jobs: - build: + ############ + # + # Defines the compiler configurations for the other jobs. + # + ##### + define-config: + runs-on: ubuntu-latest + outputs: + config: ${{ steps.output-config.outputs.config }} + env: + config: | + [ + { + "prefix": "Linux", + "suffix": "/libc++", + "os": "ubuntu-latest", + "container": { + "image": "ghcr.io/dnkpp/clang:18" + }, + "compiler_name": "clang", + "compiler_version": 18, + "libcxx": true, + "asan": true + }, + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { + "image": "ghcr.io/dnkpp/clang:18" + }, + "compiler_name": "clang", + "compiler_version": 18, + "libcxx": false, + "asan": true + }, + { + "prefix": "Linux", + "suffix": "/libc++", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/clang:17" }, + "compiler_name": "clang", + "compiler_version": 17, + "libcxx": true, + "asan": true + }, + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/clang:17" }, + "compiler_name": "clang", + "compiler_version": 17, + "libcxx": false, + "asan": true + }, + { + "prefix": "Linux", + "suffix": "/libc++", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/clang:16" }, + "compiler_name": "clang", + "compiler_version": 16, + "libcxx": true, + "asan": true + }, + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/clang:16" }, + "compiler_name": "clang", + "compiler_version": 16, + "libcxx": false, + "asan": true + }, + + + + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/gcc:14" }, + "compiler_name": "gcc", + "compiler_version": 14, + "libcxx": false, + "asan": true + }, + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/gcc:13" }, + "compiler_name": "gcc", + "compiler_version": 13, + "libcxx": false, + "asan": true + }, + { + "prefix": "Linux", + "os": "ubuntu-latest", + "container": { "image": "ghcr.io/dnkpp/gcc:12" }, + "compiler_name": "gcc", + "compiler_version": 12, + "libcxx": false, + "asan": true + }, + + + + { + "prefix": "Windows 2022", + "os": "windows-2022", + "compiler_name": "msvc", + "compiler_version": "v143", + "cmake_generator": "Visual Studio 17 2022", + "libcxx": false, + "asan": false + }, + { + "prefix": "Windows 2022", + "os": "windows-2022", + "compiler_name": "msvc", + "compiler_version": "ClangCl", + "cmake_generator": "Visual Studio 17 2022", + "libcxx": false, + "asan": false + }, + + + + { + "prefix": "macOS", + "os": "macos-latest", + "compiler_name": "AppleClang", + "compiler_version": 18, + "ldflags_workaround": "-L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib -lunwind", + "asan": true + }, + { + "prefix": "macOS", + "os": "macos-latest", + "compiler_name": "AppleClang", + "compiler_version": 17, + "ldflags_workaround": "-L/opt/homebrew/opt/llvm@17/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm@17/lib/c++", + "asan": true + }, + { + "prefix": "macOS", + "os": "macos-latest", + "compiler_name": "AppleClang", + "compiler_version": 16, + "ldflags_workaround": "-L/opt/homebrew/opt/llvm@16/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm@16/lib/c++", + "asan": true + } + ] + + steps: + - name: Output configs + id: output-config + shell: bash + run: | + # seems to convert that to a single-line json and thus please the output step + # wrap in single '! + OUTPUT='${{ env.config }}' + echo "config=$(echo $OUTPUT)" >> "$GITHUB_OUTPUT" + + ############ + # + # Runs all general unit tests and examples, without any adapter tests. + # They are excluded, because the dependency fetching and building increased the build times quite heavily, + # which does not scale properly. + # + # Runs all tests on every machine with + # - debug and release + # - c++20 and c++23 + # - std- and fmt-formatting backend + # + ##### + run-unit-tests: + needs: define-config name: | + [UT] ${{ matrix.config.prefix }} ${{ matrix.config.compiler_name }}-${{ matrix.config.compiler_version }} ${{ matrix.config.suffix }} @@ -21,160 +198,20 @@ jobs: build_mode: [Debug, Release] cxx_standard: [20, 23] format_backend: [std, fmt] - config: - #clang-18 - - { - prefix: "Linux", - suffix: "/libc++", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:18" }, - compiler_name: "clang", - compiler_version: 18, - libcxx: true, - asan: true - } - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:18" }, - compiler_name: "clang", - compiler_version: 18, - libcxx: false, - asan: true - } - #clang-17 - - { - prefix: "Linux", - suffix: "/libc++", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:17" }, - compiler_name: "clang", - compiler_version: 17, - libcxx: true, - asan: true - } - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:17" }, - compiler_name: "clang", - compiler_version: 17, - libcxx: false, - asan: true - } - #clang-16 - - { - prefix: "Linux", - suffix: "/libc++", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:16" }, - compiler_name: "clang", - compiler_version: 16, - libcxx: true, - asan: true - } - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/clang:16" }, - compiler_name: "clang", - compiler_version: 16, - libcxx: false, - asan: true - } - #gcc-14 - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/gcc:14" }, - compiler_name: "gcc", - compiler_version: 14, - libcxx: false, - asan: true - } - #gcc-13 - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/gcc:13" }, - compiler_name: "gcc", - compiler_version: 13, - libcxx: false, - asan: true - } - #gcc-12 - - { - prefix: "Linux", - os: ubuntu-latest, - container: { image: "ghcr.io/dnkpp/gcc:12" }, - compiler_name: "gcc", - compiler_version: 12, - libcxx: false, - asan: true - } - # msvc v143 - - { - prefix: "Windows 2022", - os: windows-2022, - compiler_name: "msvc", - compiler_version: v143, - cmake_generator: Visual Studio 17 2022, - libcxx: false, - asan: false - } - # msvc ClangCl - - { - prefix: "Windows 2022", - os: windows-2022, - compiler_name: "msvc", - compiler_version: ClangCl, - cmake_generator: Visual Studio 17 2022, - libcxx: false, - asan: false - } - - # AppleClang - # The ldflags_workaround are taken from the suggestions, when installing via brew - - { - prefix: "macOS", - os: macos-latest, - compiler_name: "AppleClang", - compiler_version: 18, - ldflags_workaround: -L/opt/homebrew/opt/llvm/lib/c++ -L/opt/homebrew/opt/llvm/lib -lunwind, - asan: true - } - - { - prefix: "macOS", - os: macos-latest, - compiler_name: "AppleClang", - compiler_version: 17, - ldflags_workaround: -L/opt/homebrew/opt/llvm@17/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm@17/lib/c++, - asan: true - } - - { - prefix: "macOS", - os: macos-latest, - compiler_name: "AppleClang", - compiler_version: 16, - ldflags_workaround: -L/opt/homebrew/opt/llvm@16/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm@16/lib/c++, - asan: true - } + config: ${{ fromJSON(needs.define-config.outputs.config) }} exclude: - # both compilers do not support std's format header - - format_backend: std + # all listed compilers do not support std's format header + - format_backend: "std" config: compiler_name: "clang" compiler_version: 16 - - format_backend: std + - format_backend: "std" config: compiler_name: "gcc" compiler_version: 12 - - # This compiler does work, but fails compiling something from boost::filesystem, which is indirectly required - # by the BoostAdapter-Test. - # Maybe, we can find a workaround for this in the future. - - config: + - format_backend: "std" + config: compiler_name: "AppleClang" compiler_version: 16 @@ -220,7 +257,7 @@ jobs: run: | echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DSANITIZE_ADDRESS=YES -DSANITIZE_UNDEFINED=YES)" >> $GITHUB_ENV - - name: Set fmt as formatting backend + - name: Setup fmt as formatting backend if: startsWith(matrix.format_backend, 'fmt') shell: bash run: | @@ -242,31 +279,131 @@ jobs: -B build \ -D CMAKE_VERBOSE_MAKEFILE=yes \ -D MIMICPP_FORCED_CXX_STANDARD="${{ matrix.cxx_standard }}" \ - -D MIMICPP_ENABLE_ADAPTER_TESTS=YES \ - -D MIMICPP_CONFIG_EXPERIMENTAL_CATCH2_MATCHER_INTEGRATION=YES \ ${{ env.CMAKE_CONFIG_EXTRA }} - name: Build shell: bash run: | cmake --build build \ - -j4 \ + -j5 \ ${{ env.CMAKE_BUILD_EXTRA }} - name: Run tests shell: bash env: CTEST_OUTPUT_ON_FAILURE: 1 - run: ctest --test-dir build/test/unit-tests -C ${{ matrix.build_mode }} -j4 + run: | + ctest --test-dir build/test/unit-tests \ + -C ${{ matrix.build_mode }} \ + -j5 - - name: Run adapter tests + - name: Run examples shell: bash env: CTEST_OUTPUT_ON_FAILURE: 1 - run: ctest --test-dir build/test/adapter-tests -C ${{ matrix.build_mode }} -j4 + run: | + ctest --test-dir build/examples \ + -C ${{ matrix.build_mode }} \ + -j5 - - name: Run examples + + ############ + # + # Runs the adapter test on every machine. + # + ##### + run-adapter-tests: + needs: define-config + name: | + [AT] + ${{ matrix.config.prefix }} + ${{ matrix.config.compiler_name }}-${{ matrix.config.compiler_version }} + ${{ matrix.config.suffix }} + (C++${{ matrix.cxx_standard }}, ${{ matrix.build_mode }}) + runs-on: ${{ matrix.config.os }} + container: ${{ matrix.config.container }} + + strategy: + fail-fast: false + matrix: + build_mode: [Debug, Release] + cxx_standard: [20, 23] + config: ${{ fromJSON(needs.define-config.outputs.config) }} + + exclude: + # This compiler does work, but fails compiling something from boost::filesystem, which is indirectly required + # by the BoostAdapter-Test. + # Maybe, we can find a workaround for this in the future. + - config: + compiler_name: "AppleClang" + compiler_version: 16 + + steps: + - uses: actions/checkout@v4 + + - name: Setup macOS + if: startsWith(matrix.config.os, 'macOS') + shell: bash + run: | + LLVM_NAME=llvm@${{ matrix.config.compiler_version }} + env brew install ninja $LLVM_NAME + LLVM_PATH="$(brew --prefix $LLVM_NAME)" + echo "CC=$(echo $LLVM_PATH/bin/clang)" >> $GITHUB_ENV + echo "CXX=$(echo $LLVM_PATH/bin/clang++)" >> $GITHUB_ENV + echo "LDFLAGS=$(echo $LDFLAGS ${{ matrix.config.ldflags_workaround }})" >> $GITHUB_ENV + + echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DCMAKE_BUILD_TYPE=${{ matrix.build_mode }})" >> $GITHUB_ENV + + - name: Clang libc++ setup + if: ${{ matrix.config.compiler_name == 'clang' && matrix.config.libcxx == true }} + shell: bash + run: | + echo "CXXFLAGS=$(echo $CXXFLAGS -stdlib=libc++)" >> $GITHUB_ENV + echo "LDFLAGS=$(echo $LDFLAGS -lc++abi)" >> $GITHUB_ENV + + - name: Setup linux + if: ${{ matrix.config.prefix == 'Linux' }} + shell: bash + run: | + echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DCMAKE_BUILD_TYPE=${{ matrix.build_mode }})" >> $GITHUB_ENV + + - name: Setup msvc + if: ${{ matrix.config.compiler_name == 'msvc' }} + shell: bash + run: | + echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -G\"${{ matrix.config.cmake_generator }}\" -T\"${{ matrix.config.compiler_version }}\" -Ax64)" >> $GITHUB_ENV + echo "CMAKE_BUILD_EXTRA=$(echo $CMAKE_BUILD_EXTRA --config ${{ matrix.build_mode }})" >> $GITHUB_ENV + + # This is enabled by default, because that's the only formatting-backend which is supported by every compiler. + - name: Setup fmt as formatting backend + shell: bash + run: | + echo "CMAKE_CONFIG_EXTRA=$(echo $CMAKE_CONFIG_EXTRA -DMIMICPP_CONFIG_USE_FMT=YES)" >> $GITHUB_ENV + + - name: Configure + shell: bash + run: | + cmake \ + -S . \ + -B build \ + -D CMAKE_VERBOSE_MAKEFILE=yes \ + -D MIMICPP_FORCED_CXX_STANDARD="${{ matrix.cxx_standard }}" \ + -D MIMICPP_ENABLE_ADAPTER_TESTS=YES \ + -D MIMICPP_CONFIG_EXPERIMENTAL_CATCH2_MATCHER_INTEGRATION=YES \ + ${{ env.CMAKE_CONFIG_EXTRA }} + + - name: Build + shell: bash + run: | + cmake --build build \ + -j5 \ + ${{ env.CMAKE_BUILD_EXTRA }} + + - name: Run adapter tests shell: bash env: CTEST_OUTPUT_ON_FAILURE: 1 - run: ctest --test-dir build/examples -C ${{ matrix.build_mode }} -j4 + run: | + ctest --test-dir build/test/adapter-tests \ + -C ${{ matrix.build_mode }} \ + -j5