Skip to content

Commit c954130

Browse files
committed
Add a flag to infer appropriate cross compile hosts on Darwin
Addresses rdar://98787335, apple#60348
1 parent f5787c9 commit c954130

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

utils/build-script

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,21 @@ def apply_default_arguments(toolchain, args):
389389
'-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format(
390390
args.swift_darwin_module_archs))
391391

392+
if (args.infer_cross_compile_hosts_on_darwin and
393+
platform.system() == "Darwin"):
394+
args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin()
395+
print("Inferred the following hosts for cross compilations: "
396+
f"{args.cross_compile_hosts}")
397+
sys.stdout.flush()
398+
399+
400+
def _infer_cross_compile_hosts_on_darwin():
401+
if platform.machine() == "x86_64":
402+
return ["macosx-arm64"]
403+
else:
404+
return ["macosx-x86_64"]
405+
406+
392407
# -----------------------------------------------------------------------------
393408
# Main (preset)
394409

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ def create_argument_parser():
580580
help='A space separated list of targets to cross-compile host '
581581
'Swift tools for. Can be used multiple times.')
582582

583+
option('--infer-cross-compile-hosts-on-darwin', toggle_true,
584+
help="When building on Darwin, automatically populate cross-compile-hosts "
585+
"based on the architecture build-script is running on. "
586+
"Has precedence over cross-compile-hosts")
587+
583588
option('--cross-compile-deps-path', store_path,
584589
help='The path to a directory that contains prebuilt cross-compiled '
585590
'library dependencies of the corelibs and other Swift repos, '

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
'cross_compile_append_host_target_to_destdir': True,
134134
'cross_compile_deps_path': None,
135135
'cross_compile_hosts': [],
136+
'infer_cross_compile_hosts_on_darwin': False,
136137
'darwin_deployment_version_ios':
137138
defaults.DARWIN_DEPLOYMENT_VERSION_IOS,
138139
'darwin_deployment_version_osx':
@@ -732,6 +733,7 @@ class BuildScriptImplOption(_BaseOption):
732733
IntOption('--dsymutil-jobs', dest='dsymutil_jobs'),
733734

734735
AppendOption('--cross-compile-hosts'),
736+
SetTrueOption('--infer-cross-compile-hosts-on-darwin'),
735737
AppendOption('--extra-cmake-options'),
736738
AppendOption('--extra-swift-args'),
737739
AppendOption('--test-paths'),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# REQUIRES: standalone_build
2+
# REQUIRES: OS=linux-gnu
3+
4+
# RUN: %empty-directory(%t)
5+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
6+
# RUN: %empty-directory(%t)
7+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin=1 --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
8+
# RUN: %empty-directory(%t)
9+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
10+
# RUN: %empty-directory(%t)
11+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin=0 --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
12+
13+
# NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-NOT: Inferred the following hosts for cross compilations:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# REQUIRES: standalone_build
2+
# REQUIRES: OS=macosx
3+
4+
# RUN: %empty-directory(%t)
5+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin --cmake %cmake 2>&1 | %FileCheck --check-prefix=INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-%target-cpu %s
6+
# RUN: %empty-directory(%t)
7+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin=1 --cmake %cmake 2>&1 | %FileCheck --check-prefix=INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-%target-cpu %s
8+
9+
# INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-x86_64: Inferred the following hosts for cross compilations: ['macosx-arm64']
10+
# INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-arm64: Inferred the following hosts for cross compilations: ['macosx-x86_64']
11+
12+
13+
# RUN: %empty-directory(%t)
14+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
15+
# RUN: %empty-directory(%t)
16+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer-cross-compile-hosts-on-darwin=0 --cmake %cmake 2>&1 | %FileCheck --check-prefix=NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN %s
17+
18+
# NO-INFER-CROSS-COMPILE-HOSTS-ON-DARWIN-NOT: Inferred the following hosts for cross compilations:

0 commit comments

Comments
 (0)