Skip to content

Commit 97bc7c2

Browse files
authored
Merge pull request #76550 from swiftlang/egorzhdan/msvc-checked-iterators
[build] Disable checked iterators on Windows
2 parents 4d01253 + 7fad3e7 commit 97bc7c2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,17 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
419419
${SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY_default}
420420
CACHE STRING "MSVC Runtime Library for the standard library")
421421

422+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND
423+
CMAKE_BUILD_TYPE STREQUAL "Debug")
424+
# Building with the host Swift toolchain requires linking just-built binaries
425+
# against the host Swift runtime. In debug builds, that means linking a debug
426+
# binary against a release binary. The MSVC linker does not normally permit
427+
# this, since debug builds enable bounds-checked C++ iterators by default,
428+
# which are not ABI-compatible with regular iterators. Let's instruct MSVC to
429+
# disable bounds-checked iterators to make it possible to do a debug build of
430+
# the Swift compiler with a host toolchain.
431+
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
432+
endif()
422433

423434
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
424435
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8))

0 commit comments

Comments
 (0)