From f03127eb697978bfd9f46e2d0cd7e217f1c3723d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 21 Aug 2021 13:55:06 +0200 Subject: [PATCH] Set stack size for some unit tests when using MSVC (#2961) * :checkered_flag: set stack size for some unit tests --- .github/workflows/windows.yml | 8 ++++---- appveyor.yml | 11 ++--------- test/CMakeLists.txt | 7 +++++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4820be4e1d..597da47747 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -38,13 +38,13 @@ jobs: steps: - uses: actions/checkout@v2 - name: cmake - run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX" + run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Release' && matrix.architecture == 'x64' - name: cmake run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Release' && matrix.architecture != 'x64' - name: cmake - run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX" + run: cmake -S . -B build -G "Visual Studio 15 2017" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Debug' - name: build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 @@ -76,7 +76,7 @@ jobs: run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Release' - name: cmake - run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" -DCMAKE_CXX_FLAGS="/W4 /WX" + run: cmake -S . -B build -G "Visual Studio 16 2019" -A ${{ matrix.architecture }} -DJSON_BuildTests=On -DJSON_FastTests=ON -DCMAKE_CXX_FLAGS="/W4 /WX" if: matrix.build_type == 'Debug' - name: build run: cmake --build build --config ${{ matrix.build_type }} --parallel 10 @@ -89,7 +89,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: cmake - run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" -DCMAKE_EXE_LINKER_FLAGS="/STACK:4000000" + run: cmake -S . -B build -G "Visual Studio 16 2019" -DJSON_BuildTests=On -DCMAKE_CXX_FLAGS="/permissive- /std:c++latest /utf-8 /W4 /WX" - name: build run: cmake --build build --config Release --parallel 10 - name: test diff --git a/appveyor.yml b/appveyor.yml index 4190b418ea..b04ac24f23 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,6 @@ environment: configuration: Debug platform: x86 CXX_FLAGS: "/W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 14 2015 @@ -14,7 +13,6 @@ environment: configuration: Release platform: x86 CXX_FLAGS: "/W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 14 2015 @@ -23,7 +21,6 @@ environment: platform: x86 name: with_win_header CXX_FLAGS: "/W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 14 2015 @@ -31,7 +28,6 @@ environment: configuration: Release platform: x86 CXX_FLAGS: "/permissive- /std:c++latest /utf-8 /W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 15 2017 @@ -39,7 +35,6 @@ environment: configuration: Release platform: x86 CXX_FLAGS: "/W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "-DJSON_ImplicitConversions=OFF" GENERATOR: Visual Studio 16 2019 @@ -47,15 +42,13 @@ environment: configuration: Release platform: x64 CXX_FLAGS: "/W4 /WX" - LINKER_FLAGS: "" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 14 2015 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 configuration: Release platform: x64 - CXX_FLAGS: "/permissive- /std:c++latest /Zc:__cplusplus /utf-8 /F4000000 /W4 /WX" - LINKER_FLAGS: "/STACK:4000000" + CXX_FLAGS: "/permissive- /std:c++latest /Zc:__cplusplus /utf-8 /W4 /WX" CMAKE_OPTIONS: "" GENERATOR: Visual Studio 15 2017 @@ -70,7 +63,7 @@ before_build: # for with_win_header build, inject the inclusion of Windows.h to the single-header library - ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" } - ps: if ($env:name -Eq "with_win_header") { "#include `n" + (Get-Content $header_path | Out-String) | Set-Content $header_path } - - cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%" + - cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On "%CMAKE_OPTIONS%" build_script: - cmake --build . --config "%configuration%" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a7958cbd0e..447192cb0f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -100,6 +100,13 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") #target_compile_definitions(test-disabled_exceptions PUBLIC _HAS_EXCEPTIONS=0) endif() +# avoid stack overflow, see https://github.com/nlohmann/json/issues/2955 +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set_property(TARGET test-cbor APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000") + set_property(TARGET test-msgpack APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000") + set_property(TARGET test-ubjson APPEND_STRING PROPERTY LINK_FLAGS " /STACK:4000000") +endif() + ############################################################################# # Test the generated build configs #############################################################################