@@ -545,11 +545,11 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
545545 target_link_libraries (${target} PRIVATE "swiftCore" )
546546
547547 target_link_directories (${target} PRIVATE ${host_lib_dir} )
548- if (ASRLF_BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" )
549- set (swift_runtime_rpath " ${host_lib_dir} " )
550- else ()
551- set (swift_runtime_rpath "$ORIGIN/ ${relpath_to_lib_dir} /swift/${SWIFT_SDK_ ${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" )
552- endif ( )
548+
549+ # At runtime, use swiftCore in the current toolchain.
550+ # For building stdlib, LD_LIBRARY_PATH will be set to builder's stdlib
551+ # FIXME: This assumes the ABI hasn't changed since the builder.
552+ set (swift_runtime_rpath "$ORIGIN/ ${relpath_to_lib_dir} /swift/${SWIFT_SDK_ ${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" )
553553
554554 elseif (ASRLF_BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING" )
555555 # At build time link against the built swift libraries from the
@@ -573,10 +573,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
573573 endif ()
574574
575575 if (SWIFT_SWIFT_PARSER)
576- # Make sure we can find the early SwiftSyntax libraries.
577- target_link_directories (${target} PRIVATE "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR} /lib/swift/host" )
578-
579- # For the "end step" of bootstrapping configurations on Darwin, need to be
576+ # For the "end step" of bootstrapping configurations, we need to be
580577 # able to fall back to the SDK directory for libswiftCore et al.
581578 if (BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*" )
582579 if (NOT "${bootstrapping} " STREQUAL "1" )
@@ -590,6 +587,13 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
590587 get_filename_component (TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY )
591588 get_filename_component (TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR} /../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" ABSOLUTE )
592589 target_link_directories (${target} PUBLIC ${TOOLCHAIN_LIB_DIR} )
590+ else ()
591+ get_filename_component (swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY )
592+ get_filename_component (swift_dir ${swift_bin_dir} DIRECTORY )
593+ set (host_lib_dir "${swift_dir} /lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" )
594+ target_link_directories (${target} PRIVATE ${host_lib_dir} )
595+
596+ set (swift_runtime_rpath "${host_lib_dir} " )
593597 endif ()
594598 endif ()
595599 endif ()
@@ -822,8 +826,43 @@ macro(add_swift_lib_subdirectory name)
822826 add_llvm_subdirectory(SWIFT LIB ${name} )
823827endmacro ()
824828
829+ # Add a new Swift host executable.
830+ #
831+ # Usage:
832+ # add_swift_host_tool(name
833+ # [HAS_SWIFT_MODULES | DOES_NOT_USE_SWIFT]
834+ # [THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY]
835+ #
836+ # [BOOTSTRAPPING 0|1]
837+ # [SWIFT_COMPONENT component]
838+ # [LLVM_LINK_COMPONENTS comp1 ...]
839+ # source1 [source2 source3 ...])
840+ #
841+ # name
842+ # Name of the executable (e.g., swift-frontend).
843+ #
844+ # HAS_SWIFT_MODULES
845+ # Whether to link with SwiftCompilerSources library
846+ #
847+ # DOES_NOT_USE_SWIFT
848+ # Do not link with swift runtime
849+ #
850+ # THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
851+ # Opt-out of LLVM IR optimizations when linking ThinLTO with ld64
852+ #
853+ # BOOTSTRAPPING
854+ # Bootstrapping stage.
855+ #
856+ # SWIFT_COMPONENT
857+ # Installation component where this tool belongs to.
858+ #
859+ # LLVM_LINK_COMPONENTS
860+ # LLVM components this library depends on.
861+ #
862+ # source1 ...
863+ # Sources to add into this executable.
825864function (add_swift_host_tool executable)
826- set (options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
865+ set (options HAS_SWIFT_MODULES DOES_NOT_USE_SWIFT THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
827866 set (single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
828867 set (multiple_parameter_options LLVM_LINK_COMPONENTS)
829868
@@ -879,12 +918,12 @@ function(add_swift_host_tool executable)
879918 endif ()
880919
881920 # Once the new Swift parser is linked in, every host tool has Swift modules.
882- if (SWIFT_SWIFT_PARSER)
921+ if (SWIFT_SWIFT_PARSER AND NOT ASHT_DOES_NOT_USE_SWIFT )
883922 set (ASHT_HAS_SWIFT_MODULES ON )
884923 endif ()
885924
886925 if (ASHT_HAS_SWIFT_MODULES)
887- _add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING} " )
926+ _add_swift_runtime_link_flags(${executable} "../lib" "${ASHT_BOOTSTRAPPING} " )
888927 endif ()
889928
890929 llvm_update_compile_flags(${executable} )
@@ -926,10 +965,17 @@ function(add_swift_host_tool executable)
926965 endif ()
927966 endif ()
928967
929- set_property (
930- TARGET ${executable}
931- APPEND PROPERTY INSTALL_RPATH
932- "@executable_path/../${extra_relative_rpath} lib/swift/host" )
968+ if (${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
969+ set_property (
970+ TARGET ${executable}
971+ APPEND PROPERTY INSTALL_RPATH
972+ "@executable_path/../${extra_relative_rpath} lib/swift/host" )
973+ else ()
974+ set_property (
975+ TARGET ${executable}
976+ APPEND PROPERTY INSTALL_RPATH
977+ "$ORIGIN/../${extra_relative_rpath} lib/swift/host" )
978+ endif ()
933979 endif ()
934980
935981 if (ASHT_THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
@@ -950,7 +996,8 @@ function(add_swift_host_tool executable)
950996 swift_install_in_component(TARGETS ${executable}
951997 RUNTIME
952998 DESTINATION bin
953- COMPONENT ${ASHT_SWIFT_COMPONENT} )
999+ COMPONENT ${ASHT_SWIFT_COMPONENT}
1000+ )
9541001
9551002 swift_is_installing_component(${ASHT_SWIFT_COMPONENT} is_installing)
9561003 endif ()
0 commit comments