Skip to content

Commit 277619a

Browse files
DougGregorrintaro
authored andcommitted
[CMake] Add paths for building Swift code against host toolchain
When building Swift code into the compiler (e.g, the new Swift parser along with macros support), make sure we always add the appropriate paths to (1) link against the host Swift toolchain, and (2) find the host Swift libraries (such as SwiftSyntax) at runtime. The CMake code for doing this was only running for Darwin builds, so generalize it to also work on Linux.
1 parent a129287 commit 277619a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
576576
# Make sure we can find the early SwiftSyntax libraries.
577577
target_link_directories(${target} PRIVATE "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host")
578578

579-
# For the "end step" of bootstrapping configurations on Darwin, need to be
579+
# For the "end step" of bootstrapping configurations, we need to be
580580
# able to fall back to the SDK directory for libswiftCore et al.
581581
if (BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
582582
if (NOT "${bootstrapping}" STREQUAL "1")
@@ -590,6 +590,13 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
590590
get_filename_component(TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
591591
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" ABSOLUTE)
592592
target_link_directories(${target} PUBLIC ${TOOLCHAIN_LIB_DIR})
593+
else()
594+
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
595+
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
596+
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
597+
target_link_directories(${target} PRIVATE ${host_lib_dir})
598+
599+
set(swift_runtime_rpath "${host_lib_dir}")
593600
endif()
594601
endif()
595602
endif()
@@ -926,10 +933,17 @@ function(add_swift_host_tool executable)
926933
endif()
927934
endif()
928935

929-
set_property(
930-
TARGET ${executable}
931-
APPEND PROPERTY INSTALL_RPATH
932-
"@executable_path/../${extra_relative_rpath}lib/swift/host")
936+
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
937+
set_property(
938+
TARGET ${executable}
939+
APPEND PROPERTY INSTALL_RPATH
940+
"@executable_path/../${extra_relative_rpath}lib/swift/host")
941+
else()
942+
set_property(
943+
TARGET ${executable}
944+
APPEND PROPERTY INSTALL_RPATH
945+
"$ORIGIN/../${extra_relative_rpath}lib/swift/host")
946+
endif()
933947
endif()
934948

935949
if(ASHT_THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)

0 commit comments

Comments
 (0)