Skip to content

Commit 4585bc5

Browse files
committed
build: emulate /GR- when compiling for Windows
The /GR- emulation is needed to support building on Windows. std::function in Microsoft's C++ runtime requires the use of `typeid`. We do not want to emit RTTI data. `-frtti -fno-rtti-data` allows the use of the `typeid` and `dynamic_cast` behaviours but will not emit the RTTI data. With this change, it is possible to build the Windows runtime once again.
1 parent 34e77c0 commit 4585bc5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ function(_add_variant_c_compile_flags)
248248
list(APPEND result "-D_DLL")
249249
# NOTE: We assume that we are using VS 2015 U2+
250250
list(APPEND result "-D_ENABLE_ATOMIC_ALIGNMENT_FIX")
251+
252+
# msvcprt's std::function requires RTTI, but we do not want RTTI data.
253+
# Emulate /GR-
254+
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
255+
list(APPEND result -frtti)
256+
list(APPEND result -Xclang;-fno-rtti-data)
257+
endif()
251258
endif()
252259

253260
if(CFLAGS_ENABLE_ASSERTIONS)

0 commit comments

Comments
 (0)