From f974953dcfc2c5a1b23e619da29bdb8d319e1907 Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Fri, 17 Nov 2023 21:38:58 +0300 Subject: [PATCH] Windows native build with sanitizers --- .github/workflows/windows-native.yml | 28 ++++++++++++++++++++++------ CMakeLists.txt | 12 ++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/windows-native.yml b/.github/workflows/windows-native.yml index 3f96e1c61a..f4aa2379d3 100644 --- a/.github/workflows/windows-native.yml +++ b/.github/workflows/windows-native.yml @@ -63,7 +63,7 @@ env: jobs: build_and_test: - name: Windows-2019 [arch ${{ matrix.arch.name }}, toolset ${{ matrix.toolset }}, backend ${{ matrix.backend }}, build shared libs ${{ matrix.shared_libs }}, use CMake prefix path ${{ matrix.use_cmake_prefix_path }}] + name: Windows-2019 [arch ${{ matrix.arch.name }}, toolset ${{ matrix.toolset }}, backend ${{ matrix.backend }}, build shared libs ${{ matrix.shared_libs }}, use CMake prefix path ${{ matrix.use_cmake_prefix_path }}, sanitizers ${{ matrix.sanitizers }}] runs-on: windows-2019 if: "!contains(github.event.head_commit.message, 'skip ci')" strategy: @@ -74,17 +74,26 @@ jobs: backend: [ 'botan', 'openssl' ] shared_libs: [ 'off'] use_cmake_prefix_path: [ 'on', 'off' ] + sanitizers: ['off'] include: + - arch: { name: 'x64', triplet: 'x64-windows' } + toolset: 'v142' + backend: 'botan' + use_cmake_prefix_path: 'off' + shared_libs: 'off' + sanitizers: 'on' - arch: { name: 'Win32', triplet: 'x86-windows' } toolset: 'ClangCL' backend: 'botan' use_cmake_prefix_path: 'on' shared_libs: 'off' + sanitizers: 'off' - arch: { name: 'Win32', triplet: 'x86-windows' } toolset: 'v142' backend: 'openssl' use_cmake_prefix_path: 'off' shared_libs: 'off' + sanitizers: 'off' steps: - name: Checkout @@ -140,7 +149,8 @@ jobs: -A ${{ matrix.arch.name }} \ -T ${{ matrix.toolset }} \ -DBUILD_SHARED_LIBS=${{ matrix.shared_libs}} \ - -DCRYPTO_BACKEND=${{ matrix.backend }} \ + -DENABLE_SANITIZERS=${{ matrix.sanitizers}} \ + -DCRYPTO_BACKEND=${{ matrix.backend }} \ -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_DIR }}/scripts/buildsystems/vcpkg.cmake . - name: Configure using CMake prefix path @@ -152,15 +162,15 @@ jobs: cmake -B build -G "Visual Studio 16 2019" \ -A ${{ matrix.arch.name }} \ -T ${{ matrix.toolset }} \ - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs}} \ - -DCRYPTO_BACKEND=${{ matrix.backend }} \ + -DENABLE_SANITIZERS=${{ matrix.sanitizers}} \ + -DCRYPTO_BACKEND=${{ matrix.backend }} \ -DCMAKE_PREFIX_PATH=${{ env.VCPKG_DIR }}/installed/${{ matrix.arch.triplet }} . - name: Build shell: bash run: | export PATH=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }}/bin:$PATH - cmake --build build --config "Release" --parallel ${{ env.CORES }} + cmake --build build --parallel ${{ env.CORES }} - name: Test shell: bash @@ -172,4 +182,10 @@ jobs: export PATH=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }}/bin:$PATH mkdir -p "build/Testing/Temporary" cp "cmake/CTestCostData.txt" "build/Testing/Temporary" - ctest --parallel ${{ env.CORES }} --test-dir build -C Release --output-on-failure + ctest --parallel ${{ env.CORES }} --test-dir build --output-on-failure + +# Local build hints: +# cmd /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat" +# cmake -B build -G "Visual Studio 16 2019" -A x64 -T v142 -DCMAKE_BUILD_TYPE=Release -DENABLE_SANITIZERS=OFF ^ +# -DBUILD_SHARED_LIBS=OFF -DCRYPTO_BACKEND=botan -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake . +# set PATH=C:\vcpkg\installed\x64-windows\bin;%PATH% diff --git a/CMakeLists.txt b/CMakeLists.txt index 426865f2ab..2fe738622c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,11 +177,15 @@ endif() # sanitizers if (ENABLE_SANITIZERS) - if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") - message(FATAL_ERROR "Sanitizers have only been tested with the clang compiler.") + if (MSVC) + add_compile_options(/fsanitize=address /Zi) + add_link_options(/INCREMENTAL:NO /DEBUG) + elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-fsanitize=leak,address,undefined -fno-omit-frame-pointer -fno-common -O1) + link_libraries(-fsanitize=leak,address,undefined) + else() + message(FATAL_ERROR "Sanitizers have only been tested with the Clang compiler or Microsoft Visual Studio.") endif() - add_compile_options(-fsanitize=leak,address,undefined -fno-omit-frame-pointer -fno-common -O1) - link_libraries(-fsanitize=leak,address,undefined) endif() # adoc for man generation