Skip to content

Commit

Permalink
Try to optimize CI sanitizer checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Nov 14, 2024
1 parent bc6a99a commit c84a7ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ jobs:
run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }}

- name: Linux ${{ matrix.compiler }} sanitizer
if: startsWith(matrix.preset, 'debug')
run: CXX=${{ matrix.compiler }} make all
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }}

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

- name: macos g++ ${{ matrix.preset }}
Expand All @@ -69,5 +69,5 @@ jobs:

# TODO: fails with AppleClang 16.0.0 on CI!
# - name: macos g++ sanitizer
# if: startsWith(matrix.compiler, 'g++')
# if: startsWith(matrix.compiler, 'g++') && startsWith(matrix.preset, 'debug')
# run: CXX=${{ matrix.compiler }} make all
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ install(
DESTINATION ${INSTALL_CONFIGDIR}
)

set(CPACK_GENERATOR TGZ)
include(CPack)
31 changes: 20 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
MAKEFLAGS+= --no-builtin-rules # Disable the built-in implicit rules.
MAKEFLAGS+= --warn-undefined-variables # Warn when an undefined variable is referenced.

SANITIZERS = release debug usan # TODO: lsan
SANITIZERS = usan # TODO: lsan
OS := $(shell /usr/bin/uname)
ifeq ($(OS),Darwin)
SANITIZERS += tsan
SANITIZERS += tsan # TODO: asan
endif
ifeq ($(OS),Linux)
SANITIZERS += asan # TODO: msan
SANITIZERS += asan # TODO: tsan msan
endif

.PHONY: default doc run update check ce todo distclean clean codespell clang-tidy build test all format $(SANITIZERS)
.PHONY: default release debug doc run update check ce todo distclean clean codespell clang-tidy build test all format $(SANITIZERS)

SYSROOT ?=
TOOLCHAIN ?=
Expand All @@ -27,8 +27,10 @@ ifeq ($(CXX_BASE),clang++)
COMPILER=clang++
endif

CXX_FLAGS = -g
SANITIZER = release
LDFLAGS :=
SAN_FLAGS :=
CXX_FLAGS := -g
SANITIZER ?= default
SOURCEDIR = $(CURDIR)
BUILDROOT = build
BUILD = $(BUILDROOT)/$(SANITIZER)
Expand All @@ -43,18 +45,22 @@ ifeq ($(SANITIZER),debug)
endif
ifeq ($(SANITIZER),msan)
SAN_FLAGS = -fsanitize=memory
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),asan)
SAN_FLAGS = -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize-address-use-after-scope
endif
ifeq ($(SANITIZER),usan)
SAN_FLAGS = -fsanitize=undefined
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),tsan)
SAN_FLAGS = -fsanitize=thread
LDFLAGS = $(SAN_FLAGS)
endif
ifeq ($(SANITIZER),lsan)
SAN_FLAGS = -fsanitize=leak
LDFLAGS = $(SAN_FLAGS)
endif

default: test
Expand All @@ -67,20 +73,23 @@ run: test
doc:
doxygen docs/Doxyfile

release: test

$(SANITIZERS):
$(MAKE) SANITIZER=$@

build:
@mkdir -p $(BUILD)
cd $(BUILD); CC=$(CXX) cmake -G Ninja $(SOURCEDIR) $(TOOLCHAIN) $(SYSROOT) -DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
CC=$(CXX) LDFLAGS=$(LDFLAGS) cmake --fresh -G Ninja -S $(SOURCEDIR) -B $(BUILD) $(TOOLCHAIN) $(SYSROOT) \
-DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_CXX_FLAGS="$(CXX_FLAGS) $(SAN_FLAGS)"
cmake --build $(BUILD)

test: build
# cmake --workflow --preset $(SANITIZER)
ctest --test-dir $(BUILD) --rerun-failed --output-on-failure

release:
cmake --workflow --preset $@ --fresh

debug:
cmake --workflow --preset $@ --fresh

ce:
@mkdir -p $(BUILD)
bin/mk-compiler-explorer.py $(BUILD)
Expand Down

0 comments on commit c84a7ae

Please sign in to comment.