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
87 changes: 84 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Test
name: Build & Test CI

on:
push:
Expand All @@ -7,9 +7,9 @@ on:
branches: [main]

jobs:
build:
build_default:
name: Build (Default)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -25,3 +25,84 @@ jobs:

- name: Run tests
run: ctest --test-dir build --output-on-failure

build_asan:
name: Build (ASan)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build g++ libgtest-dev

- name: Configure CMake (ASan)
run: cmake -S . -B build -GNinja -DENABLE_TESTING=ON -DENABLE_ASAN=ON

- name: Build
run: cmake --build build

- name: Run tests
run: ctest --test-dir build --output-on-failure

build_ubsan:
name: Build (UBSan)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build g++ libgtest-dev

- name: Configure CMake (UBSan)
run: cmake -S . -B build -GNinja -DENABLE_TESTING=ON -DENABLE_UBSAN=ON

- name: Build
run: cmake --build build

- name: Run tests
run: ctest --test-dir build --output-on-failure

build_asan_ubsan:
name: Build (ASan + UBSan)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build g++ libgtest-dev

- name: Configure CMake (ASan + UBSan)
run: cmake -S . -B build -GNinja -DENABLE_TESTING=ON -DENABLE_ASAN=ON -DENABLE_UBSAN=ON

- name: Build
run: cmake --build build

- name: Run tests
run: ctest --test-dir build --output-on-failure

build_tsan:
name: Build (TSan)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cmake ninja-build g++ libgtest-dev

- name: Configure CMake (TSan)
run: cmake -S . -B build -GNinja -DENABLE_TESTING=ON -DENABLE_TSAN=ON

- name: Build
run: cmake --build build

- name: Run tests
run: ctest --test-dir build --output-on-failure
# TSan tests might need specific environment variables or options if they are flaky
# For example, setting TSAN_OPTIONS:
# env:
# TSAN_OPTIONS: "suppressions=my_tsan.supp"
# End of workflow file
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/PreventInSourceBuilds.cmake)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
option(ENABLE_TESTING "Enable Test Builds" OFF)

# Sanitizer Options
option(ENABLE_ASAN "Enable AddressSanitizer (ASan)" OFF)
option(ENABLE_TSAN "Enable ThreadSanitizer (TSan)" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)

# Sanitizer configuration
# Ensure TSan is mutually exclusive with ASan and UBSan for this project
if(ENABLE_TSAN)
if(ENABLE_ASAN)
message(WARNING "AddressSanitizer (ASan) is not compatible with ThreadSanitizer (TSan). Disabling ASan.")
set(ENABLE_ASAN OFF CACHE BOOL "Enable AddressSanitizer (ASan)" FORCE)
endif()
if(ENABLE_UBSAN)
message(WARNING "UndefinedBehaviorSanitizer (UBSan) is not recommended with ThreadSanitizer (TSan) in this configuration. Disabling UBSan.")
set(ENABLE_UBSAN OFF CACHE BOOL "Enable UndefinedBehaviorSanitizer (UBSan)" FORCE)
endif()
endif()

if(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# For some linkers (like LLD), you might need to add -u__asan_default_options to ensure options are linked.
# Also, for better stack traces, you might add:
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
message(STATUS "AddressSanitizer (ASan) enabled.")
endif()

if(ENABLE_TSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
message(STATUS "ThreadSanitizer (TSan) enabled.")
endif()

if(ENABLE_UBSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
# Common UBSan flags for stricter checks / immediate exit:
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=all")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-sanitize-recover=all")
message(STATUS "UndefinedBehaviorSanitizer (UBSan) enabled.")
endif()

include_directories(include)

add_subdirectory(src)
Expand Down
Loading