Skip to content

Commit 9322d91

Browse files
committed
[bootstrap] Add @executable_path RPATH on Darwin.
Add `@executable_path/../lib/swift/<platform>` RPATH on Darwin platforms. This is necessary for experimental toolchains that include libraries not part of the OS (e.g. `PythonKit` or `TensorFlow`). Verified to fix SwiftPM command linker issues for Swift for TensorFlow toolchains: tensorflow/swift#347. Effectively reverts swiftlang#2548: an unverified fix for the same issue that did not work.
1 parent cc2acb0 commit 9322d91

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

Utilities/bootstrap

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -547,27 +547,40 @@ def get_swiftpm_flags(args):
547547
"-Xlinker", "-rpath",
548548
"-Xlinker", "@executable_path/../../../../../SharedFrameworks",
549549

550-
# For TensorFlow.
551-
"-Xlinker", "-rpath",
552-
"-Xlinker", "@executable_path/../lib/swift/macosx",
553-
554550
# For LLBuild in CLT.
555551
"-Xlinker", "-rpath",
556552
"-Xlinker", "@executable_path/../lib/swift/pm/llbuild",
557553
])
558554

559-
# Add a relative rpath to find core Swift libraries on non-Darwin platforms,
560-
# where they aren't present as part of the base OS.
561-
if platform.system() != 'Darwin':
562-
platform_path = None
563-
for path in args.target_info["paths"]["runtimeLibraryPaths"]:
564-
platform_path = re.search(r'(lib/swift/[^/]+)$', path)
565-
if platform_path:
566-
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../" + platform_path.group(1)])
567-
break
568-
569-
if not platform_path:
570-
error("the command `%s -print-target-info` didn't return a valid runtime library path" % args.swiftc_path)
555+
# Add a relative rpath to find Swift libraries in toolchains.
556+
# On non-Darwin platforms, a relative rpath is necessary because Swift
557+
# libraries are not part of the OS.
558+
# On Darwin platforms, a relative rpath is necessary for experimental
559+
# toolchains that include libraries not part of the OS (e.g. PythonKit or
560+
# TensorFlow).
561+
if platform.system() == "Darwin":
562+
swift_library_rpath_prefix = "@executable_path/../"
563+
else:
564+
swift_library_rpath_prefix = "$ORIGIN/../"
565+
platform_path = None
566+
for path in args.target_info["paths"]["runtimeLibraryPaths"]:
567+
platform_path = re.search(r"(lib/swift/[^/]+)$", path)
568+
if platform_path:
569+
build_flags.extend(
570+
[
571+
"-Xlinker",
572+
"-rpath",
573+
"-Xlinker",
574+
swift_library_rpath_prefix + platform_path.group(1),
575+
]
576+
)
577+
break
578+
579+
if not platform_path:
580+
error(
581+
"the command `%s -print-target-info` didn't return a valid runtime library path"
582+
% args.swiftc_path
583+
)
571584

572585
# Don't use GNU strerror_r on Android.
573586
if 'ANDROID_DATA' in os.environ:

0 commit comments

Comments
 (0)