Skip to content

Commit 55dfff1

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.
1 parent e27f9dd commit 55dfff1

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ 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:
255-
# Indicating we don't want to build LLVM at all should
256-
# override everything.
257-
build_targets = []
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)):
257+
build = False
258258
elif self.args.skip_build or not self.args.build_llvm:
259259
# We can't skip the build completely because the standalone
260260
# build of Swift depends on these.
@@ -456,7 +456,8 @@ def build(self, host_target):
456456

457457
self._handle_cxx_headers(host_target, platform)
458458

459-
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
459+
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [],
460+
build_llvm=build)
460461

461462
# copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
462463
# that Swift's stdlib can use compiler-rt builtins when targeting
@@ -541,7 +542,9 @@ def should_install(self, host_target):
541542
Whether or not this product should be installed with the given
542543
arguments.
543544
"""
544-
return self.args.install_llvm
545+
return self.args.install_llvm and (
546+
self.args.cross_compile_build_swift_tools or
547+
not self.is_cross_compile_target(host_target))
545548

546549
def install(self, host_target):
547550
"""

utils/swift_build_support/swift_build_support/products/swift_testing_macros.py

Lines changed: 13 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)

0 commit comments

Comments
 (0)