@@ -600,13 +600,22 @@ function(add_swift_host_library name)
600600 # find all of the necessary swift libraries on Darwin.
601601 if (NOT ASHL_PURE_SWIFT)
602602 if (CMAKE_Swift_COMPILER)
603- # Add in the SDK directory for the host platform and add an rpath.
604- target_link_directories (${name} PRIVATE
605- ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}/usr/lib/swift)
606603 # Add in the toolchain directory so we can grab compatibility libraries
607604 get_filename_component (TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY )
608605 get_filename_component (TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR} /../lib/swift/macosx" ABSOLUTE )
609606 target_link_directories (${name} PUBLIC ${TOOLCHAIN_LIB_DIR} )
607+
608+ # Add in the SDK directory for the host platform.
609+ #
610+ # NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
611+ # ensure that we first find libraries from the toolchain, rather than
612+ # from the SDK. The reason why this is important is that when we perform
613+ # a stage2 build, this path is into the stage1 build. This is not a pure
614+ # SDK and also contains compatibility libraries. We need to make sure
615+ # that the compiler sees the actual toolchain's compatibility libraries
616+ # first before the just built compability libraries or build errors occur.
617+ target_link_directories (${name} PRIVATE
618+ ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}/usr/lib/swift)
610619 endif ()
611620 endif ()
612621
@@ -808,14 +817,23 @@ function(add_swift_host_tool executable)
808817 # host side tools but link with clang, add the appropriate -L paths so we
809818 # find all of the necessary swift libraries on Darwin.
810819 if (CMAKE_Swift_COMPILER)
811- # Add in the SDK directory for the host platform and add an rpath.
812- target_link_directories (${executable} PRIVATE
813- ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}/usr/lib/swift)
814820 # Add in the toolchain directory so we can grab compatibility libraries
815821 get_filename_component (TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY )
816822 get_filename_component (TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR} /../lib/swift/macosx" ABSOLUTE )
817823 target_link_directories (${executable} PUBLIC ${TOOLCHAIN_LIB_DIR} )
818824
825+ # Add in the SDK directory for the host platform and add an rpath.
826+ #
827+ # NOTE: We do this /after/ target_link_directorying TOOLCHAIN_LIB_DIR to
828+ # ensure that we first find libraries from the toolchain, rather than from
829+ # the SDK. The reason why this is important is that when we perform a
830+ # stage2 build, this path is into the stage1 build. This is not a pure SDK
831+ # and also contains compatibility libraries. We need to make sure that the
832+ # compiler sees the actual toolchain's compatibility libraries first
833+ # before the just built compability libraries or build errors occur.
834+ target_link_directories (${executable} PRIVATE
835+ ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}/usr/lib/swift)
836+
819837 if (ASHT_HAS_LIBSWIFT AND SWIFT_TOOLS_ENABLE_LIBSWIFT)
820838 # Workaround to make lldb happy: we have to explicitly add all libswift modules
821839 # to the linker command line.
0 commit comments