From 48060d1111cd907c3f8427f28c2c822c00083ddd Mon Sep 17 00:00:00 2001 From: Lee *!* Clagett Date: Tue, 23 Sep 2025 11:13:17 -0400 Subject: [PATCH] Add sanitizer option to build and add CI that uses it (#184) --- .github/workflows/build-ubuntu.yml | 52 ++++++++++++++++++++++++++++++ CMakeLists.txt | 11 +++++++ 2 files changed, 63 insertions(+) diff --git a/.github/workflows/build-ubuntu.yml b/.github/workflows/build-ubuntu.yml index 32880a1..40348af 100644 --- a/.github/workflows/build-ubuntu.yml +++ b/.github/workflows/build-ubuntu.yml @@ -105,4 +105,56 @@ jobs: - name: Run Tests run: cd ${{github.workspace}}/lws/build && ctest + build-sanitizer-tests: + runs-on: ${{matrix.os}} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + rmq: [WITH_RMQ=ON] + sanitizer: [SANITIZER=address] + steps: + - name: set apt conf (Debian based Linux) + if: matrix.os == 'ubuntu-latest' + run: ${{env.APT_SET_CONF}} + - name: update apt (Debian based Linux) + if: matrix.os == 'ubuntu-latest' + run: sudo apt update + - name: Install dependencies (Debian based Linux) + if: matrix.os == 'ubuntu-latest' + run: ${{env.APT_INSTALL_LINUX}} + - name: Install RabbitMQ iff WITH_RMQ (Debian based Linux) + if: matrix.rmq == 'WITH_RMQ=ON' && (matrix.os == 'ubuntu-latest') + run: sudo apt -y install librabbitmq-dev + + - name: Install dependencies (MacOS) + if: matrix.os == 'macos-latest' + run: ${{env.BREW_INSTALL_MAC}} + - name: Install RabbitMQ iff WITH_RMQ (MacOS) + if: matrix.rmq == 'WITH_RMQ=ON' && (matrix.os == 'macos-latest') + run: HOMEBREW_NO_AUTO_UPDATE=1 brew install rabbitmq-c + + - name: Checkout Monero Source + uses: actions/checkout@v4 + with: + repository: monero-project/monero + path: ${{github.workspace}}/monero/ + submodules: recursive + + - name: Checkout LWS Source + uses: actions/checkout@v4 + with: + path: ${{github.workspace}}/lws + + - name: Configure LWS + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/lws/build -D${{matrix.rmq}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DMONERO_SOURCE_DIR=${{github.workspace}}/monero ${{github.workspace}}/lws -D${{matrix.sanitizer}} -DBUILD_TESTS=ON + + - name: Build LWS + # Build your program with the given configuration + run: (cd ${{github.workspace}}/lws/build && make -j$(nproc)) + + - name: Run Tests + run: cd ${{github.workspace}}/lws/build && ctest --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index fad3fec..347d23e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,17 @@ endif() set (LWS_BUILD_TESTS "${BUILD_TESTS}") set (BUILD_TESTS "Off") +option(SANITIZER "Use specific sanitizer" OFF) +if(NOT SANITIZER STREQUAL "OFF") + if (MSVC) + message(FATAL_ERROR "Cannot sanitize with MSVC") + else() + message(STATUS "Using sanitizer=${SANITIZER}") + add_compile_options("-fsanitize=${SANITIZER}") + add_link_options("-fsanitize=${SANITIZER}") + endif() +endif() + if(STATIC) if(MSVC) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES})