Skip to content

Commit 584dd98

Browse files
committed
CMake: ensure Swift host tools depend on HostCompatibilityLibs target
At the time I implemented #60728, I did not realize that in all the bootstrapping mode we need to depend on the compatibility libraries we build -- otherwise when targeting a low deployment target we risk failing because we are not able to find such libraries. Addresses rdar://126552386
1 parent 9504de5 commit 584dd98

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
466466
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
467467
468468
set(sdk_dir "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift")
469+
get_property(compatibility_libs
470+
TARGET HostCompatibilityLibs
471+
PROPERTY INTERFACE_LINK_LIBRARIES)
472+
set(compatibility_libs_path
473+
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}")
469474
470475
# If we found a swift compiler and are going to use swift code in swift
471476
# host side tools but link with clang, add the appropriate -L paths so we
@@ -505,8 +510,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
505510
target_link_directories(${target} PRIVATE "${sdk_dir}")
506511
507512
# A backup in case the toolchain doesn't have one of the compatibility libraries.
508-
target_link_directories(${target} PRIVATE
509-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
513+
# We are using on purpose `add_dependencies` instead of `target_link_libraries`,
514+
# since we want to ensure the linker is pulling the matching archives
515+
# only if needed
516+
target_link_directories(${target} PRIVATE "${compatibility_libs_path}")
517+
add_dependencies(${target} ${compatibility_libs})
510518
511519
# Include the abi stable system stdlib in our rpath.
512520
set(swift_runtime_rpath "/usr/lib/swift")
@@ -518,8 +526,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
518526
target_link_directories(${target} PRIVATE ${bs_lib_dir})
519527
520528
# Required to pick up the built libswiftCompatibility<n>.a libraries
521-
target_link_directories(${target} PRIVATE
522-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
529+
# We are using on purpose `add_dependencies` instead of `target_link_libraries`,
530+
# since we want to ensure the linker is pulling the matching archives
531+
# only if needed
532+
target_link_directories(${target} PRIVATE "${compatibility_libs_path}")
533+
add_dependencies(${target} ${compatibility_libs})
523534
524535
# At runtime link against the built swift libraries from the current
525536
# bootstrapping stage.

0 commit comments

Comments
 (0)