diff --git a/utils/build-script-impl b/utils/build-script-impl index 097cb6b981ced..50d93594c899b 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -1117,7 +1117,7 @@ function false_true() { CROSS_COMPILE_HOSTS=($CROSS_COMPILE_HOSTS) for t in "${CROSS_COMPILE_HOSTS[@]}"; do case ${t} in - macosx* | iphone* | appletv* | watch* | linux-armv5 | linux-armv6 | linux-armv7 | android-* | openbsd-* | linux-static-* ) + macosx* | iphone* | appletv* | watch* | android-* | openbsd-* | linux-* | linux-static-* ) ;; *) echo "Unknown host to cross-compile for: ${t}" diff --git a/utils/swift_build_support/swift_build_support/products/product.py b/utils/swift_build_support/swift_build_support/products/product.py index 8e675f228a29f..2cee987ba5366 100644 --- a/utils/swift_build_support/swift_build_support/products/product.py +++ b/utils/swift_build_support/swift_build_support/products/product.py @@ -379,6 +379,11 @@ def get_linux_target_components(self, arch): def get_linux_sysroot(self, platform, arch): if not self.is_cross_compile_target('{}-{}'.format(platform, arch)): return None + + # If the deps path was passed, use it instead + if self.args.cross_compile_deps_path: + return self.args.cross_compile_deps_path + sysroot_arch, _, abi = self.get_linux_target_components(arch) # $ARCH-$PLATFORM-$ABI # E.x.: aarch64-linux-gnu @@ -479,6 +484,11 @@ def common_cross_c_flags(self, platform, arch, include_arch=False): if self.is_release(): cross_flags.append('-fno-stack-protector') + # Use lld when cross-compiling to a Linux arch + if (self.is_cross_compile_target("{}-{}".format(platform, arch)) + and platform == 'linux'): + cross_flags.append('-w -fuse-ld=lld') + return self.common_c_flags + cross_flags diff --git a/utils/swift_build_support/tests/products/test_llvm_linux_cross_compile.py b/utils/swift_build_support/tests/products/test_llvm_linux_cross_compile.py index 1691c3eae78fd..df64a6ebbfd7b 100644 --- a/utils/swift_build_support/tests/products/test_llvm_linux_cross_compile.py +++ b/utils/swift_build_support/tests/products/test_llvm_linux_cross_compile.py @@ -40,7 +40,8 @@ def setUp(self): clang_compiler_version=None, clang_user_visible_version=None, cross_compile_hosts='linux-aarch64', - cross_compile_deps_path='sysroot' + cross_compile_deps_path=None, + build_variant='Release' ) # Setup shell @@ -59,7 +60,7 @@ def tearDown(self): self.toolchain = None self.args = None - def test_llvm_get_linux_sysroot(self): + def test_llvm_get_linux_sysroot_default(self): llvm = LLVM( args=self.args, toolchain=self.toolchain, @@ -67,3 +68,30 @@ def test_llvm_get_linux_sysroot(self): build_dir='/path/to/build') expected_arg = '/usr/aarch64-linux-gnu' self.assertIn(expected_arg, llvm.get_linux_sysroot("linux", "aarch64")) + + def test_llvm_get_linux_sysroot_external(self): + self.args = argparse.Namespace( + llvm_targets_to_build='X86;ARM;AArch64', + llvm_assertions='true', + compiler_vendor='none', + clang_compiler_version=None, + clang_user_visible_version=None, + cross_compile_hosts='linux-armv7', + cross_compile_deps_path='sysroot' + ) + llvm = LLVM( + args=self.args, + toolchain=self.toolchain, + source_dir='/path/to/src', + build_dir='/path/to/build') + expected_arg = 'sysroot' + self.assertIn(expected_arg, llvm.get_linux_sysroot("linux", "armv7")) + + def test_llvm_c_flags_includes_lld(self): + llvm = LLVM( + args=self.args, + toolchain=self.toolchain, + source_dir='/path/to/src', + build_dir='/path/to/build') + expected_flag = '-w -fuse-ld=lld' + self.assertIn(expected_flag, llvm.llvm_c_flags("linux", "aarch64"))