Skip to content

Commit b806b86

Browse files
authored
Merge pull request #66199 from DougGregor/cmake-host-swift-paths-linux
2 parents f20edfa + 3ca1358 commit b806b86

File tree

5 files changed

+54
-13
lines changed

5 files changed

+54
-13
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,15 @@ function(add_pure_swift_host_tool name)
261261
add_executable(${name} ${APSHT_SOURCES})
262262
_add_host_swift_compile_options(${name})
263263

264-
set_property(TARGET ${name}
265-
APPEND PROPERTY INSTALL_RPATH
266-
"@executable_path/../lib/swift/host")
264+
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
265+
set_property(TARGET ${name}
266+
APPEND PROPERTY INSTALL_RPATH
267+
"@executable_path/../lib/swift/host")
268+
else()
269+
set_property(TARGET ${name}
270+
APPEND PROPERTY INSTALL_RPATH
271+
"$ORIGIN/../lib/swift/host")
272+
endif()
267273

268274
set_property(TARGET ${name}
269275
PROPERTY BUILD_WITH_INSTALL_RPATH YES)

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)

test/Macros/macro_swiftdeps.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// RUN: split-file %s %t/src
99

10-
//#-- Prepare the macro dylib plugin.
10+
//#-- Prepare the macro shared library plugin.
1111
// RUN: %host-build-swift \
1212
// RUN: -swift-version 5 \
1313
// RUN: -emit-library -o %t/plugin/%target-library-name(MacroDefinition) \
@@ -76,7 +76,7 @@
7676
// RUN: %FileCheck --check-prefix WITHOUT_PLUGIN %s < %t/with_macro_nonprimary.swiftdeps.processed
7777

7878
// WITH_PLUGIN: externalDepend interface '' 'BUILD_DIR{{.*}}mock-plugin' false
79-
// WITH_PLUGIN: externalDepend interface '' 'BUILD_DIR{{.*}}libMacroDefinition.dylib' false
79+
// WITH_PLUGIN: externalDepend interface '' 'BUILD_DIR{{.*}}libMacroDefinition.{{(dylib|so|dll)}}' false
8080

8181
// WITHOUT_PLUGIN-NOT: MacroDefinition
8282
// WITHOUT_PLUGIN-NOT: mock-plugin

test/lit.cfg

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,16 @@ else:
548548
"env SDKROOT=%s %r -toolchain-stdlib-rpath -Xlinker -rpath -Xlinker /usr/lib/swift %s %s %s"
549549
% (shell_quote(config.host_sdkroot), config.swiftc, mcp_opt, config.swift_test_options, config.swift_driver_test_options))
550550

551+
# Parse the host triple.
552+
(host_cpu, host_vendor, host_os, host_vers) = re.match('([^-]+)-([^-]+)-([^0-9-]+)(.*)', config.host_triple).groups()
553+
554+
if platform.system() == 'Darwin':
555+
host_build_extra_rpath=""
556+
else:
557+
host_build_extra_rpath="-Xlinker -rpath -Xlinker %s" % (make_path(config.swift_lib_dir, 'swift', host_os))
558+
551559
config.host_build_swift = (
552-
"%s -sdk %s -target %s -I %s -L %s" % (config.swiftc_driver, config.host_sdkroot, config.host_triple, config.swift_host_lib_dir, config.swift_host_lib_dir)
553-
)
560+
"%s -sdk %s -target %s -I %s -L %s %s" % (config.swiftc_driver, config.host_sdkroot, config.host_triple, config.swift_host_lib_dir, config.swift_host_lib_dir, host_build_extra_rpath))
554561

555562
config.substitutions.append( ('%llvm_obj_root', config.llvm_obj_root) )
556563
config.substitutions.append( ('%swift-bin-dir', config.swift_bin_dir) )

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,17 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
153153
message(FATAL_ERROR "Unknown ASKD_BOOTSTRAPPING_MODE '${ASKD_BOOTSTRAPPING_MODE}'")
154154
endif()
155155
endif()
156-
set(RPATH_LIST ${RPATH_LIST} PARENT_SCOPE)
157156

158157
if(SWIFT_SWIFT_PARSER)
159158
# Make sure we can find the early SwiftSyntax libraries.
160159
target_link_directories(${target} PRIVATE "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host")
161160

161+
# Add rpath to the host Swift libraries.
162+
if (NOT ${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)
163+
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
164+
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
165+
endif()
166+
162167
# For the "end step" of bootstrapping configurations on Darwin, need to be
163168
# able to fall back to the SDK directory for libswiftCore et al.
164169
if (BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
@@ -173,10 +178,19 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
173178
get_filename_component(TOOLCHAIN_BIN_DIR ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
174179
get_filename_component(TOOLCHAIN_LIB_DIR "${TOOLCHAIN_BIN_DIR}/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}" ABSOLUTE)
175180
target_link_directories(${target} PUBLIC ${TOOLCHAIN_LIB_DIR})
181+
else()
182+
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
183+
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
184+
set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
185+
target_link_directories(${target} PUBLIC ${host_lib_dir})
186+
187+
list(APPEND RPATH_LIST "${host_lib_dir}")
176188
endif()
177189
endif()
178190
endif()
179191
endif()
192+
193+
set(RPATH_LIST ${RPATH_LIST} PARENT_SCOPE)
180194
endfunction()
181195

182196
# Add a new SourceKit library.

0 commit comments

Comments
 (0)