Skip to content

Commit b6878ce

Browse files
authored
Link all compatibility libraries when cross compiling and bootstrapping (#60728)
Refactor the logic so to have a single target to reference the compatibility libraries for the host, and use that when needed. The main driver for this change is supporting the cross-compilation of x86-64 on Apple Silicon. Supports rdar://90307965
1 parent 27ff49f commit b6878ce

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,13 @@ else()
301301
endif()
302302
endif()
303303
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS AND SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
304-
set(platform ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR})
305-
set(compatibility_libs
306-
"swiftCompatibility50-${platform}"
307-
"swiftCompatibility51-${platform}"
308-
"swiftCompatibilityDynamicReplacements-${platform}")
309-
304+
# We cannot specify directly HostCompatibilityLibs
305+
# because ultimately is used to specify a dependency for a
306+
# custom target and, unlike `target_link_libraries`, such dependency
307+
# would be lost at the generation of the build system.
308+
get_property(compatibility_libs
309+
TARGET HostCompatibilityLibs
310+
PROPERTY INTERFACE_LINK_LIBRARIES)
310311
list(APPEND b0_deps ${compatibility_libs})
311312
list(APPEND b1_deps ${compatibility_libs})
312313
endif()

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
465465
# the stdlib is not picked up from there, but from the SDK.
466466
# This requires to explicitly add all the needed compatibility libraries. We
467467
# can take them from the current build.
468-
set(vsuffix "-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
469-
set(conctarget "swiftCompatibilityConcurrency${vsuffix}")
470-
target_link_libraries(${target} PUBLIC ${conctarget})
468+
target_link_libraries(${target} PUBLIC HostCompatibilityLibs)
471469
472470
# Add the SDK directory for the host platform.
473471
target_link_directories(${target} PRIVATE "${sdk_dir}")

stdlib/toolchain/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,16 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
5353
add_subdirectory(CompatibilityDynamicReplacements)
5454
add_subdirectory(CompatibilityConcurrency)
5555
add_subdirectory(CompatibilityThreading)
56+
57+
# This is a convenience target to have the list
58+
# of all the compatibility libraries needed to build
59+
# host tools in a single place
60+
add_library(HostCompatibilityLibs INTERFACE)
61+
set(vsuffix "-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
62+
target_link_libraries(HostCompatibilityLibs INTERFACE
63+
swiftCompatibilityConcurrency${vsuffix}
64+
swiftCompatibilityDynamicReplacements${vsuffix}
65+
swiftCompatibility50${vsuffix}
66+
swiftCompatibility51${vsuffix})
67+
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS HostCompatibilityLibs)
5668
endif()

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ function(add_sourcekitd_swifrt_linking target path HAS_SWIFT_MODULES)
5151
# the stdlib is not picked up from there, but from the SDK.
5252
# This requires to explicitly add all the needed compatibility libraries. We
5353
# can take them from the current build.
54-
set(vsuffix "-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
55-
set(conctarget "swiftCompatibilityConcurrency${vsuffix}")
56-
target_link_libraries(${target} PUBLIC ${conctarget})
54+
target_link_libraries(${target} PUBLIC HostCompatibilityLibs)
5755

5856
# Add the SDK directory for the host platform.
5957
target_link_directories(${target} PRIVATE "${sdk_dir}")

0 commit comments

Comments
 (0)