Skip to content

Commit 0fe5b10

Browse files
committed
[build] Disable checked iterators on Windows
Trying to run a debug build of the Swift compiler with a host Swift toolchain on Windows was failing with a linker error due to a mismatched `_ITERATOR_DEBUG_LEVEL` macro. This avoids the linker error by disabling bounds-checked iterators on Windows. See the inline comment for details.
1 parent ad503af commit 0fe5b10

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ 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")
423+
# Building with the host Swift toolchain requires linking just-built binaries
424+
# against the host Swift runtime. In debug builds, that means linking a debug
425+
# binary against a release binary. The MSVC linker does not normally permit
426+
# this, since debug builds enable bounds-checked C++ iterators by default,
427+
# which are not ABI-compatible with regular iterators. Let's instruct MSVC to
428+
# disable bounds-checked iterators to make it possible to do a debug build of
429+
# the Swift compiler with a host toolchain.
430+
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
431+
endif()
422432

423433
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
424434
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)