Skip to content

Commit 9b3a088

Browse files
committed
[cmake] Build Swift host libraries with -DCLANG_BUILD_STATIC on Windows
By default (`CLANG_BUILD_STATIC` and `CLANG_EXPORTS` not defined) some Clang visibility macros expand to `__declspec(dllimport)`. This change ensures that the compiled visibilities for a Swift host library that statically depends on Clang match up with the compiled visibilities of a consumer that also statically depends on Clang, such as LLDB.
1 parent 23eb9d6 commit 9b3a088

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ function(_add_host_variant_c_compile_flags target)
269269
target_compile_options(${target} PRIVATE
270270
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-U_DEBUG>)
271271
endif()
272+
273+
# Swift host libraries are always linked with Clang libraries statically,
274+
# so turn off Clang visibility macros for both the library and its
275+
# consumers.
276+
target_compile_definitions(${target} PUBLIC
277+
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:CLANG_BUILD_STATIC>)
278+
if(TARGET "obj.${target}")
279+
target_compile_definitions("obj.${target}" PUBLIC
280+
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:CLANG_BUILD_STATIC>)
281+
endif()
282+
endif()
272283
endif()
273284
274285
if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")

0 commit comments

Comments
 (0)