Skip to content

Commit a41c369

Browse files
committed
[CMake] Fix host library builds and rpaths for testing macros
This enables running macro tests on Linux.
1 parent c9383ff commit a41c369

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
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)

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) )

0 commit comments

Comments
 (0)