@@ -10,3 +10,151 @@ index 16e05052609..7ab8cebfab8 100755
10
10
11
11
cmake_options=(
12
12
-DENABLE_SWIFT=YES
13
+ diff --git a/swift/utils/build_swift/build_swift/driver_arguments.py b/swift/utils/build_swift/build_swift/driver_arguments.py
14
+ index 2b7d6d07799..e0d04d22825 100644
15
+ --- a/swift/utils/build_swift/build_swift/driver_arguments.py
16
+ +++ b/swift/utils/build_swift/build_swift/driver_arguments.py
17
+ @@ -677,6 +677,12 @@ def create_argument_parser():
18
+ "for each cross-compiled toolchain's destdir, useful when building "
19
+ "multiple toolchains and can be disabled if only cross-compiling one.")
20
+
21
+ + option('--cross-compile-build-swift-tools', toggle_true,
22
+ + default=True,
23
+ + help="Cross-compile the Swift compiler, other host tools from the "
24
+ + "compiler repository, and various macros for each listed "
25
+ + "--cross-compile-hosts platform.")
26
+ +
27
+ option('--stdlib-deployment-targets', store,
28
+ type=argparse.ShellSplitType(),
29
+ default=None,
30
+ diff --git a/swift/utils/build_swift/tests/expected_options.py b/swift/utils/build_swift/tests/expected_options.py
31
+ index f8d1a3526ed..b655d610923 100644
32
+ --- a/swift/utils/build_swift/tests/expected_options.py
33
+ +++ b/swift/utils/build_swift/tests/expected_options.py
34
+ @@ -155,6 +155,7 @@ EXPECTED_DEFAULTS = {
35
+ 'compiler_vendor': defaults.COMPILER_VENDOR,
36
+ 'coverage_db': None,
37
+ 'cross_compile_append_host_target_to_destdir': True,
38
+ + 'cross_compile_build_swift_tools': True,
39
+ 'cross_compile_deps_path': None,
40
+ 'cross_compile_hosts': [],
41
+ 'infer_cross_compile_hosts_on_darwin': False,
42
+ @@ -622,6 +623,7 @@ EXPECTED_OPTIONS = [
43
+ EnableOption('--build-swift-clang-overlays'),
44
+ EnableOption('--build-swift-remote-mirror'),
45
+ EnableOption('--cross-compile-append-host-target-to-destdir'),
46
+ + EnableOption('--cross-compile-build-swift-tools'),
47
+ EnableOption('--color-in-tests'),
48
+ EnableOption('--distcc'),
49
+ EnableOption('--sccache'),
50
+ diff --git a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
51
+ index a0289515fd0..355d72fe21f 100644
52
+ --- a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
53
+ +++ b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
54
+ @@ -119,6 +119,8 @@ class BuildScriptInvocation(object):
55
+ "--cmake-generator", args.cmake_generator,
56
+ "--cross-compile-append-host-target-to-destdir", str(
57
+ args.cross_compile_append_host_target_to_destdir).lower(),
58
+ + "--cross-compile-build-swift-tools", str(
59
+ + args.cross_compile_build_swift_tools).lower(),
60
+ "--build-jobs", str(args.build_jobs),
61
+ "--lit-jobs", str(args.lit_jobs),
62
+ "--common-cmake-options=%s" % ' '.join(
63
+ diff --git a/swift/utils/swift_build_support/swift_build_support/products/cmake_product.py b/swift/utils/swift_build_support/swift_build_support/products/cmake_product.py
64
+ index dc338334f28..f1a9f4d28bf 100644
65
+ --- a/swift/utils/swift_build_support/swift_build_support/products/cmake_product.py
66
+ +++ b/swift/utils/swift_build_support/swift_build_support/products/cmake_product.py
67
+ @@ -71,9 +71,7 @@ class CMakeProduct(product.Product):
68
+ env=env)
69
+
70
+ is_llvm = self.product_name() == "llvm"
71
+ - if (not is_llvm and not self.args.skip_build) or (
72
+ - is_llvm and self.args._build_llvm
73
+ - ):
74
+ + if (not is_llvm and not self.args.skip_build) or (is_llvm and build_llvm):
75
+ cmake_opts = [self.build_dir, "--config", build_type]
76
+
77
+ shell.call(
78
+ diff --git a/swift/utils/swift_build_support/swift_build_support/products/llvm.py b/swift/utils/swift_build_support/swift_build_support/products/llvm.py
79
+ index ffae1d66702..72e400c55be 100644
80
+ --- a/swift/utils/swift_build_support/swift_build_support/products/llvm.py
81
+ +++ b/swift/utils/swift_build_support/swift_build_support/products/llvm.py
82
+ @@ -249,10 +249,13 @@ class LLVM(cmake_product.CMakeProduct):
83
+ # space/time efficient than -g on that platform.
84
+ llvm_cmake_options.define('LLVM_USE_SPLIT_DWARF:BOOL', 'YES')
85
+
86
+ - if not self.args._build_llvm:
87
+ + build = True
88
+ + if not self.args._build_llvm or (not self.args.cross_compile_build_swift_tools
89
+ + and self.is_cross_compile_target(host_target)):
90
+ # Indicating we don't want to build LLVM at all should
91
+ # override everything.
92
+ build_targets = []
93
+ + build = False
94
+ elif self.args.skip_build or not self.args.build_llvm:
95
+ # We can't skip the build completely because the standalone
96
+ # build of Swift depends on these.
97
+ @@ -399,7 +402,8 @@ class LLVM(cmake_product.CMakeProduct):
98
+
99
+ self._handle_cxx_headers(host_target, platform)
100
+
101
+ - self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
102
+ + self.build_with_cmake(build_targets, self.args.llvm_build_variant, [],
103
+ + build_llvm=build)
104
+
105
+ # copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
106
+ # that Swift's stdlib can use compiler-rt builtins when targeting
107
+ @@ -484,7 +488,9 @@ class LLVM(cmake_product.CMakeProduct):
108
+ Whether or not this product should be installed with the given
109
+ arguments.
110
+ """
111
+ - return self.args.install_llvm
112
+ + return self.args.install_llvm and (
113
+ + self.args.cross_compile_build_swift_tools or
114
+ + not self.is_cross_compile_target(host_target))
115
+
116
+ def install(self, host_target):
117
+ """
118
+ diff --git a/swift/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py b/swift/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py
119
+ index ddb3b553de7..d127424709c 100644
120
+ --- a/swift/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py
121
+ +++ b/swift/utils/swift_build_support/swift_build_support/products/swift_testing_macros.py
122
+ @@ -42,13 +42,24 @@ class SwiftTestingMacros(product.Product):
123
+ return True
124
+
125
+ def should_build(self, host_target):
126
+ - return True
127
+ + build_macros = not self.is_cross_compile_target(host_target) or \
128
+ + self.args.cross_compile_build_swift_tools
129
+ + if not build_macros:
130
+ + print("Skipping building Testing Macros for %s, because the host tools "
131
+ + "are not being built" % host_target)
132
+ + return build_macros
133
+
134
+ def should_test(self, host_target):
135
+ return False
136
+
137
+ def should_install(self, host_target):
138
+ - return self.args.install_swift_testing_macros
139
+ + install_macros = self.args.install_swift_testing_macros and \
140
+ + (not self.is_cross_compile_target(host_target) or
141
+ + self.args.cross_compile_build_swift_tools)
142
+ + if self.args.install_swift_testing_macros and not install_macros:
143
+ + print("Skipping installing Testing Macros for %s, because the host tools "
144
+ + "are not being built" % host_target)
145
+ + return install_macros
146
+
147
+ def _cmake_product(self, host_target):
148
+ build_root = os.path.dirname(self.build_dir)
149
+ @@ -121,3 +132,11 @@ class SwiftTestingMacrosCMakeShim(cmake_product.CMakeProduct):
150
+ install_prefix = install_destdir + self.args.install_prefix
151
+
152
+ self.install_with_cmake(['install'], install_prefix)
153
+ +
154
+ + @classmethod
155
+ + def is_build_script_impl_product(cls):
156
+ + return False
157
+ +
158
+ + @classmethod
159
+ + def is_before_build_script_impl_product(cls):
160
+ + return False
0 commit comments