Skip to content

Commit

Permalink
On ELF platforms, add a runpath to an architecture-specific directory…
Browse files Browse the repository at this point in the history
… for the runtime libraries.

This is needed for swiftlang/swift#63782, which changes the Unix toolchain to look
for libraries in architecture-specific directories.
  • Loading branch information
finagolfin committed Feb 23, 2023
1 parent 24ce1be commit 4bbc021
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Utilities/build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def swiftpm_bin_path(swift_exec: str, swiftpm_args: List[str], additional_env: D
return check_output(cmd, additional_env=additional_env, capture_stderr=False, verbose=verbose).strip()


def get_build_target(swift_exec: str, args: argparse.Namespace) -> str:
def get_build_target(swift_exec: str, args: argparse.Namespace, cross_compile: bool = False) -> str:
"""Returns the target-triple of the current machine or for cross-compilation."""
try:
command = [swift_exec, '-print-target-info']
if cross_compile:
cross_compile_json = json.load(open(args.cross_compile_config))
command += ['-target', cross_compile_json["target"]]
target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip()
args.target_info = json.loads(target_info_json)
if platform.system() == 'Darwin':
Expand Down Expand Up @@ -121,21 +124,23 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
]

build_target = get_build_target(swift_exec, args, cross_compile=(True if args.cross_compile_config else False))
build_arch = build_target.split('-')[0]
build_os = build_target.split('-')[2]
if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
'android-', args.cross_compile_host)):
swiftpm_args += [
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android/' + build_arch,
# SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
'-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
]
elif platform.system() == 'Linux':
elif not re.search('-apple-macosx', build_target):
# Library rpath for swift, dispatch, Foundation, etc. when installing
swiftpm_args += [
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch,
]

build_target = get_build_target(swift_exec, args)
if args.cross_compile_host:
if re.search('-apple-macosx', build_target) and re.match('macosx-', args.cross_compile_host):
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
Expand Down

0 comments on commit 4bbc021

Please sign in to comment.