Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0de70db

Browse files
authored
Use the x64 toolchain when building host artifacts on arm64 mac (#39279)
1 parent 30ba71e commit 0de70db

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

tools/gn

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,22 @@ def to_gn_args(args):
342342
gn_args['host_cpu'] = 'x86'
343343
gn_args['current_cpu'] = 'x86'
344344

345-
if is_host_build(args) and gn_args['host_os'] == 'mac':
346-
# macOS host builds (whether x64 or arm64) must currently be built under
347-
# Rosetta on Apple Silicon Macs.
348-
# TODO(cbracken): https://github.com/flutter/flutter/issues/103386
345+
# When building binaries to run on a macOS host (like gen_snapshot), always
346+
# use the clang_x64 toolchain, which will run under Rosetta. This is done for
347+
# two reasons:
348+
# 1. goma currently only supports the clang_x64 toolchain.
349+
# 2. gen_snapshot cannot crossbuild from arm64 to x64. Its host architecture
350+
# must be x64 to target x64.
351+
# TODO(cbracken): https://github.com/flutter/flutter/issues/103386
352+
if get_host_os() == 'mac' and not args.force_mac_arm64:
349353
gn_args['host_cpu'] = 'x64'
350354

355+
if is_host_build(args) and gn_args['host_os'] == 'mac':
351356
# macOS unit tests include Vulkan headers which reference Metal types
352357
# introduced in macOS 10.14.
353358
gn_args['mac_sdk_min'] = '10.14'
354359
gn_args['mac_deployment_target'] = '10.14.0'
355360

356-
# macOS target builds (whether x64 or arm64) must currently be built under
357-
# Rosetta on Apple Silicon Macs.
358-
# TODO(cbracken): https://github.com/flutter/flutter/issues/103386
359-
if 'target_os' in gn_args and gn_args['target_os'] == 'mac':
360-
gn_args['host_cpu'] = 'x64'
361-
362361
if gn_args['target_os'] == 'ios':
363362
gn_args['use_ios_simulator'] = args.simulator
364363
elif get_host_os() == 'mac':
@@ -729,6 +728,13 @@ def parse_args(args):
729728
parser.add_argument(
730729
'--mac-cpu', type=str, choices=['x64', 'arm64'], default='x64'
731730
)
731+
parser.add_argument(
732+
'--force-mac-arm64',
733+
action='store_true',
734+
default=False,
735+
help='Force use of the clang_arm64 toolchain on an arm64 mac host when '
736+
'building host binaries.'
737+
)
732738
parser.add_argument('--simulator', action='store_true', default=False)
733739
parser.add_argument(
734740
'--linux', dest='target_os', action='store_const', const='linux'

0 commit comments

Comments
 (0)