Skip to content

Commit 5447656

Browse files
authored
Merge pull request #73343 from edymtt/edymtt/use-hostcompatibilitylibs-for-all-bootstrapping-modes-5.10
[🍒 5.10] CMake: ensure Swift host tools depend on HostCompatibilityLibs target
2 parents 86a9b81 + 39d9113 commit 5447656

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,17 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
460460
461461
set(sdk_dir "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift")
462462
463+
# HostCompatibilityLibs is defined as an interface library that
464+
# does not generate any concrete build target
465+
# (https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries)
466+
# In order to specify a dependency to it using `add_dependencies`
467+
# we need to manually "expand" its underlying targets
468+
get_property(compatibility_libs
469+
TARGET HostCompatibilityLibs
470+
PROPERTY INTERFACE_LINK_LIBRARIES)
471+
set(compatibility_libs_path
472+
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}")
473+
463474
# If we found a swift compiler and are going to use swift code in swift
464475
# host side tools but link with clang, add the appropriate -L paths so we
465476
# find all of the necessary swift libraries on Darwin.
@@ -498,8 +509,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
498509
target_link_directories(${target} PRIVATE "${sdk_dir}")
499510
500511
# A backup in case the toolchain doesn't have one of the compatibility libraries.
501-
target_link_directories(${target} PRIVATE
502-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
512+
# We are using on purpose `add_dependencies` instead of `target_link_libraries`,
513+
# since we want to ensure the linker is pulling the matching archives
514+
# only if needed
515+
target_link_directories(${target} PRIVATE "${compatibility_libs_path}")
516+
add_dependencies(${target} ${compatibility_libs})
503517
504518
# Include the abi stable system stdlib in our rpath.
505519
set(swift_runtime_rpath "/usr/lib/swift")
@@ -511,8 +525,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
511525
target_link_directories(${target} PRIVATE ${bs_lib_dir})
512526
513527
# Required to pick up the built libswiftCompatibility<n>.a libraries
514-
target_link_directories(${target} PRIVATE
515-
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
528+
# We are using on purpose `add_dependencies` instead of `target_link_libraries`,
529+
# since we want to ensure the linker is pulling the matching archives
530+
# only if needed
531+
target_link_directories(${target} PRIVATE "${compatibility_libs_path}")
532+
add_dependencies(${target} ${compatibility_libs})
516533
517534
# At runtime link against the built swift libraries from the current
518535
# bootstrapping stage.

0 commit comments

Comments
 (0)