diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 1294167..e42b53d 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -32,62 +32,45 @@ jobs: fail-fast: false matrix: platform: - - description: "Ubuntu GCC" - cpp: g++ - c: gcc + - description: "Ubuntu GNU" os: ubuntu-latest - - description: "Ubuntu Clang" - cpp: clang++ - c: clang + toolchain: "cmake/gnu-toolchain.cmake" + - description: "Ubuntu LLVM" os: ubuntu-latest + toolchain: "cmake/llvm-toolchain.cmake" + - description: "Windows MSVC" + os: windows-latest + toolchain: "cmake/msvc-toolchain.cmake" cpp_version: [17, 20, 23, 26] cmake_args: - description: "Default" - args: "" - description: "TSan" - args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" + args: "-DBEMAN_BUILDSYS_SANITIZER=TSan" - description: "ASan" - args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" + args: "-DBEMAN_BUILDSYS_SANITIZER=ASan" include: - platform: description: "Ubuntu GCC" - cpp: g++ - c: gcc os: ubuntu-latest + toolchain: "cmake/gnu-toolchain.cmake" cpp_version: 17 cmake_args: description: "Werror" args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'" - platform: description: "Ubuntu GCC" - cpp: g++ - c: gcc os: ubuntu-latest + toolchain: "cmake/gnu-toolchain.cmake" cpp_version: 17 cmake_args: description: "Dynamic" args: "-DBUILD_SHARED_LIBS=on" + exclude: + # MSVC does not support thread sanitizer - platform: description: "Windows MSVC" - cpp: cl - c: cl - os: windows-latest - cpp_version: 17 - cmake_args: - description: "Default" - args: "" - - platform: - description: "Windows MSVC" - cpp: cl - c: cl - os: windows-latest - cpp_version: 17 cmake_args: - description: "ASan" - # Debug infomation needed to avoid cl: C5072 - # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-c5072?view=msvc-170 - args: "-DCMAKE_CXX_FLAGS='/fsanitize=address /Zi'" - + description: "TSan" name: "Unit: ${{ matrix.platform.description }} ${{ matrix.cpp_version }} ${{ matrix.cmake_args.description }}" runs-on: ${{ matrix.platform.os }} @@ -106,26 +89,13 @@ jobs: - name: Print installed softwares shell: bash run: | - echo "Compiler:" - - # cl does not have a --version option - if [ "${{ matrix.platform.cpp }}" != "cl" ]; then - ${{ matrix.platform.cpp }} --version - ${{ matrix.platform.c }} --version - else - ${{ matrix.platform.cpp }} - ${{ matrix.platform.c }} - fi - echo "Build system:" cmake --version ninja --version - name: Configure CMake run: | - cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }} + cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} -DCMAKE_TOOLCHAIN_FILE="${{ matrix.platform.toolchain }}" ${{ matrix.cmake_args.args }} env: - CC: ${{ matrix.platform.c }} - CXX: ${{ matrix.platform.cpp }} CMAKE_GENERATOR: "Ninja Multi-Config" - name: Build Release run: | diff --git a/CMakePresets.json b/CMakePresets.json index 0b645f2..402261a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,15 +15,14 @@ "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined" + "BEMAN_BUILDSYS_SANITIZER": "ASan" } }, { "name": "_release-base", "hidden": true, "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "CMAKE_CXX_FLAGS": "-O3" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { @@ -34,7 +33,7 @@ "_debug-base" ], "cacheVariables": { - "CMAKE_CXX_COMPILER": "g++" + "CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake" } }, { @@ -45,7 +44,7 @@ "_release-base" ], "cacheVariables": { - "CMAKE_CXX_COMPILER": "g++" + "CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake" } } ], diff --git a/cmake/gnu-toolchain.cmake b/cmake/gnu-toolchain.cmake new file mode 100644 index 0000000..2b74d5c --- /dev/null +++ b/cmake/gnu-toolchain.cmake @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +include_guard(GLOBAL) + +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) + +if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan") + set(CMAKE_CXX_FLAGS_DEBUG_INIT + "-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined" + ) + set(CMAKE_C_FLAGS_DEBUG_INIT + "-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined" + ) +elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan") + set(CMAKE_CXX_FLAGS_DEBUG_INIT "-fsanitize=thread") + set(CMAKE_C_FLAGS_DEBUG_INIT "-fsanitize=thread") +endif() + +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O3") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O3") diff --git a/cmake/llvm-toolchain.cmake b/cmake/llvm-toolchain.cmake new file mode 100644 index 0000000..debacef --- /dev/null +++ b/cmake/llvm-toolchain.cmake @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +include_guard(GLOBAL) + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan") + set(CMAKE_CXX_FLAGS_DEBUG_INIT + "-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined" + ) + set(CMAKE_C_FLAGS_DEBUG_INIT + "-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined" + ) +elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan") + set(CMAKE_CXX_FLAGS_DEBUG_INIT "-fsanitize=thread") + set(CMAKE_C_FLAGS_DEBUG_INIT "-fsanitize=thread") +endif() + +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O3") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O3") diff --git a/cmake/msvc-toolchain.cmake b/cmake/msvc-toolchain.cmake new file mode 100644 index 0000000..0f40ba7 --- /dev/null +++ b/cmake/msvc-toolchain.cmake @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +include_guard(GLOBAL) + +set(CMAKE_C_COMPILER cl) +set(CMAKE_CXX_COMPILER cl) + +if(BEMAN_BUILDSYS_SANITIZER STREQUAL "ASan") + set(CMAKE_CXX_FLAGS_DEBUG_INIT "/fsanitize=address /Zi") + set(CMAKE_C_FLAGS_DEBUG_INIT "/fsanitize=address /Zi") +endif() + +set(CMAKE_CXX_FLAGS_DEBUG_INIT + "${CMAKE_CXX_FLAGS_DEBUG_INIT} /EHsc /permissive-" +) +set(CMAKE_C_FLAGS_DEBUG_INIT "${CMAKE_C_FLAGS_DEBUG_INIT} /EHsc /permissive-") + +set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/EHsc /permissive- /O2") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "/EHsc /permissive- /O2")