Skip to content

Commit

Permalink
Windows native build with sanitizers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Nov 17, 2023
1 parent a266da2 commit f974953
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/windows-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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%
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f974953

Please sign in to comment.