Skip to content

Commit 67b23d7

Browse files
authored
Merge pull request #60664 from edymtt/infer-cross-compile-hosts-on-darwin
Add a flag to infer appropriate cross compile hosts on Darwin
2 parents 714eee0 + 778c738 commit 67b23d7

6 files changed

+54
-1
lines changed

utils/build-presets.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ release-debuginfo
12371237
compiler-vendor=apple
12381238

12391239
# Cross compile for Apple Silicon
1240-
cross-compile-hosts=macosx-arm64
1240+
infer-cross-compile-hosts-on-darwin
12411241

12421242
lldb-use-system-debugserver
12431243
lldb-build-type=Release

utils/build-script

+15
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ def apply_default_arguments(toolchain, args):
411411
'-DSWIFT_DARWIN_MODULE_ARCHS:STRING={}'.format(
412412
args.swift_darwin_module_archs))
413413

414+
if (args.infer_cross_compile_hosts_on_darwin and
415+
platform.system() == "Darwin"):
416+
args.cross_compile_hosts = _infer_cross_compile_hosts_on_darwin()
417+
print("Inferred the following hosts for cross compilations: "
418+
f"{args.cross_compile_hosts}")
419+
sys.stdout.flush()
420+
421+
422+
def _infer_cross_compile_hosts_on_darwin():
423+
if platform.machine() == "x86_64":
424+
return ["macosx-arm64"]
425+
else:
426+
return ["macosx-x86_64"]
427+
428+
414429
# -----------------------------------------------------------------------------
415430
# Main (preset)
416431

utils/build_swift/build_swift/driver_arguments.py

+5
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

+2
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'),
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:
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)