Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ ifdef C2PA_RS_PATH
CMAKE_OPTS += -DC2PA_RS_PATH="$(C2PA_RS_PATH)"
endif

# Sanitizer builds need a compiler-rt that matches the running OS. On macOS 26+
# the Apple clang (Xcode 16) AddressSanitizer runtime can abort at process startup
# with "sanitizer_malloc_mac.inc CHECK failed: ((!asan_init_is_running))"
# before main() runs. If a Homebrew LLVM clang is actually installed, use it for
# sanitizer builds; otherwise fall back to the default toolchain (fine on older
# macOS and on Linux). Override with SAN_CC / SAN_CXX.
# Note: `brew --prefix llvm` prints a path even when llvm is NOT installed, so the
# binary's existence must be verified (-x) before using it.
SAN_CMAKE_OPTS :=
ifeq ($(OS),Darwin)
SAN_CC ?= $(shell c="$$(brew --prefix llvm 2>/dev/null)/bin/clang"; [ -x "$$c" ] && echo "$$c")
SAN_CXX ?= $(shell c="$$(brew --prefix llvm 2>/dev/null)/bin/clang++"; [ -x "$$c" ] && echo "$$c")
ifneq ($(SAN_CC),)
SAN_CMAKE_OPTS += -DCMAKE_C_COMPILER=$(SAN_CC) -DCMAKE_CXX_COMPILER=$(SAN_CXX)
endif
endif

# Default target
all: clean test examples

Expand Down Expand Up @@ -43,7 +60,14 @@ test-release: clean release

# Test with sanitizers (ASAN + UBSAN)
test-san: clean
cmake -S . -B $(DEBUG_BUILD_DIR) -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON $(CMAKE_OPTS)
@if [ -n "$(SAN_CC)" ]; then \
echo "Sanitizer build using $(SAN_CC)"; \
elif [ "$(OS)" = "Darwin" ]; then \
echo "NOTE: using the default toolchain for sanitizers. If tests abort at startup with"; \
echo " 'asan_init_is_running' (Apple clang on macOS 26+), run 'brew install llvm'"; \
echo " or set SAN_CC/SAN_CXX to a clang whose compiler-rt supports this OS."; \
fi
cmake -S . -B $(DEBUG_BUILD_DIR) -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON $(CMAKE_OPTS) $(SAN_CMAKE_OPTS)
cmake --build $(DEBUG_BUILD_DIR)
cd $(DEBUG_BUILD_DIR) && ctest --output-on-failure

Expand Down
Loading
Loading