Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce CMake toolchain #76

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
60c0bd5
add toolchain
wusatosi Nov 14, 2024
054c877
enable santizier
wusatosi Nov 14, 2024
8a59d2e
fix toolchain
wusatosi Nov 14, 2024
d65aeaf
update action script
wusatosi Nov 14, 2024
aba4789
use toolchain in CI
wusatosi Nov 14, 2024
730028a
Update toolchain.cmake
wusatosi Nov 14, 2024
f4932e9
run gcc-debug on macos
wusatosi Nov 15, 2024
cc37b1a
give up using toolchain
wusatosi Nov 15, 2024
14431a5
Merge branch 'main' into toolchain
wusatosi Nov 15, 2024
78e0a40
revert previous changes that are no longer needed
wusatosi Nov 15, 2024
6287403
readd -O3 flag to release build
wusatosi Nov 15, 2024
18f2be1
move sanitizer entry
wusatosi Nov 15, 2024
4f892cf
refactor apply_santizers
wusatosi Nov 15, 2024
87ac8ed
run profile test on windows
wusatosi Nov 15, 2024
219978e
Revert "run profile test on windows"
wusatosi Nov 15, 2024
93c0641
revert preset changes
wusatosi Nov 20, 2024
d648625
tweak for msvc
wusatosi Nov 26, 2024
ff6a3d9
warp apply_santizers.cmake in ifdef
wusatosi Nov 26, 2024
03a0ea0
extract sanitizer generation as function
wusatosi Nov 26, 2024
55c966c
update comment
wusatosi Nov 26, 2024
ac9408b
Merge branch 'main' into toolchain
wusatosi Dec 11, 2024
8057e45
use toolchain
wusatosi Dec 11, 2024
6822493
move generator out
wusatosi Dec 11, 2024
b99f9ad
remove generator at preset
wusatosi Dec 11, 2024
f309be8
remove cmake/apply_santizers.cmake
wusatosi Dec 11, 2024
b93b070
add msvc toolchain
wusatosi Dec 11, 2024
0c6f92b
ensure portable
wusatosi Dec 11, 2024
9127cc2
msvc does not support TSan
wusatosi Dec 12, 2024
ab682c6
Merge branch 'main' into toolchain
wusatosi Dec 13, 2024
3bba8f1
apply license
wusatosi Dec 15, 2024
a0f8cd2
adopt include guard
wusatosi Dec 16, 2024
f7e1c96
apply sanitizer to all targets
wusatosi Dec 20, 2024
f1f3f69
update all release targets
wusatosi Dec 20, 2024
66d8fd1
asan -> maxsan
wusatosi Dec 20, 2024
fa2f1b9
add documentation
wusatosi Dec 22, 2024
1dee249
remove unneeded include guard
wusatosi Dec 24, 2024
c0910c4
Merge branch 'main' into toolchain
wusatosi Dec 25, 2024
e97cec1
update use of toolchain for appleclang and msvc
wusatosi Dec 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 16 additions & 46 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,62 +49,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"
- description: "ASan"
args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'"
args: "-DBEMAN_BUILDSYS_SANITIZER=TSan"
- description: "MaxSan"
args: "-DBEMAN_BUILDSYS_SANITIZER=MaxSan"
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 }}
Expand All @@ -123,26 +106,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: |
Expand Down
21 changes: 8 additions & 13 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"name": "_debug-base",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"BEMAN_BUILDSYS_SANITIZER": "MaxSan"
}
},
{
Expand All @@ -32,8 +33,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined"
"CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake"
}
},
{
Expand All @@ -44,8 +44,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_CXX_FLAGS": "-O3"
"CMAKE_TOOLCHAIN_FILE": "cmake/gnu-toolchain.cmake"
}
},
{
Expand All @@ -56,8 +55,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
"CMAKE_TOOLCHAIN_FILE": "cmake/appleclang-toolchain.cmake"
}
},
{
Expand All @@ -68,8 +66,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS": "-O3"
"CMAKE_TOOLCHAIN_FILE": "cmake/appleclang-toolchain.cmake"
}
},
{
Expand All @@ -80,8 +77,7 @@
"_debug-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_CXX_FLAGS": "/EHsc /permissive- /fsanitize=address /Zi"
"CMAKE_TOOLCHAIN_FILE": "cmake/msvc-toolchain.cmake"
}
},
{
Expand All @@ -92,8 +88,7 @@
"_release-base"
],
"cacheVariables": {
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_CXX_FLAGS": "/EHsc /permissive- /O2"
"CMAKE_TOOLCHAIN_FILE": "cmake/msvc-toolchain.cmake"
}
}
],
Expand Down
37 changes: 37 additions & 0 deletions cmake/appleclang-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This toolchain file is not meant to be used directly,
# but to be invoked by CMake preset and GitHub CI.
#
# This toolchain file configures for apple clang family of compiler.
# Note this is different from LLVM toolchain.
#
# BEMAN_BUILDSYS_SANITIZER:
# This optional CMake parameter is not meant for public use and is subject to
# change.
# Possible values:
# - MaxSan: configures clang and clang++ to use all available non-conflicting
# sanitizers. Note that apple clang does not support leak sanitizer.
# - TSan: configures clang and clang++ to enable the use of thread sanitizer.

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
set(SANITIZER_FLAGS
"-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
set(SANITIZER_FLAGS "-fsanitize=thread")
endif()

set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")

set(RELEASE_FLAG "-O3 ${SANITIZER_FLAGS}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this variable should be prefixed with BEMAN_BUILDSYS_ to avoid conflicts with project variables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only meant to be a local variable and not to be exported. I will see if I can make it so that it's treated like a local variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FLAG -> FLAGS to match the existing CMake conventions.


set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")

set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
36 changes: 36 additions & 0 deletions cmake/gnu-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This toolchain file is not meant to be used directly,
# but to be invoked by CMake preset and GitHub CI.
#
# This toolchain file configures for GNU family of compiler.
#
# BEMAN_BUILDSYS_SANITIZER:
# This optional CMake parameter is not meant for public use and is subject to
# change.
# Possible values:
# - MaxSan: configures gcc and g++ to use all available non-conflicting
# sanitizers.
# - TSan: configures gcc and g++ to enable the use of thread sanitizer

set(CMAKE_C_COMPILER gcc)
wusatosi marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_CXX_COMPILER g++)

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
set(SANITIZER_FLAGS
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
set(SANITIZER_FLAGS "-fsanitize=thread")
endif()

set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")

set(RELEASE_FLAG "-O3 ${SANITIZER_FLAGS}")

set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")

set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
36 changes: 36 additions & 0 deletions cmake/llvm-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
camio marked this conversation as resolved.
Show resolved Hide resolved

# This toolchain file is not meant to be used directly,
# but to be invoked by CMake preset and GitHub CI.
#
# This toolchain file configures for LLVM family of compiler.
#
# BEMAN_BUILDSYS_SANITIZER:
# This optional CMake parameter is not meant for public use and is subject to
# change.
# Possible values:
# - MaxSan: configures clang and clang++ to use all available non-conflicting
# sanitizers.
# - TSan: configures clang and clang++ to enable the use of thread sanitizer.

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
set(SANITIZER_FLAGS
"-fsanitize=address -fsanitize=leak -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
)
elseif(BEMAN_BUILDSYS_SANITIZER STREQUAL "TSan")
set(SANITIZER_FLAGS "-fsanitize=thread")
endif()

set(CMAKE_C_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${SANITIZER_FLAGS}")

set(RELEASE_FLAG "-O3 ${SANITIZER_FLAGS}")

set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")

set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
34 changes: 34 additions & 0 deletions cmake/msvc-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This toolchain file is not meant to be used directly,
# but to be invoked by CMake preset and GitHub CI.
#
# This toolchain file configures for MSVC family of compiler.
#
# BEMAN_BUILDSYS_SANITIZER:
# This optional CMake parameter is not meant for public use and is subject to
# change.
# Possible values:
# - MaxSan: configures cl to use all available non-conflicting sanitizers.
#
# Note that in other toolchain files, TSan is also a possible value for
# BEMAN_BUILDSYS_SANITIZER, however, MSVC does not support thread sanitizer,
# thus this value is omitted.

set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)

if(BEMAN_BUILDSYS_SANITIZER STREQUAL "MaxSan")
set(SANITIZER_FLAGS "/fsanitize=address /Zi")
endif()

set(CMAKE_CXX_FLAGS_DEBUG_INIT "/EHsc /permissive- ${SANITIZER_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG_INIT "/EHsc /permissive- ${SANITIZER_FLAGS}")

set(RELEASE_FLAG "/EHsc /permissive- /O2 ${SANITIZER_FLAGS}")

set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${RELEASE_FLAG}")

set(CMAKE_C_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${RELEASE_FLAG}")
Loading