Skip to content

Commit efb9f7c

Browse files
committed
CMake: on Darwin be explicit about inclusion in the dyld shared cache
This entails passing a linker flags when the standard library is not meant for inclusion in such cache -- such flag is supported by both LLD and the Apple linkers. For this to have effect on every library, propagate link flags when building _Concurrency and Observation. This is needed for Apple internal configurations. Addresses rdar://120653968
1 parent 2ce19b0 commit efb9f7c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

stdlib/public/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ if(SWIFT_STDLIB_SIL_DEBUGGING)
1919
list(APPEND SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS "-Xfrontend" "-sil-based-debuginfo")
2020
endif()
2121

22+
option(SWIFT_RUNTIME_PART_OF_DARWIN_SHARED_CACHE
23+
"On Darwin platforms, link the standard library in a way that
24+
allows inclusion in the dyld shared cache"
25+
FALSE)
26+
27+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
28+
set(linker_detected "$<BOOL:${LLVM_LINKER_DETECTED}>")
29+
set(runtime_not_in_shared_cache "$<NOT:$<BOOL:${SWIFT_RUNTIME_PART_OF_DARWIN_SHARED_CACHE}>>")
30+
set(shared_cache_link_flags
31+
"$<$<AND:${linker_detected},${runtime_not_in_shared_cache}>:LINKER:-not_for_dyld_shared_cache>")
32+
list(APPEND SWIFT_RUNTIME_LINK_FLAGS ${shared_cache_link_flags})
33+
list(APPEND SWIFT_RUNTIME_SWIFT_LINK_FLAGS ${shared_cache_link_flags})
34+
endif()
35+
2236
# Build the runtime with -Wall to catch, e.g., uninitialized variables
2337
# warnings.
2438
if(SWIFT_COMPILER_IS_MSVC_LIKE)

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
172172
-diagnostic-style swift
173173
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
174174
${swift_concurrency_options}
175+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
175176
INSTALL_IN_COMPONENT stdlib
176177
MACCATALYST_BUILD_FLAVOR zippered
177178
)

stdlib/public/Observation/Sources/Observation/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_swift_target_library(swiftObservation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS
2929

3030
C_COMPILE_FLAGS
3131
${swift_runtime_library_compile_flags}
32+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
3233

3334
SWIFT_MODULE_DEPENDS _Concurrency
3435
INSTALL_IN_COMPONENT stdlib

0 commit comments

Comments
 (0)