Skip to content

Commit 52593c5

Browse files
committed
build: enable handling of alpine-linux-musl triple
Currently, when building LLVM/clang on Alpine Linux, CMake toolchain file specifies incorrect `<cpu_arch>-unknown-linux-musl` target, which makes the build immediately fail. Correct target that allows building on Alpine should be specified as `<cpu_arch>-alpine-linux-musl`, with `<cpu_arch>` replaced with respective CPU platform, e.g. `aarch64`.
1 parent be972c2 commit 52593c5

File tree

1 file changed

+22
-7
lines changed
  • utils/swift_build_support/swift_build_support/products

1 file changed

+22
-7
lines changed

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def generate_darwin_toolchain_file(self, platform, arch):
301301

302302
return toolchain_file
303303

304-
def get_linux_abi(self, arch):
304+
def get_linux_target_components(self, arch):
305305
# Map tuples of (platform, arch) to ABI
306306
#
307307
# E.x.: Hard ABI or Soft ABI for Linux map to gnueabihf
@@ -310,22 +310,37 @@ def get_linux_abi(self, arch):
310310
'armv7': ('arm', 'gnueabihf')
311311
}
312312

313-
# Default is just arch, gnu
314-
sysroot_arch, abi = arch_platform_to_abi.get(arch, (arch, 'gnu'))
315-
return sysroot_arch, abi
313+
abi = 'gnu'
314+
vendor = 'unknown'
315+
316+
try:
317+
output = shell.capture(["clang", "--version"])
318+
319+
# clang can't handle default `*-unknown-linux-*` components on Alpine,
320+
# it needs special handling to propagate `vendor` and `abi` intact
321+
if 'alpine-linux-musl' in output:
322+
vendor = 'alpine'
323+
abi = 'musl'
324+
325+
sysroot_arch, abi = arch_platform_to_abi.get(arch, (arch, abi))
326+
327+
except BaseException:
328+
# Default is just arch, gnu
329+
sysroot_arch, abi = arch_platform_to_abi.get(arch, (arch, abi))
330+
return sysroot_arch, vendor, abi
316331

317332
def get_linux_sysroot(self, platform, arch):
318333
if not self.is_cross_compile_target('{}-{}'.format(platform, arch)):
319334
return None
320-
sysroot_arch, abi = self.get_linux_abi(arch)
335+
sysroot_arch, abi = self.get_linux_target_components(arch)
321336
# $ARCH-$PLATFORM-$ABI
322337
# E.x.: aarch64-linux-gnu
323338
sysroot_dirname = '{}-{}-{}'.format(sysroot_arch, platform, abi)
324339
return os.path.join(os.sep, 'usr', sysroot_dirname)
325340

326341
def get_linux_target(self, platform, arch):
327-
sysroot_arch, abi = self.get_linux_abi(arch)
328-
return '{}-unknown-linux-{}'.format(sysroot_arch, abi)
342+
sysroot_arch, vendor, abi = self.get_linux_target_components(arch)
343+
return '{}-{}-linux-{}'.format(sysroot_arch, vendor, abi)
329344

330345
def generate_linux_toolchain_file(self, platform, arch):
331346
shell.makedirs(self.build_dir)

0 commit comments

Comments
 (0)