Skip to content

Commit 53a1e88

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

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Utilities/build-script-helper.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ 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)
7780
if platform.system() == 'Darwin':
@@ -121,21 +124,22 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
121124
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
122125
]
123126

124-
if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
125-
'android-', args.cross_compile_host)):
127+
build_target = get_build_target(swift_exec, args, cross_compile=(True if args.cross_compile_config else False))
128+
build_arch = build_target.split('-')[0]
129+
build_os = build_target.split('-')[2]
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)