Skip to content

Commit 56214dc

Browse files
committed
[build] Make the new --cross-compile-build-swift-tools flag public
This new flag makes it easy to build Swift cross-compilation toolchains, by disabling cross-compilation of all host tools, like the Swift compiler and various macros, building on prior pulls #38441 and #82163. Also, add two class methods to the Testing macros product so it works with #83260.
1 parent 3d6c240 commit 56214dc

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,12 @@ def create_argument_parser():
689689
"for each cross-compiled toolchain's destdir, useful when building "
690690
"multiple toolchains and can be disabled if only cross-compiling one.")
691691

692+
option('--cross-compile-build-swift-tools', toggle_true,
693+
default=True,
694+
help="Cross-compile the Swift compiler, other host tools from the "
695+
"compiler repository, and various macros for each listed "
696+
"--cross-compile-hosts platform.")
697+
692698
option('--stdlib-deployment-targets', store,
693699
type=argparse.ShellSplitType(),
694700
default=None,

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
'compiler_vendor': defaults.COMPILER_VENDOR,
157157
'coverage_db': None,
158158
'cross_compile_append_host_target_to_destdir': True,
159+
'cross_compile_build_swift_tools': True,
159160
'cross_compile_deps_path': None,
160161
'cross_compile_hosts': [],
161162
'infer_cross_compile_hosts_on_darwin': False,
@@ -628,6 +629,7 @@ class BuildScriptImplOption(_BaseOption):
628629
EnableOption('--build-swift-clang-overlays'),
629630
EnableOption('--build-swift-remote-mirror'),
630631
EnableOption('--cross-compile-append-host-target-to-destdir'),
632+
EnableOption('--cross-compile-build-swift-tools'),
631633
EnableOption('--color-in-tests'),
632634
EnableOption('--distcc'),
633635
EnableOption('--sccache'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def convert_to_impl_arguments(self):
119119
"--cmake-generator", args.cmake_generator,
120120
"--cross-compile-append-host-target-to-destdir", str(
121121
args.cross_compile_append_host_target_to_destdir).lower(),
122+
"--cross-compile-build-swift-tools", str(
123+
args.cross_compile_build_swift_tools).lower(),
122124
"--build-jobs", str(args.build_jobs),
123125
"--lit-jobs", str(args.lit_jobs),
124126
"--common-cmake-options=%s" % ' '.join(

utils/swift_build_support/swift_build_support/products/cmake_product.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def is_verbose(self):
2525

2626
def build_with_cmake(self, build_targets, build_type, build_args,
2727
prefer_native_toolchain=False,
28-
ignore_extra_cmake_options=False):
28+
ignore_extra_cmake_options=False, build_llvm=True):
2929
assert self.toolchain.cmake is not None
3030
cmake_build = []
3131
_cmake = cmake.CMake(self.args, self.toolchain,
@@ -73,9 +73,7 @@ def build_with_cmake(self, build_targets, build_type, build_args,
7373
env=env)
7474

7575
is_llvm = self.product_name() == "llvm"
76-
if (not is_llvm and not self.args.skip_build) or (
77-
is_llvm and self.args._build_llvm
78-
):
76+
if (not is_llvm and not self.args.skip_build) or (is_llvm and build_llvm):
7977
cmake_opts = [self.build_dir, "--config", build_type]
8078

8179
shell.call(

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,13 @@ def build(self, host_target):
251251
# space/time efficient than -g on that platform.
252252
llvm_cmake_options.define('LLVM_USE_SPLIT_DWARF:BOOL', 'YES')
253253

254-
if not self.args._build_llvm:
254+
build = True
255+
if not self.args._build_llvm or (not self.args.cross_compile_build_swift_tools
256+
and self.is_cross_compile_target(host_target)):
255257
# Indicating we don't want to build LLVM at all should
256258
# override everything.
257259
build_targets = []
260+
build = False
258261
elif self.args.skip_build or not self.args.build_llvm:
259262
# We can't skip the build completely because the standalone
260263
# build of Swift depends on these.
@@ -456,7 +459,8 @@ def build(self, host_target):
456459

457460
self._handle_cxx_headers(host_target, platform)
458461

459-
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
462+
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [],
463+
build_llvm=build)
460464

461465
# copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
462466
# that Swift's stdlib can use compiler-rt builtins when targeting
@@ -541,7 +545,9 @@ def should_install(self, host_target):
541545
Whether or not this product should be installed with the given
542546
arguments.
543547
"""
544-
return self.args.install_llvm
548+
return self.args.install_llvm and (
549+
self.args.cross_compile_build_swift_tools or
550+
not self.is_cross_compile_target(host_target))
545551

546552
def install(self, host_target):
547553
"""

utils/swift_build_support/swift_build_support/products/swift_testing_macros.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ def should_clean(self, host_target):
4242
return True
4343

4444
def should_build(self, host_target):
45-
return True
45+
build_macros = not self.is_cross_compile_target(host_target) or \
46+
self.args.cross_compile_build_swift_tools
47+
if not build_macros:
48+
print("Skipping building Testing Macros for %s, because the host tools "
49+
"are not being built" % host_target)
50+
return build_macros
4651

4752
def should_test(self, host_target):
4853
return False
4954

5055
def should_install(self, host_target):
51-
return self.args.install_swift_testing_macros
56+
install_macros = self.args.install_swift_testing_macros and \
57+
(not self.is_cross_compile_target(host_target) or
58+
self.args.cross_compile_build_swift_tools)
59+
if self.args.install_swift_testing_macros and not install_macros:
60+
print("Skipping installing Testing Macros for %s, because the host tools "
61+
"are not being built" % host_target)
62+
return install_macros
5263

5364
def _cmake_product(self, host_target):
5465
build_root = os.path.dirname(self.build_dir)
@@ -121,3 +132,11 @@ def install(self, host_target):
121132
install_prefix = install_destdir + self.args.install_prefix
122133

123134
self.install_with_cmake(['install'], install_prefix)
135+
136+
@classmethod
137+
def is_build_script_impl_product(cls):
138+
return False
139+
140+
@classmethod
141+
def is_before_build_script_impl_product(cls):
142+
return False
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# REQUIRES: standalone_build
2-
# UNSUPPORTED: OS=macosx
3-
# UNSUPPORTED: OS=ios
4-
# UNSUPPORTED: OS=tvos
5-
# UNSUPPORTED: OS=watchos
62

73
# RUN: %empty-directory(%t)
8-
# 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
4+
# 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
95

10-
# CHECK: -DCMAKE_Swift_FLAGS{{.*}}-target {{.*}}unknown-linux-android{{.*}} -sdk
11-
# CHECK: -DCMAKE_SYSTEM_NAME=Android {{.*}} -DCMAKE_ANDROID_NDK
6+
# CHECK: pushd {{.*}}/llvm-android-aarch64
7+
# CHECK-NOT: cmake --build {{.*}}/llvm-android-aarch64 --config
8+
# CHECK-NOT: cmake --build {{.*}}/llvm-android-aarch64 {{.*}} install-llvm
9+
# CHECK: cmake {{.*}}-DSWIFT_INCLUDE_TOOLS:BOOL=FALSE{{.*}}/swift
10+
# CHECK: Skipping building Testing Macros for android-aarch64, because the host tools are not being built
11+
# CHECK: Skipping installing Testing Macros for android-aarch64, because the host tools are not being built
12+
# CHECK: cmake {{.*}}-DCMAKE_TOOLCHAIN_FILE:PATH={{.*}}swifttesting-android-aarch64/BuildScriptToolchain.cmake
13+
# CHECK: -DCMAKE_Swift_FLAGS=-target aarch64-unknown-linux-android{{.*}} -sdk

validation-test/BuildSystem/skip_clean_corelibs.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# REQUIRES: standalone_build
22
# UNSUPPORTED: OS=macosx
3-
# UNSUPPORTED: OS=ios
4-
# UNSUPPORTED: OS=tvos
5-
# UNSUPPORTED: OS=watchos
6-
# UNSUPPORTED: OS=xros
73
#
84
# RUN: %empty-directory(%t)
95
# RUN: mkdir -p %t

0 commit comments

Comments
 (0)