Skip to content

Commit 8bf26a7

Browse files
committed
Runtime: control swiftCore_EXPORTS based on the build
This define is meant to be present only when performing a build of a dynamic library. The general pattern for this is: ```c #if defined(LIBRARY_STATIC) # define LIBRARY_ABI /**/ #else # if defined(_WIN32) # if defined(LIBRARY_EXPORTS) # define LIBRARY_ABI __declspec(dllexport) # else # define LIBRARY_ABI __declspec(dllimport) # endif # elseif defined(__linux__) && !defined(__ANDROID__) # define LIBRARY_ABI __attribute__((__visibility__("protected"))) # else # define LIBRARY_ABI __attribute__((__visibility__("default"))) # endif #endif ``` For AIX this would require an additional flag to be specified (`-mdefault-visibility-export-mapping=explicit`). The same applies for other non-AIX, non-Windows platforms with a different set of flags: `-fvisibility=hidden -fvisibility-inlines-hidden`. This is required to start trying to build the standard library statically on Windows (which also requires further changes to the Swift compiler).
1 parent b748546 commit 8bf26a7

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ add_library(swiftDemangling OBJECT
99
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Remangler.cpp"
1010
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/NodeDumper.cpp"
1111
"${SwiftCore_SWIFTC_SOURCE_DIR}/lib/Demangling/Errors.cpp")
12-
target_compile_definitions(swiftDemangling PRIVATE swiftCore_EXPORTS
12+
target_compile_definitions(swiftDemangling PRIVATE
13+
$<$<BOOL:${BUILD_SHARED_LIBS}>:-DswiftCore_EXPORTS>
1314
$<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_SUPPORT_OLD_MANGLING>
1415
$<$<BOOL:${SwiftCore_ENABLE_TYPE_PRINTING}>:-DSWIFT_STDLIB_HAS_TYPE_PRINTING>
1516
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>)

Runtimes/Core/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ target_compile_definitions(swiftCore PRIVATE
306306
$<$<BOOL:${SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS}>:-DSWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER>
307307
$<$<COMPILE_LANGUAGE:C,CX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftCore>)
308308
target_compile_options(swiftCore PRIVATE
309-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DswiftCore_EXPORTS>")
309+
"$<$<AND:$<BOOL:${BUILD_SHARED_LIBS}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DswiftCore_EXPORTS>")
310310

311311
target_link_libraries(swiftCore PRIVATE swiftShims)
312312
target_link_libraries(swiftCore

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ endif()
7676
# file rather than pushing them through macro flags.
7777
target_compile_definitions(swiftRuntime
7878
PRIVATE
79-
-DswiftCore_EXPORTS
8079
-DSWIFT_RUNTIME
8180
-DSWIFT_TARGET_LIBRARY_NAME=swiftRuntime
81+
$<$<BOOL:${BUILD_SHARED_LIBS}>:-DswiftCore_EXPORTS>
8282
$<$<BOOL:${SwiftCore_ENABLE_BACKTRACING}>:-DSWIFT_ENABLE_BACKTRACING>
8383
$<$<BOOL:${SwiftCore_ENABLE_OVERRIDABLE_RETAIN_RELEASE}>:-DSWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE>
8484
$<$<BOOL:${SwiftCore_ENABLE_MALLOC_TYPE}>:-DSWIFT_STDLIB_HAS_MALLOC_TYPE>

Runtimes/Core/stubs/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ endif()
2727

2828

2929
target_compile_definitions(swiftStdlibStubs PRIVATE
30-
swiftCore_EXPORTS
30+
$<$<BOOL:${BUILD_SHARED_LIBS}>:-DswiftCore_EXPORTS>
3131
$<$<BOOL:${SwiftCore_ENABLE_UNICODE_DATA}>:-DSWIFT_STDLIB_ENABLE_UNICODE_DATA>)
32+
33+
3234
target_link_libraries(swiftStdlibStubs PRIVATE swiftShims)
3335
target_include_directories(swiftStdlibStubs PRIVATE
3436
"${PROJECT_BINARY_DIR}/include"

0 commit comments

Comments
 (0)