From 4c982601f5121118b0b645dbd03b59a569feafee Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Tue, 29 Oct 2024 14:26:01 -0400 Subject: [PATCH] build Windows debug client/server with ASAN This commit updates the `tests/CMakeLists.txt` configuration for building the client/server examples on Windows to enable address sanitizer (ASAN). We were already doing this for Linux and MacOS builds but were missing Windows coverage. Notably this requires a modern MSVC configured on the $PATH at runtime so that the ASAN DLLs are present. Otherwise the built binaries cryptically exit immediately with no output, just the exit status -1073741515. We use the setup-msvc-dev action in CI to do this for us. See the Microsoft documentation for more information: https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/#compiling-with-asan-from-the-console --- .github/workflows/test.yaml | 8 ++++++++ tests/CMakeLists.txt | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7b44ad9d..9c499ae6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -111,6 +111,14 @@ jobs: persist-credentials: false - name: Install nightly rust toolchain uses: dtolnay/rust-toolchain@nightly + # For Debug builds we use ASAN, which requires a modern MSVC on $PATH + # to provide the ASAN clang_rt.asan_*.dll runtime deps or + # the built client/server binary will exit immediately with + # exit code -1073741515 + - name: Setup MSVC + uses: TheMrMilchmann/setup-msvc-dev@v3 + with: + arch: x64 - name: Configure CMake run: cmake -DCRYPTO_PROVIDER="${{ matrix.crypto }}" -S . -B build - name: Build, debug configuration diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a7b10a04..328eb174 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,6 +13,10 @@ elseif (CRYPTO_PROVIDER STREQUAL "ring") add_compile_definitions(DEFINE_RING) endif () +# Set ASAN sanitizer flags conditionally for Debug builds +set(sanitizer_flags "$<$:-fsanitize=address>") +add_compile_options(${sanitizer_flags}) + add_executable(client client.c common.c) add_dependencies(client rustls-ffi) target_include_directories(client PUBLIC ${CMAKE_SOURCE_DIR}/src)