[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 <rmacnak@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
This commit is contained in:
Ryan Macnak 2021-09-28 17:44:32 +00:00 committed by commit-bot@chromium.org
parent 00c98c7644
commit 41e45e7a1c
5 changed files with 44 additions and 10 deletions

View file

@ -2,8 +2,15 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
_toolchain_cpu = host_cpu
if (host_os == "mac") {
# TODO(https://fxbug.dev/73385): Use arm64 toolchain on arm64 when it exists.
_toolchain_cpu = "x64"
}
default_clang_prefix =
rebase_path("//buildtools/${host_os}-${host_cpu}/clang/bin", root_build_dir)
rebase_path("//buildtools/${host_os}-${_toolchain_cpu}/clang/bin",
root_build_dir)
declare_args() {
clang_prefix = default_clang_prefix

View file

@ -19,10 +19,7 @@ main() {
"Can't locate gen_kernel$_batchSuffix on this platform");
Expect.isTrue(File(genKernel).existsSync(),
"Can't locate gen_kernel$_batchSuffix on this platform");
// Currently gen_snapshot is only in buildDir/clang_x64 on Mac ARM64.
final genSnapshot = Platform.isMacOS && buildDir.endsWith('XARM64')
? path.join(buildDir, 'clang_x64', 'gen_snapshot$_execSuffix')
: path.join(buildDir, 'gen_snapshot$_execSuffix');
final genSnapshot = path.join(buildDir, 'gen_snapshot$_execSuffix');
Expect.isTrue(File(genSnapshot).existsSync(),
"Can't locate gen_snapshot$_execSuffix on this platform");

View file

@ -19,10 +19,7 @@ main() {
path.join(sdkDir, 'pkg', 'vm', 'tool', 'gen_kernel$_batchSuffix');
Expect.isTrue(File(genKernel).existsSync(),
"Can't locate gen_kernel$_batchSuffix on this platform");
// Currently gen_snapshot is only in buildDir/clang_x64 on Mac ARM64.
final genSnapshot = Platform.isMacOS && buildDir.endsWith('XARM64')
? path.join(buildDir, 'clang_x64', 'gen_snapshot$_execSuffix')
: path.join(buildDir, 'gen_snapshot$_execSuffix');
final genSnapshot = path.join(buildDir, 'gen_snapshot$_execSuffix');
Expect.isTrue(File(genSnapshot).existsSync(),
"Can't locate gen_snapshot$_execSuffix on this platform");

View file

@ -2936,7 +2936,7 @@
"create_sdk"
],
"environment": {
"DART_GN_ARGS": "mac_use_goma_rbe=true dart_snapshot_kind=\"app-jit\""
"DART_GN_ARGS": "mac_use_goma_rbe=true"
}
},
{

View file

@ -5,6 +5,7 @@
import argparse
import os
import platform
import subprocess
import sys
import time
@ -66,7 +67,39 @@ def ToCommandLine(gn_args):
return [merge(x, y) for x, y in gn_args.items()]
# Runs true if the currently executing python interpreter is running under
# Rosetta. I.e., python3 is an x64 executable and we're on an arm64 Mac.
def IsRosetta():
if platform.system() == 'Darwin':
p = subprocess.Popen(['sysctl', '-in', 'sysctl.proc_translated'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, _ = p.communicate()
return output.decode('utf-8').strip() == '1'
return False
def HostCpuForArch(arch):
# Check for Rosetta before checking platform.machine(), as the latter
# returns 'x86_64' when running under Rosetta.
if IsRosetta():
if arch in ['x64', 'x64c']:
# Without this case, we would try to build with
# host_cpu="arm64"
# target_cpu="x64"
# dart_target_arch="x64"
# Which requires the VM to use an x64 simulator in the host
# arm64 binaries, and this simulator is unimplemented.
return 'x64'
else:
return 'arm64'
m = platform.machine()
if m == 'aarch64' or m == 'arm64':
return 'arm64'
if m == 'armv7l' or m == 'armv6l':
return 'arm'
if arch in ['ia32', 'arm', 'armv6', 'simarm', 'simarmv6', 'simarm_x64']:
return 'x86'
if arch in [