Skip to content

Commit 41e45e7

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[build] Detect the host architecture of an ARM64 Mac as ARM64 even through Rosetta.
Lets AppJIT training happen directly, instead of the absurdity of arm64 (hardware) running x64 (Rosetta) running arm64 (VM's simulator). Change-Id: Idbf82530d946099db80c550070257c4c6ead31e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214763 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: William Hesse <[email protected]> Reviewed-by: Alexander Thomas <[email protected]>
1 parent 00c98c7 commit 41e45e7

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

build/config/clang/clang.gni

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
_toolchain_cpu = host_cpu
6+
if (host_os == "mac") {
7+
# TODO(https://fxbug.dev/73385): Use arm64 toolchain on arm64 when it exists.
8+
_toolchain_cpu = "x64"
9+
}
10+
511
default_clang_prefix =
6-
rebase_path("//buildtools/${host_os}-${host_cpu}/clang/bin", root_build_dir)
12+
rebase_path("//buildtools/${host_os}-${_toolchain_cpu}/clang/bin",
13+
root_build_dir)
714

815
declare_args() {
916
clang_prefix = default_clang_prefix

tests/standalone/check_for_aot_snapshot_jit_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ main() {
1919
"Can't locate gen_kernel$_batchSuffix on this platform");
2020
Expect.isTrue(File(genKernel).existsSync(),
2121
"Can't locate gen_kernel$_batchSuffix on this platform");
22-
// Currently gen_snapshot is only in buildDir/clang_x64 on Mac ARM64.
23-
final genSnapshot = Platform.isMacOS && buildDir.endsWith('XARM64')
24-
? path.join(buildDir, 'clang_x64', 'gen_snapshot$_execSuffix')
25-
: path.join(buildDir, 'gen_snapshot$_execSuffix');
22+
final genSnapshot = path.join(buildDir, 'gen_snapshot$_execSuffix');
2623
Expect.isTrue(File(genSnapshot).existsSync(),
2724
"Can't locate gen_snapshot$_execSuffix on this platform");
2825

tests/standalone_2/check_for_aot_snapshot_jit_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ main() {
1919
path.join(sdkDir, 'pkg', 'vm', 'tool', 'gen_kernel$_batchSuffix');
2020
Expect.isTrue(File(genKernel).existsSync(),
2121
"Can't locate gen_kernel$_batchSuffix on this platform");
22-
// Currently gen_snapshot is only in buildDir/clang_x64 on Mac ARM64.
23-
final genSnapshot = Platform.isMacOS && buildDir.endsWith('XARM64')
24-
? path.join(buildDir, 'clang_x64', 'gen_snapshot$_execSuffix')
25-
: path.join(buildDir, 'gen_snapshot$_execSuffix');
22+
final genSnapshot = path.join(buildDir, 'gen_snapshot$_execSuffix');
2623
Expect.isTrue(File(genSnapshot).existsSync(),
2724
"Can't locate gen_snapshot$_execSuffix on this platform");
2825

tools/bots/test_matrix.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@
29362936
"create_sdk"
29372937
],
29382938
"environment": {
2939-
"DART_GN_ARGS": "mac_use_goma_rbe=true dart_snapshot_kind=\"app-jit\""
2939+
"DART_GN_ARGS": "mac_use_goma_rbe=true"
29402940
}
29412941
},
29422942
{

tools/gn.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import argparse
77
import os
8+
import platform
89
import subprocess
910
import sys
1011
import time
@@ -66,7 +67,39 @@ def merge(key, value):
6667
return [merge(x, y) for x, y in gn_args.items()]
6768

6869

70+
# Runs true if the currently executing python interpreter is running under
71+
# Rosetta. I.e., python3 is an x64 executable and we're on an arm64 Mac.
72+
def IsRosetta():
73+
if platform.system() == 'Darwin':
74+
p = subprocess.Popen(['sysctl', '-in', 'sysctl.proc_translated'],
75+
stdout=subprocess.PIPE,
76+
stderr=subprocess.STDOUT)
77+
output, _ = p.communicate()
78+
return output.decode('utf-8').strip() == '1'
79+
return False
80+
81+
6982
def HostCpuForArch(arch):
83+
# Check for Rosetta before checking platform.machine(), as the latter
84+
# returns 'x86_64' when running under Rosetta.
85+
if IsRosetta():
86+
if arch in ['x64', 'x64c']:
87+
# Without this case, we would try to build with
88+
# host_cpu="arm64"
89+
# target_cpu="x64"
90+
# dart_target_arch="x64"
91+
# Which requires the VM to use an x64 simulator in the host
92+
# arm64 binaries, and this simulator is unimplemented.
93+
return 'x64'
94+
else:
95+
return 'arm64'
96+
97+
m = platform.machine()
98+
if m == 'aarch64' or m == 'arm64':
99+
return 'arm64'
100+
if m == 'armv7l' or m == 'armv6l':
101+
return 'arm'
102+
70103
if arch in ['ia32', 'arm', 'armv6', 'simarm', 'simarmv6', 'simarm_x64']:
71104
return 'x86'
72105
if arch in [

0 commit comments

Comments
 (0)