Skip to content

Commit c00fc40

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)`. Swift depends on Clang statically, so needs to turn these macros off.
1 parent 23eb9d6 commit c00fc40

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ 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()
272282
endif()
273283
274284
if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
#ifndef __SWIFT_ABI_DIGESTER_MODULE_NODES_H__
1818
#define __SWIFT_ABI_DIGESTER_MODULE_NODES_H__
1919

20-
#include "clang/AST/ASTContext.h"
21-
#include "clang/AST/DeclObjC.h"
22-
#include "clang/Lex/Preprocessor.h"
23-
#include "clang/Sema/Lookup.h"
24-
#include "clang/Sema/Sema.h"
2520
#include "llvm/ADT/TinyPtrVector.h"
2621
#include "llvm/ADT/STLExtras.h"
2722
#include "llvm/Support/CommandLine.h"

lib/APIDigester/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ add_swift_host_library(swiftAPIDigester STATIC
77
target_link_libraries(swiftAPIDigester PRIVATE
88
swiftIDE)
99

10+
# Clang dependencies. These are private because APIDigester's public
11+
# interface does not use Clang symbols.
12+
target_link_libraries(swiftAPIDigester PRIVATE
13+
clangAST
14+
clangLex)
15+
1016
set_swift_llvm_is_available(swiftAPIDigester)

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "swift/Basic/Defer.h"
44
#include "swift/Parse/Lexer.h"
55
#include "swift/Sema/IDETypeChecking.h"
6+
#include "clang/AST/DeclObjC.h"
7+
#include "clang/Lex/Preprocessor.h"
68
#include "llvm/ADT/STLExtras.h"
79
#include <algorithm>
810
#include <swift/APIDigester/ModuleAnalyzerNodes.h>

lib/IDE/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ target_link_libraries(swiftIDE PRIVATE
4646
swiftParse
4747
swiftSema)
4848

49+
# Clang dependencies. These are private because IDE's public
50+
# interface does not use Clang symbols.
51+
target_link_libraries(swiftIDE PRIVATE
52+
clangAST
53+
clangBasic
54+
clangIndex
55+
clangLex)
56+
4957
if (SWIFT_BUILD_SWIFT_SYNTAX)
5058
target_link_libraries(swiftIDE PRIVATE
5159
swiftIDEUtilsBridging

0 commit comments

Comments
 (0)