diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index e47fd450231c5..162af7d598faa 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -689,6 +689,12 @@ def create_argument_parser(): "for each cross-compiled toolchain's destdir, useful when building " "multiple toolchains and can be disabled if only cross-compiling one.") + option('--cross-compile-build-swift-tools', toggle_true, + default=True, + help="Cross-compile the Swift compiler, other host tools from the " + "compiler repository, and various macros for each listed " + "--cross-compile-hosts platform.") + option('--stdlib-deployment-targets', store, type=argparse.ShellSplitType(), default=None, diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index dddb505174e2c..6052e1f3da644 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -156,6 +156,7 @@ 'compiler_vendor': defaults.COMPILER_VENDOR, 'coverage_db': None, 'cross_compile_append_host_target_to_destdir': True, + 'cross_compile_build_swift_tools': True, 'cross_compile_deps_path': None, 'cross_compile_hosts': [], 'infer_cross_compile_hosts_on_darwin': False, @@ -628,6 +629,7 @@ class BuildScriptImplOption(_BaseOption): EnableOption('--build-swift-clang-overlays'), EnableOption('--build-swift-remote-mirror'), EnableOption('--cross-compile-append-host-target-to-destdir'), + EnableOption('--cross-compile-build-swift-tools'), EnableOption('--color-in-tests'), EnableOption('--distcc'), EnableOption('--sccache'), diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py index f4eaf537317cc..f52bf2237ef70 100644 --- a/utils/swift_build_support/swift_build_support/build_script_invocation.py +++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py @@ -119,6 +119,8 @@ def convert_to_impl_arguments(self): "--cmake-generator", args.cmake_generator, "--cross-compile-append-host-target-to-destdir", str( args.cross_compile_append_host_target_to_destdir).lower(), + "--cross-compile-build-swift-tools", str( + args.cross_compile_build_swift_tools).lower(), "--build-jobs", str(args.build_jobs), "--lit-jobs", str(args.lit_jobs), "--common-cmake-options=%s" % ' '.join( diff --git a/utils/swift_build_support/swift_build_support/products/cmake_product.py b/utils/swift_build_support/swift_build_support/products/cmake_product.py index 6d0aae3283525..3713086fec3d5 100644 --- a/utils/swift_build_support/swift_build_support/products/cmake_product.py +++ b/utils/swift_build_support/swift_build_support/products/cmake_product.py @@ -25,7 +25,7 @@ def is_verbose(self): def build_with_cmake(self, build_targets, build_type, build_args, prefer_native_toolchain=False, - ignore_extra_cmake_options=False): + ignore_extra_cmake_options=False, build_llvm=True): assert self.toolchain.cmake is not None cmake_build = [] _cmake = cmake.CMake(self.args, self.toolchain, @@ -73,9 +73,7 @@ def build_with_cmake(self, build_targets, build_type, build_args, env=env) is_llvm = self.product_name() == "llvm" - if (not is_llvm and not self.args.skip_build) or ( - is_llvm and self.args._build_llvm - ): + if (not is_llvm and not self.args.skip_build) or (is_llvm and build_llvm): cmake_opts = [self.build_dir, "--config", build_type] shell.call( diff --git a/utils/swift_build_support/swift_build_support/products/llvm.py b/utils/swift_build_support/swift_build_support/products/llvm.py index 8b137df5b2fed..15a9a236f4167 100644 --- a/utils/swift_build_support/swift_build_support/products/llvm.py +++ b/utils/swift_build_support/swift_build_support/products/llvm.py @@ -251,10 +251,13 @@ def build(self, host_target): # space/time efficient than -g on that platform. llvm_cmake_options.define('LLVM_USE_SPLIT_DWARF:BOOL', 'YES') - if not self.args._build_llvm: + build = True + if not self.args._build_llvm or (not self.args.cross_compile_build_swift_tools + and self.is_cross_compile_target(host_target)): # Indicating we don't want to build LLVM at all should # override everything. build_targets = [] + build = False elif self.args.skip_build or not self.args.build_llvm: # We can't skip the build completely because the standalone # build of Swift depends on these. @@ -456,7 +459,8 @@ def build(self, host_target): self._handle_cxx_headers(host_target, platform) - self.build_with_cmake(build_targets, self.args.llvm_build_variant, []) + self.build_with_cmake(build_targets, self.args.llvm_build_variant, [], + build_llvm=build) # copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure # that Swift's stdlib can use compiler-rt builtins when targeting @@ -541,7 +545,9 @@ def should_install(self, host_target): Whether or not this product should be installed with the given arguments. """ - return self.args.install_llvm + return self.args.install_llvm and ( + self.args.cross_compile_build_swift_tools or + not self.is_cross_compile_target(host_target)) def install(self, host_target): """ diff --git a/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py b/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py index ddb3b553de734..d127424709c57 100644 --- a/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py +++ b/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py @@ -42,13 +42,24 @@ def should_clean(self, host_target): return True def should_build(self, host_target): - return True + build_macros = not self.is_cross_compile_target(host_target) or \ + self.args.cross_compile_build_swift_tools + if not build_macros: + print("Skipping building Testing Macros for %s, because the host tools " + "are not being built" % host_target) + return build_macros def should_test(self, host_target): return False def should_install(self, host_target): - return self.args.install_swift_testing_macros + install_macros = self.args.install_swift_testing_macros and \ + (not self.is_cross_compile_target(host_target) or + self.args.cross_compile_build_swift_tools) + if self.args.install_swift_testing_macros and not install_macros: + print("Skipping installing Testing Macros for %s, because the host tools " + "are not being built" % host_target) + return install_macros def _cmake_product(self, host_target): build_root = os.path.dirname(self.build_dir) @@ -121,3 +132,11 @@ def install(self, host_target): install_prefix = install_destdir + self.args.install_prefix self.install_with_cmake(['install'], install_prefix) + + @classmethod + def is_build_script_impl_product(cls): + return False + + @classmethod + def is_before_build_script_impl_product(cls): + return False diff --git a/validation-test/BuildSystem/android_cross_compile.test b/validation-test/BuildSystem/android_cross_compile.test index 8396568dce764..a371bcc47722b 100644 --- a/validation-test/BuildSystem/android_cross_compile.test +++ b/validation-test/BuildSystem/android_cross_compile.test @@ -1,11 +1,13 @@ # REQUIRES: standalone_build -# UNSUPPORTED: OS=macosx -# UNSUPPORTED: OS=ios -# UNSUPPORTED: OS=tvos -# UNSUPPORTED: OS=watchos # RUN: %empty-directory(%t) -# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake --libdispatch --cross-compile-hosts=android-aarch64 --skip-local-build --android --android-ndk %t/ndk/ --android-arch aarch64 2>&1 | %FileCheck %s +# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake --swift-testing --swift-testing-macros --install-swift-testing-macros --install-llvm --cross-compile-hosts=android-aarch64 --cross-compile-build-swift-tools=False --android --android-ndk %t/ndk/ --android-arch aarch64 2>&1 | %FileCheck %s -# CHECK: -DCMAKE_Swift_FLAGS{{.*}}-target {{.*}}unknown-linux-android{{.*}} -sdk -# CHECK: -DCMAKE_SYSTEM_NAME=Android {{.*}} -DCMAKE_ANDROID_NDK +# CHECK: pushd {{.*}}/llvm-android-aarch64 +# CHECK-NOT: cmake --build {{.*}}/llvm-android-aarch64 --config +# CHECK-NOT: cmake --build {{.*}}/llvm-android-aarch64 {{.*}} install-llvm +# CHECK: cmake {{.*}}-DSWIFT_INCLUDE_TOOLS:BOOL=FALSE{{.*}}/swift +# CHECK: Skipping building Testing Macros for android-aarch64, because the host tools are not being built +# CHECK: Skipping installing Testing Macros for android-aarch64, because the host tools are not being built +# CHECK: cmake {{.*}}-DCMAKE_TOOLCHAIN_FILE:PATH={{.*}}swifttesting-android-aarch64/BuildScriptToolchain.cmake +# CHECK: -DCMAKE_Swift_FLAGS=-target aarch64-unknown-linux-android{{.*}} -sdk