Skip to content

Commit e8a2d90

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 e8a2d90

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Utilities/build-script-helper.py

+10-5
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,23 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]:
121124
os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
122125
]
123126

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]
124130
if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
125131
'android-', args.cross_compile_host)):
126132
swiftpm_args += [
127-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
133+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android/' + build_arch,
128134
# SwiftPM will otherwise try to compile against GNU strerror_r on
129135
# Android and fail.
130136
'-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
131137
]
132-
elif platform.system() == 'Linux':
138+
elif platform.system() != 'Darwin':
133139
# Library rpath for swift, dispatch, Foundation, etc. when installing
134140
swiftpm_args += [
135-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
141+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os + '/' + build_arch,
136142
]
137143

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

0 commit comments

Comments
 (0)