Skip to content

Commit b8b689b

Browse files
authored
Try to optimize CI sanitizer checks (#80)
* Try to optimize CI sanitizer checks * Add package_project cmake moduels * Prevent to set sanitizer from Makefile * Disable msan for now * Build all presets on Windows too * cleanup
1 parent bc6a99a commit b8b689b

File tree

10 files changed

+119
-48
lines changed

10 files changed

+119
-48
lines changed

.github/workflows/linux.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
paths:
1010
- "include/**"
1111
- "src/**"
12-
- "test/**"
12+
- "tests/**"
13+
- "examples/**"
1314
- "cmake/**"
1415
- "Makefile"
1516
- "CMakePresets.json"
@@ -20,7 +21,8 @@ on:
2021
paths:
2122
- "include/**"
2223
- "src/**"
23-
- "test/**"
24+
- "tests/**"
25+
- "examples/**"
2426
- "cmake/**"
2527
- "Makefile"
2628
- "CMakePresets.json"
@@ -52,4 +54,5 @@ jobs:
5254
run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}
5355

5456
- name: Linux ${{ matrix.compiler }} sanitizer
57+
if: startsWith(matrix.preset, 'debug')
5558
run: CXX=${{ matrix.compiler }} make all

.github/workflows/macos.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
paths:
1010
- "include/**"
1111
- "src/**"
12-
- "test/**"
12+
- "tests/**"
13+
- "examples/**"
1314
- "cmake/**"
1415
- "Makefile"
1516
- "CMakePresets.json"
@@ -20,7 +21,8 @@ on:
2021
paths:
2122
- "include/**"
2223
- "src/**"
23-
- "test/**"
24+
- "tests/**"
25+
- "examples/**"
2426
- "cmake/**"
2527
- "Makefile"
2628
- "CMakePresets.json"
@@ -60,7 +62,7 @@ jobs:
6062
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}
6163

6264
- name: macos clang++-18 sanitizer
63-
if: startsWith(matrix.compiler, 'clang')
65+
if: startsWith(matrix.compiler, 'clang') && startsWith(matrix.preset, 'debug')
6466
run: CXX=$(brew --prefix llvm@18)/bin/clang++ make all
6567

6668
- name: macos g++ ${{ matrix.preset }}
@@ -69,5 +71,5 @@ jobs:
6971

7072
# TODO: fails with AppleClang 16.0.0 on CI!
7173
# - name: macos g++ sanitizer
72-
# if: startsWith(matrix.compiler, 'g++')
74+
# if: startsWith(matrix.compiler, 'g++') && startsWith(matrix.preset, 'debug')
7375
# run: CXX=${{ matrix.compiler }} make all

.github/workflows/windows.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99
paths:
1010
- "include/**"
1111
- "src/**"
12-
- "test/**"
12+
- "tests/**"
13+
- "examples/**"
1314
- "cmake/**"
1415
- "CMakePresets.json"
1516
- "CMakeLists.txt"
@@ -19,7 +20,8 @@ on:
1920
paths:
2021
- "include/**"
2122
- "src/**"
22-
- "test/**"
23+
- "tests/**"
24+
- "examples/**"
2325
- "cmake/**"
2426
- "CMakePresets.json"
2527
- "CMakeLists.txt"
@@ -32,8 +34,7 @@ jobs:
3234
fail-fast: false
3335

3436
matrix:
35-
# TODO: sanitizer: [debug, release]
36-
sanitizer: [release]
37+
preset: [debug, release]
3738
# TODO: compiler: [cl, clang-cl]
3839
compiler: [cl]
3940

@@ -48,18 +49,18 @@ jobs:
4849
# - name: build environment
4950
# run: pip install -r requirements.txt
5051

51-
- name: cmake workflow ${{ matrix.sanitizer }}
52+
- name: cmake workflow ${{ matrix.preset }}
5253
shell: bash
5354
run: |
5455
cmake --version
5556
ninja --version
56-
CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.sanitizer }}
57+
CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}
5758
5859
# - name: configure
59-
# run: CXX=${{ matrix.compiler }} cmake --preset ${{ matrix.sanitizer }}
60+
# run: CXX=${{ matrix.compiler }} cmake --preset ${{ matrix.preset }}
6061

6162
# - name: build
62-
# run: cmake --build --preset ${{ matrix.sanitizer }}
63+
# run: cmake --build --preset ${{ matrix.preset }}
6364

6465
# - name: ctest
65-
# run: ctest --preset ${{ matrix.sanitizer }}
66+
# run: ctest --preset ${{ matrix.preset }}

CMakeLists.txt

+54-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ cmake_minimum_required(VERSION 3.25...3.31)
77

88
project(beman_execution26 VERSION 0.0.1 LANGUAGES CXX)
99

10+
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
11+
message(FATAL_ERROR "In-source builds are not allowed!")
12+
endif()
13+
1014
set(TARGET_NAME execution26)
1115
set(TARGET_NAMESPACE beman) # FIXME: not used in install(EXPORT ...) CK?
1216
set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME})
@@ -15,13 +19,58 @@ set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY})
1519
set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config)
1620
set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets)
1721

18-
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
19-
message(FATAL_ERROR "In-source builds are not allowed!")
20-
endif()
21-
2222
include(GNUInstallDirs)
2323
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
2424

25+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
26+
include(FetchContent)
27+
28+
# Add project_options from https://github.com/aminya/project_options
29+
# Change the version in the following URL to update the package
30+
# (watch the releases of the repository for future updates)
31+
set(PROJECT_OPTIONS_VERSION "v0.41.0")
32+
FetchContent_Declare(
33+
_project_options URL https://github.com/aminya/project_options/archive/refs/tags/${PROJECT_OPTIONS_VERSION}.zip
34+
)
35+
FetchContent_MakeAvailable(_project_options)
36+
include(${_project_options_SOURCE_DIR}/Index.cmake)
37+
38+
# Initialize project_options variable related to this project
39+
# This overwrites `project_options` and sets `project_warnings`
40+
# uncomment to enable the options. Some of them accept one or more inputs:
41+
project_options(
42+
PREFIX
43+
${PROJECT_NAME}
44+
ENABLE_CACHE
45+
# NO! # ENABLE_CLANG_TIDY
46+
# NO! ENABLE_VS_ANALYSIS
47+
# ENABLE_INTERPROCEDURAL_OPTIMIZATION
48+
# ENABLE_NATIVE_OPTIMIZATION
49+
# ENABLE_DOXYGEN
50+
# ENABLE_COVERAGE
51+
ENABLE_SANITIZER_ADDRESS
52+
ENABLE_SANITIZER_UNDEFINED
53+
# TODO: ENABLE_SANITIZER_THREAD
54+
# FIXME: on Linux only with clang++? ENABLE_SANITIZER_MEMORY
55+
ENABLE_SANITIZER_POINTER_COMPARE
56+
ENABLE_SANITIZER_POINTER_SUBTRACT
57+
ENABLE_CONTROL_FLOW_PROTECTION
58+
ENABLE_STACK_PROTECTION
59+
ENABLE_OVERFLOW_PROTECTION
60+
# ENABLE_ELF_PROTECTION
61+
# ENABLE_RUNTIME_SYMBOLS_RESOLUTION
62+
# ENABLE_COMPILE_COMMANDS_SYMLINK
63+
# ENABLE_PCH
64+
# PCH_HEADERS
65+
# WARNINGS_AS_ERRORS
66+
# ENABLE_INCLUDE_WHAT_YOU_USE
67+
# ENABLE_GCC_ANALYZER
68+
# ENABLE_BUILD_WITH_TIME_TRACE
69+
# TODO: buggy! ENABLE_UNITY
70+
# LINKER "lld"
71+
)
72+
endif()
73+
2574
add_subdirectory(src/beman/execution26)
2675

2776
if(PROJECT_IS_TOP_LEVEL)
@@ -50,4 +99,5 @@ install(
5099
DESTINATION ${INSTALL_CONFIGDIR}
51100
)
52101

102+
set(CPACK_GENERATOR TGZ)
53103
include(CPack)

Makefile

+34-20
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
55
MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.
66

7-
SANITIZERS = release debug usan # TODO: lsan
8-
OS := $(shell /usr/bin/uname)
9-
ifeq ($(OS),Darwin)
10-
SANITIZERS += tsan
11-
endif
12-
ifeq ($(OS),Linux)
13-
SANITIZERS += asan # TODO: msan
14-
endif
15-
16-
.PHONY: default doc run update check ce todo distclean clean codespell clang-tidy build test all format $(SANITIZERS)
7+
SANITIZERS := run
8+
# SANITIZERS = usan # TODO: lsan
9+
# OS := $(shell /usr/bin/uname)
10+
# ifeq ($(OS),Darwin)
11+
# SANITIZERS += tsan # TODO: asan
12+
# endif
13+
# ifeq ($(OS),Linux)
14+
# SANITIZERS += asan # TODO: tsan msan
15+
# endif
16+
17+
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test install all format $(SANITIZERS)
1718

1819
SYSROOT ?=
1920
TOOLCHAIN ?=
@@ -27,34 +28,40 @@ ifeq ($(CXX_BASE),clang++)
2728
COMPILER=clang++
2829
endif
2930

30-
CXX_FLAGS = -g
31-
SANITIZER = release
31+
LDFLAGS ?=
32+
SAN_FLAGS ?=
33+
CXX_FLAGS ?= -g
34+
SANITIZER ?= default
3235
SOURCEDIR = $(CURDIR)
3336
BUILDROOT = build
3437
BUILD = $(BUILDROOT)/$(SANITIZER)
3538
EXAMPLE = beman.execution26.examples.stop_token
3639
CMAKE_CXX_COMPILER=$(COMPILER)
3740

3841
ifeq ($(SANITIZER),release)
39-
CXX_FLAGS = -O3 -Wpedantic -Wall -Wextra -Wshadow # TODO: -Werror
42+
CXX_FLAGS = -O3 -Wpedantic -Wall -Wextra -Wno-shadow -Werror
4043
endif
4144
ifeq ($(SANITIZER),debug)
4245
CXX_FLAGS = -g
4346
endif
4447
ifeq ($(SANITIZER),msan)
4548
SAN_FLAGS = -fsanitize=memory
49+
LDFLAGS = $(SAN_FLAGS)
4650
endif
4751
ifeq ($(SANITIZER),asan)
4852
SAN_FLAGS = -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize-address-use-after-scope
4953
endif
5054
ifeq ($(SANITIZER),usan)
5155
SAN_FLAGS = -fsanitize=undefined
56+
LDFLAGS = $(SAN_FLAGS)
5257
endif
5358
ifeq ($(SANITIZER),tsan)
5459
SAN_FLAGS = -fsanitize=thread
60+
LDFLAGS = $(SAN_FLAGS)
5561
endif
5662
ifeq ($(SANITIZER),lsan)
5763
SAN_FLAGS = -fsanitize=leak
64+
LDFLAGS = $(SAN_FLAGS)
5865
endif
5966

6067
default: test
@@ -67,20 +74,27 @@ run: test
6774
doc:
6875
doxygen docs/Doxyfile
6976

70-
release: test
71-
72-
$(SANITIZERS):
73-
$(MAKE) SANITIZER=$@
77+
# $(SANITIZERS):
78+
# $(MAKE) SANITIZER=$@
7479

7580
build:
76-
@mkdir -p $(BUILD)
77-
cd $(BUILD); CC=$(CXX) cmake -G Ninja $(SOURCEDIR) $(TOOLCHAIN) $(SYSROOT) -DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
81+
CC=$(CXX) cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
82+
-DCMAKE_CXX_COMPILER=$(CXX) # XXX -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
7883
cmake --build $(BUILD)
7984

85+
# NOTE: without install! CK
8086
test: build
81-
# cmake --workflow --preset $(SANITIZER)
8287
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure
8388

89+
install: test
90+
cmake --install $(BUILD) --prefix /opt/local
91+
92+
release:
93+
cmake --workflow --preset $@ --fresh
94+
95+
debug:
96+
cmake --workflow --preset $@ --fresh
97+
8498
ce:
8599
@mkdir -p $(BUILD)
86100
bin/mk-compiler-explorer.py $(BUILD)

cmake/CMakeDarwinPresets.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"name": "debug-base-Darwin",
99
"hidden": true,
1010
"cacheVariables": {
11-
"CMAKE_BUILD_TYPE": "Debug",
12-
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
11+
"CMAKE_BUILD_TYPE": "Debug"
1312
},
1413
"condition": {
1514
"type": "equals",
@@ -21,8 +20,7 @@
2120
"name": "release-base-Darwin",
2221
"hidden": true,
2322
"cacheVariables": {
24-
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
25-
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wno-shadow -Wconversion -Wsign-conversion -Wcast-align -Wcast-qual -Woverloaded-virtual -Wformat=2 -Wno-error"
23+
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
2624
},
2725
"condition": {
2826
"type": "equals",

cmake/CMakeLinuxPresets.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"name": "debug-base-Linux",
99
"hidden": true,
1010
"cacheVariables": {
11-
"CMAKE_BUILD_TYPE": "Debug",
12-
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined"
11+
"CMAKE_BUILD_TYPE": "Debug"
1312
},
1413
"condition": {
1514
"type": "equals",

cmake/CMakeWindowsPresets.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"root-config"
1414
],
1515
"cacheVariables": {
16-
"CMAKE_CXX_COMPILER": "cl",
17-
"CMAKE_CXX_FLAGS": "/W3 /EHsc /w14242 /w14254 /w14263 /w14265 /w14287 /w14289 /w14296 /w14311 /w14545 /w14546 /w14547 /w14549 /w14555 /w14640 /w14826 /w14928 /WX"
16+
"CMAKE_CXX_COMPILER": "cl"
1817
},
1918
"condition": {
2019
"type": "equals",

include/beman/execution26/detail/schedule_from.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct impls_for<::beman::execution26::detail::schedule_from_t> : ::beman::execu
120120
static constexpr bool nothrow() {
121121
return noexcept(::beman::execution26::connect(::beman::execution26::schedule(::std::declval<Scheduler>()),
122122
receiver_t{nullptr}));
123-
};
123+
}
124124
explicit state_type(Scheduler& sch, Receiver& receiver) noexcept(nothrow())
125125
: state_base<Receiver, Variant>{receiver},
126126
op_state(::beman::execution26::connect(::beman::execution26::schedule(sch), receiver_t{this})) {}

src/beman/execution26/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
add_library(${TARGET_LIBRARY} STATIC)
77
add_library(${TARGET_ALIAS} ALIAS ${TARGET_LIBRARY})
88

9+
if(CMAKE_BUILD_TYPE STREQUAL Debug)
10+
target_link_libraries(${TARGET_LIBRARY} PUBLIC $<BUILD_INTERFACE:${TARGET_LIBRARY}_project_options>)
11+
target_link_libraries(${TARGET_LIBRARY} PUBLIC $<BUILD_INTERFACE:${TARGET_LIBRARY}_project_warnings>)
12+
endif()
13+
914
include(CMakePrintHelpers)
1015
cmake_print_variables(TARGET_ALIAS TARGET_LIBRARY TARGET_PREFIX PROJECT_SOURCE_DIR)
1116

0 commit comments

Comments
 (0)