Skip to content

Commit f527cb6

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.
1 parent 24ce1be commit f527cb6

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Utilities/build-script-helper.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ def swiftpm_bin_path(swift_exec: str, swiftpm_args: List[str], additional_env: D
6868
return check_output(cmd, additional_env=additional_env, capture_stderr=False, verbose=verbose).strip()
6969

7070

71-
def get_build_target(swift_exec: str, args: argparse.Namespace) -> str:
71+
def get_build_target(swift_exec: str, args: argparse.Namespace, cross_compile: bool = False) -> str:
7272
"""Returns the target-triple of the current machine or for cross-compilation."""
7373
try:
7474
command = [swift_exec, '-print-target-info']
75+
if cross_compile:
76+
cross_compile_json = json.load(open(args.cross_compile_config))
77+
command += ['-target', cross_compile_json["target"]]
7578
target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip()
7679
args.target_info = json.loads(target_info_json)
77-
if platform.system() == 'Darwin':
80+
if re.search('-apple-macosx', args.target_info["target"]["unversionedTriple"]):
7881
return args.target_info["target"]["unversionedTriple"]
7982
return args.target_info["target"]["triple"]
8083
except Exception as e:
@@ -105,7 +108,10 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
105108
for san in args.sanitize:
106109
swiftpm_args += ['--sanitize=%s' % san]
107110

108-
if platform.system() == 'Darwin':
111+
build_target = get_build_target(swift_exec, args, cross_compile=(True if args.cross_compile_config else False))
112+
build_arch = build_target.split('-')[0]
113+
build_os = build_target.split('-')[2]
114+
if re.search('-apple-macosx', build_target):
109115
swiftpm_args += [
110116
'-Xlinker', '-rpath', '-Xlinker', '/usr/lib/swift',
111117
'-Xlinker', '-rpath', '-Xlinker', '@executable_path/../lib/swift/macosx',
@@ -121,21 +127,19 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
121127
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
122128
]
123129

124-
if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
125-
'android-', args.cross_compile_host)):
130+
if re.search('-android', build_target):
126131
swiftpm_args += [
127-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
132+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android/' + build_arch,
128133
# SwiftPM will otherwise try to compile against GNU strerror_r on
129134
# Android and fail.
130135
'-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
131136
]
132-
elif platform.system() == 'Linux':
137+
elif not re.search('-apple-macosx', build_target):
133138
# Library rpath for swift, dispatch, Foundation, etc. when installing
134139
swiftpm_args += [
135-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
140+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch,
136141
]
137142

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

0 commit comments

Comments
 (0)