Skip to content

Commit 376e216

Browse files
authored
Merge pull request #71042 from ahoppen/ahoppen/cross-compile-swiftformat
[build] Support cross-compilation of swift-format
2 parents ece521c + acad2bf commit 376e216

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

utils/swift_build_support/swift_build_support/products/swiftformat.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from . import swiftsyntax
2828
from . import xctest
2929
from .. import shell
30+
from .. import targets
3031

3132

3233
class SwiftFormat(product.Product):
@@ -57,23 +58,41 @@ def run_build_script_helper(self, action, host_target, additional_params=[]):
5758
script_path = os.path.join(
5859
self.source_dir, 'build-script-helper.py')
5960

60-
install_destdir = self.host_install_destdir(host_target)
61-
6261
helper_cmd = [
6362
script_path,
6463
action,
6564
'--toolchain', self.install_toolchain_path(host_target),
6665
'--configuration', self.configuration(),
6766
'--build-path', self.build_dir,
6867
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
69-
# There might have been a Package.resolved created by other builds
70-
# or by the package being opened using Xcode. Discard that and
71-
# reset the dependencies to be local.
72-
'--update'
7368
]
74-
helper_cmd.extend([
75-
'--prefix', install_destdir + self.args.install_prefix
76-
])
69+
70+
install_destdir = self.host_install_destdir(host_target)
71+
toolchain_path = self.native_toolchain_path(host_target)
72+
73+
# Pass Cross compile host info unless we're testing.
74+
# It doesn't make sense to run tests of the cross compile host.
75+
if self.has_cross_compile_hosts() and action != 'test':
76+
if self.is_darwin_host(host_target):
77+
if len(self.args.cross_compile_hosts) != 1:
78+
raise RuntimeError("Cross-Compiling swift-format to multiple " +
79+
"targets is not supported")
80+
helper_cmd += ['--cross-compile-host', self.args.cross_compile_hosts[0]]
81+
elif self.is_cross_compile_target(host_target):
82+
helper_cmd.extend(['--cross-compile-host', host_target])
83+
build_toolchain_path = install_destdir + self.args.install_prefix
84+
resource_dir = f'{build_toolchain_path}/lib/swift'
85+
cross_compile_config = targets.StdlibDeploymentTarget \
86+
.get_target_for_name(host_target) \
87+
.platform \
88+
.swiftpm_config(
89+
self.args,
90+
output_dir=build_toolchain_path,
91+
swift_toolchain=toolchain_path,
92+
resource_path=resource_dir
93+
)
94+
helper_cmd += ['--cross-compile-config', cross_compile_config]
95+
7796
if self.args.verbose_build:
7897
helper_cmd.append('--verbose')
7998
helper_cmd.extend(additional_params)
@@ -139,7 +158,12 @@ def should_install(self, host_target):
139158
return self.args.install_swiftformat
140159

141160
def install(self, host_target):
142-
self.run_build_script_helper('install', host_target)
161+
install_destdir = self.host_install_destdir(host_target)
162+
self.run_build_script_helper(
163+
'install',
164+
host_target,
165+
additional_params=['--prefix', install_destdir + self.args.install_prefix]
166+
)
143167

144168
@classmethod
145169
def get_dependencies(cls):

0 commit comments

Comments
 (0)