Skip to content

Commit a77fcd5

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 2c1ac12 commit a77fcd5

File tree

7 files changed

+51
-16
lines changed

7 files changed

+51
-16
lines changed

utils/build_swift/build_swift/driver_arguments.py

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

680+
option('--cross-compile-build-swift-tools', toggle_true,
681+
default=True,
682+
help="Cross-compile the Swift compiler, other host tools from the "
683+
"compiler repository, and various macros for each listed "
684+
"--cross-compile-hosts platform.")
685+
680686
option('--stdlib-deployment-targets', store,
681687
type=argparse.ShellSplitType(),
682688
default=None,

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
'compiler_vendor': defaults.COMPILER_VENDOR,
156156
'coverage_db': None,
157157
'cross_compile_append_host_target_to_destdir': True,
158+
'cross_compile_build_swift_tools': True,
158159
'cross_compile_deps_path': None,
159160
'cross_compile_hosts': [],
160161
'infer_cross_compile_hosts_on_darwin': False,
@@ -622,6 +623,7 @@ class BuildScriptImplOption(_BaseOption):
622623
EnableOption('--build-swift-clang-overlays'),
623624
EnableOption('--build-swift-remote-mirror'),
624625
EnableOption('--cross-compile-append-host-target-to-destdir'),
626+
EnableOption('--cross-compile-build-swift-tools'),
625627
EnableOption('--color-in-tests'),
626628
EnableOption('--distcc'),
627629
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
@@ -24,7 +24,7 @@ def is_verbose(self):
2424
return self.args.verbose_build
2525

2626
def build_with_cmake(self, build_targets, build_type, build_args,
27-
prefer_native_toolchain=False):
27+
prefer_native_toolchain=False, build_llvm=True):
2828
assert self.toolchain.cmake is not None
2929
cmake_build = []
3030
_cmake = cmake.CMake(self.args, self.toolchain,
@@ -71,9 +71,7 @@ def build_with_cmake(self, build_targets, build_type, build_args,
7171
env=env)
7272

7373
is_llvm = self.product_name() == "llvm"
74-
if (not is_llvm and not self.args.skip_build) or (
75-
is_llvm and self.args._build_llvm
76-
):
74+
if (not is_llvm and not self.args.skip_build) or (is_llvm and build_llvm):
7775
cmake_opts = [self.build_dir, "--config", build_type]
7876

7977
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
@@ -249,10 +249,13 @@ def build(self, host_target):
249249
# space/time efficient than -g on that platform.
250250
llvm_cmake_options.define('LLVM_USE_SPLIT_DWARF:BOOL', 'YES')
251251

252-
if not self.args._build_llvm:
252+
build = True
253+
if not self.args._build_llvm or (not self.args.cross_compile_build_swift_tools
254+
and self.is_cross_compile_target(host_target)):
253255
# Indicating we don't want to build LLVM at all should
254256
# override everything.
255257
build_targets = []
258+
build = False
256259
elif self.args.skip_build or not self.args.build_llvm:
257260
# We can't skip the build completely because the standalone
258261
# build of Swift depends on these.
@@ -399,7 +402,8 @@ def build(self, host_target):
399402

400403
self._handle_cxx_headers(host_target, platform)
401404

402-
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
405+
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [],
406+
build_llvm=build)
403407

404408
# copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
405409
# that Swift's stdlib can use compiler-rt builtins when targeting
@@ -484,7 +488,9 @@ def should_install(self, host_target):
484488
Whether or not this product should be installed with the given
485489
arguments.
486490
"""
487-
return self.args.install_llvm
491+
return self.args.install_llvm and (
492+
self.args.cross_compile_build_swift_tools or
493+
not self.is_cross_compile_target(host_target))
488494

489495
def install(self, host_target):
490496
"""

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

0 commit comments

Comments
 (0)