Skip to content

[build] Support cross-compilation of swift-format #71042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from . import swiftsyntax
from . import xctest
from .. import shell
from .. import targets


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

install_destdir = self.host_install_destdir(host_target)

helper_cmd = [
script_path,
action,
'--toolchain', self.install_toolchain_path(host_target),
'--configuration', self.configuration(),
'--build-path', self.build_dir,
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
# There might have been a Package.resolved created by other builds
# or by the package being opened using Xcode. Discard that and
# reset the dependencies to be local.
'--update'
]
helper_cmd.extend([
'--prefix', install_destdir + self.args.install_prefix
])

install_destdir = self.host_install_destdir(host_target)
toolchain_path = self.native_toolchain_path(host_target)

# Pass Cross compile host info unless we're testing.
# It doesn't make sense to run tests of the cross compile host.
if self.has_cross_compile_hosts() and action != 'test':
if self.is_darwin_host(host_target):
if len(self.args.cross_compile_hosts) != 1:
raise RuntimeError("Cross-Compiling swift-format to multiple " +
"targets is not supported")
helper_cmd += ['--cross-compile-host', self.args.cross_compile_hosts[0]]
elif self.is_cross_compile_target(host_target):
helper_cmd.extend(['--cross-compile-host', host_target])
build_toolchain_path = install_destdir + self.args.install_prefix
resource_dir = f'{build_toolchain_path}/lib/swift'
cross_compile_config = targets.StdlibDeploymentTarget \
.get_target_for_name(host_target) \
.platform \
.swiftpm_config(
self.args,
output_dir=build_toolchain_path,
swift_toolchain=toolchain_path,
resource_path=resource_dir
)
helper_cmd += ['--cross-compile-config', cross_compile_config]

if self.args.verbose_build:
helper_cmd.append('--verbose')
helper_cmd.extend(additional_params)
Expand Down Expand Up @@ -139,7 +158,12 @@ def should_install(self, host_target):
return self.args.install_swiftformat

def install(self, host_target):
self.run_build_script_helper('install', host_target)
install_destdir = self.host_install_destdir(host_target)
self.run_build_script_helper(
'install',
host_target,
additional_params=['--prefix', install_destdir + self.args.install_prefix]
)

@classmethod
def get_dependencies(cls):
Expand Down