Skip to content

Commit eca1759

Browse files
committed
On ELF platforms, add a runpath to an architecture-specific directory for the runtime libraries.
This is needed for swiftlang/swift#63782, which changes the Unix toolchain to look for libraries in architecture-specific directories. I also updated some checks for the runtime target triple, rather than checking the host system, and removed unnecessary regex checking.
1 parent 72020de commit eca1759

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

build-script-helper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import json
2020
import sys
2121
import os, platform
22-
import re
2322
import subprocess
2423

2524
def printerr(message):
@@ -159,7 +158,10 @@ def get_swiftpm_options(action, args):
159158
if args.verbose or action == 'install':
160159
swiftpm_args += ['--verbose']
161160

162-
if platform.system() == 'Darwin':
161+
build_target = get_build_target(args)
162+
build_arch = build_target.split('-')[0]
163+
build_os = build_target.split('-')[2]
164+
if build_os.startswith('macosx'):
163165
swiftpm_args += [
164166
# Relative library rpath for swift; will only be used when /usr/lib/swift
165167
# is not available.
@@ -168,13 +170,12 @@ def get_swiftpm_options(action, args):
168170
else:
169171
swiftpm_args += [
170172
# Library rpath for swift, dispatch, Foundation, etc. when installing
171-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
173+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch,
172174
]
173175

174-
build_target = get_build_target(args)
175176
cross_compile_hosts = args.cross_compile_hosts
176177
if cross_compile_hosts:
177-
if re.search('-apple-macosx', build_target) and re.match('macosx-', cross_compile_hosts):
178+
if build_os.startswith('macosx') and cross_compile_hosts.startswith('macosx-'):
178179
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
179180
else:
180181
printerr("cannot cross-compile for %s" % cross_compile_hosts)
@@ -290,7 +291,7 @@ def get_build_target(args):
290291
command = [args.swift_exec, '-print-target-info']
291292
target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip()
292293
args.target_info = json.loads(target_info_json)
293-
if platform.system() == 'Darwin':
294+
if '-apple-macosx' in args.target_info["target"]["unversionedTriple"]:
294295
return args.target_info["target"]["unversionedTriple"]
295296

296297
return args.target_info["target"]["triple"]

0 commit comments

Comments
 (0)