Felt should use arm64 dart sdk and arm64 Chromium when on arm Macs (flutter/engine#36336)

This commit is contained in:
Jackson Gardner
2022-09-23 13:09:14 -07:00
committed by GitHub
parent 89398f450c
commit 9d1aaf1159
10 changed files with 150 additions and 84 deletions

View File

@@ -38,11 +38,13 @@ class ChromeLock {
ChromeLock._fromYaml(YamlMap yaml) :
linux = (yaml['Linux'] as int).toString(),
mac = (yaml['Mac'] as int).toString(),
macArm = (yaml['Mac_Arm'] as int).toString(),
windows = (yaml['Win'] as int).toString(),
version = yaml['version'] as String;
final String linux;
final String mac;
final String macArm;
final String windows;
/// The major version of Chromium represented by this lock. E.g: '96' (for Chromium 96.0.554.51)
final String version;

View File

@@ -13,10 +13,11 @@ chrome:
# `self.m.platform.name.capitalize()` evaluates to. See:
#
# recipe_modules/web_util/api.py
Linux: 929514
Mac: 929514
Win: 929514
version: '96.2' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
Linux: 1027016
Mac: 1027007
Mac_Arm: 1026994
Win: 1026943
version: '105.0' # CIPD tag for the above Build IDs. Normally "ChromeMajorVersion.UploadAttempt". ;)
## Firefox does not use CIPD. To update the version, simply update it in this
## file.

View File

@@ -82,16 +82,27 @@ void processArgs(ArgResults args) {
verbose = args['verbose'] as bool;
}
class _Platform {
_Platform(this.os, this.arch, this.binding);
final String os;
final String arch;
final PlatformBinding binding;
String get name => '$os-$arch';
}
class _BrowserRoller {
_BrowserRoller();
final io.Directory _rollDir = io.Directory.systemTemp.createTempSync('browser-roll-');
final Map<String, PlatformBinding> _platformBindings = <String, PlatformBinding>{
'linux': LinuxPlatformBinding(),
'mac': MacPlatformBinding(),
'windows': WindowsPlatformBinding(),
};
final List<_Platform> _platforms = <_Platform>[
_Platform('linux', 'amd64', LinuxPlatformBinding()),
_Platform('mac', 'amd64', Macx64PlatformBinding()),
_Platform('mac', 'arm64', MacArmPlatformBinding()),
_Platform('windows', 'amd64', WindowsPlatformBinding()),
];
final BrowserLock _lock = BrowserLock();
@@ -104,11 +115,9 @@ class _BrowserRoller {
// Roll Chromium and ChromeDriver for each of the Platforms.
Future<void> roll() async {
for (final MapEntry<String, PlatformBinding> entry in _platformBindings.entries) {
final String platform = entry.key;
final PlatformBinding binding = entry.value;
await _rollChromium(platform, binding);
await _rollChromeDriver(platform, binding);
for (final _Platform platform in _platforms) {
await _rollChromium(platform);
await _rollChromeDriver(platform);
}
if (dryRun) {
print('\nDry Run Done!\nNon-published roll artifacts kept here: ${_rollDir.path}\n');
@@ -273,13 +282,13 @@ data:
// Downloads Chromium from the internet, packs it in the directory structure
// that the LUCI script wants. The result of this will be then uploaded to CIPD.
Future<void> _rollChromium(String platform, PlatformBinding binding) async {
final String chromeBuild = binding.getChromeBuild(_lock.chromeLock);
Future<void> _rollChromium(_Platform platform) async {
final String chromeBuild = platform.binding.getChromeBuild(_lock.chromeLock);
final String majorVersion = _lock.chromeLock.version;
final String url = binding.getChromeDownloadUrl(chromeBuild);
final String cipdPackageName = 'flutter_internal/browsers/chrome/$platform-amd64';
final io.Directory platformDir = io.Directory(path.join(_rollDir.path, platform));
print('\nRolling Chromium for $platform (version:$majorVersion, build $chromeBuild)');
final String url = platform.binding.getChromeDownloadUrl(chromeBuild);
final String cipdPackageName = 'flutter_internal/browsers/chrome/${platform.name}';
final io.Directory platformDir = io.Directory(path.join(_rollDir.path, platform.name));
print('\nRolling Chromium for ${platform.name} (version:$majorVersion, build $chromeBuild)');
// Bail out if CIPD already has version:$majorVersion for this package!
if (!dryRun && await _cipdKnowsPackageVersion(package: cipdPackageName, versionTag: majorVersion)) {
print(' Skipping $cipdPackageName version:$majorVersion. Already uploaded to CIPD!');
@@ -296,7 +305,7 @@ data:
late String relativePlatformDirPath;
// Preserve the `chrome-mac` directory when bundling, but remove it for win and linux.
if (platform == 'Mac') {
if (platform.os == 'mac') {
relativePlatformDirPath = path.relative(platformDir.path, from: _rollDir.path);
} else {
final io.Directory? actualContentRoot = await _locateContentRoot(platformDir);
@@ -306,7 +315,7 @@ data:
// Create the config manifest to upload to CIPD
final io.File cipdConfigFile = await _writeFile(
path.join(_rollDir.path, 'cipd.chromium.$platform.yaml'),
path.join(_rollDir.path, 'cipd.chromium.${platform.name}.yaml'),
_getCipdChromiumConfig(
package: cipdPackageName,
majorVersion: majorVersion,
@@ -319,13 +328,13 @@ data:
// Downloads Chromedriver from the internet, packs it in the directory structure
// that the LUCI script wants. The result of this will be then uploaded to CIPD.
Future<void> _rollChromeDriver(String platform, PlatformBinding binding) async {
final String chromeBuild = binding.getChromeBuild(_lock.chromeLock);
Future<void> _rollChromeDriver(_Platform platform) async {
final String chromeBuild = platform.binding.getChromeBuild(_lock.chromeLock);
final String majorVersion = _lock.chromeLock.version;
final String url = binding.getChromeDriverDownloadUrl(chromeBuild);
final String cipdPackageName = 'flutter_internal/browser-drivers/chrome/$platform-amd64';
final io.Directory platformDir = io.Directory(path.join(_rollDir.path, '${platform}_driver'));
print('\nRolling Chromedriver for $platform (version:$majorVersion, build $chromeBuild)');
final String url = platform.binding.getChromeDriverDownloadUrl(chromeBuild);
final String cipdPackageName = 'flutter_internal/browser-drivers/chrome/${platform.name}';
final io.Directory platformDir = io.Directory(path.join(_rollDir.path, '${platform.name}_driver'));
print('\nRolling Chromedriver for ${platform.os}-${platform.arch} (version:$majorVersion, build $chromeBuild)');
// Bail out if CIPD already has version:$majorVersion for this package!
if (!dryRun && await _cipdKnowsPackageVersion(package: cipdPackageName, versionTag: majorVersion)) {
print(' Skipping $cipdPackageName version:$majorVersion. Already uploaded to CIPD!');
@@ -347,7 +356,7 @@ data:
// Create the config manifest to upload to CIPD
final io.File cipdConfigFile = await _writeFile(
path.join(_rollDir.path, 'cipd.chromedriver.$platform.yaml'),
path.join(_rollDir.path, 'cipd.chromedriver.${platform.name}.yaml'),
_getCipdChromedriverConfig(
package: cipdPackageName,
majorVersion: majorVersion,

View File

@@ -43,7 +43,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
final FilePath libPath = FilePath.fromWebUi('lib');
final List<PipelineStep> steps = <PipelineStep>[
GnPipelineStep(),
NinjaPipelineStep(target: environment.hostDebugUnoptDir),
NinjaPipelineStep(target: environment.engineBuildDir),
];
if (buildCanvasKit) {
steps.addAll(<PipelineStep>[
@@ -96,6 +96,7 @@ class GnPipelineStep extends ProcessStep {
'--unopt',
if (Platform.isMacOS) '--xcode-symlinks',
'--full-dart-sdk',
if (environment.isMacosArm) '--mac-cpu=arm64',
]);
} else if (target == 'canvaskit') {
gnArgs.addAll(<String>[

View File

@@ -10,6 +10,7 @@ import 'browser.dart';
import 'browser_lock.dart';
import 'chrome.dart';
import 'edge.dart';
import 'environment.dart';
import 'firefox.dart';
import 'safari_macos.dart';
@@ -30,7 +31,10 @@ abstract class PlatformBinding {
return LinuxPlatformBinding();
}
if (io.Platform.isMacOS) {
return MacPlatformBinding();
if (environment.isMacosArm) {
return MacArmPlatformBinding();
}
return Macx64PlatformBinding();
}
if (io.Platform.isWindows) {
return WindowsPlatformBinding();
@@ -139,19 +143,16 @@ class LinuxPlatformBinding implements PlatformBinding {
throw UnsupportedError('Edge is not supported on Linux');
}
class MacPlatformBinding implements PlatformBinding {
@override
String getChromeBuild(ChromeLock chromeLock) {
return chromeLock.mac;
}
abstract class MacPlatformBinding implements PlatformBinding {
String get chromePlatformString;
@override
String getChromeDownloadUrl(String version) =>
'$_kBaseDownloadUrl/Mac%2F$version%2Fchrome-mac.zip?alt=media';
'$_kBaseDownloadUrl/$chromePlatformString%2F$version%2Fchrome-mac.zip?alt=media';
@override
String getChromeDriverDownloadUrl(String version) =>
'$_kBaseDownloadUrl/Mac%2F$version%2Fchromedriver_mac64.zip?alt=media';
'$_kBaseDownloadUrl/$chromePlatformString%2F$version%2Fchromedriver_mac64.zip?alt=media';
@override
String getChromeExecutablePath(io.Directory versionDir) => path.join(
@@ -187,6 +188,26 @@ class MacPlatformBinding implements PlatformBinding {
throw UnimplementedError('Tests for Edge are not implemented for MacOS.');
}
class MacArmPlatformBinding extends MacPlatformBinding {
@override
String get chromePlatformString => 'Mac_Arm';
@override
String getChromeBuild(ChromeLock chromeLock) {
return chromeLock.macArm;
}
}
class Macx64PlatformBinding extends MacPlatformBinding {
@override
String get chromePlatformString => 'Mac';
@override
String getChromeBuild(ChromeLock chromeLock) {
return chromeLock.mac;
}
}
class BrowserInstallation {
const BrowserInstallation({
required this.version,

View File

@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ffi' as ffi;
import 'dart:io' as io;
import 'package:path/path.dart' as pathlib;
import 'exceptions.dart';
@@ -17,26 +19,27 @@ Environment? _environment;
/// Contains various environment variables, such as common file paths and command-line options.
class Environment {
factory Environment() {
final bool isMacosArm = ffi.Abi.current() == ffi.Abi.macosArm64;
final io.File self = io.File.fromUri(io.Platform.script);
final io.Directory engineSrcDir = self.parent.parent.parent.parent.parent;
final io.Directory engineToolsDir =
io.Directory(pathlib.join(engineSrcDir.path, 'flutter', 'tools'));
final io.Directory outDir =
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory engineBuildDir =
io.Directory(pathlib.join(
outDir.path,
isMacosArm ? 'host_debug_unopt_arm64' : 'host_debug_unopt'
));
final io.Directory wasmReleaseOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory dartSdkDir =
io.Directory(pathlib.join(hostDebugUnoptDir.path, 'dart-sdk'));
io.Directory(pathlib.join(engineBuildDir.path, 'dart-sdk'));
final io.Directory webUiRootDir = io.Directory(
pathlib.join(engineSrcDir.path, 'flutter', 'lib', 'web_ui'));
for (final io.Directory expectedDirectory in <io.Directory>[
engineSrcDir,
outDir,
hostDebugUnoptDir,
dartSdkDir,
webUiRootDir
]) {
if (!expectedDirectory.existsSync()) {
@@ -47,11 +50,12 @@ class Environment {
return Environment._(
self: self,
isMacosArm: isMacosArm,
webUiRootDir: webUiRootDir,
engineSrcDir: engineSrcDir,
engineToolsDir: engineToolsDir,
outDir: outDir,
hostDebugUnoptDir: hostDebugUnoptDir,
engineBuildDir: engineBuildDir,
wasmReleaseOutDir: wasmReleaseOutDir,
dartSdkDir: dartSdkDir,
);
@@ -59,11 +63,12 @@ class Environment {
Environment._({
required this.self,
required this.isMacosArm,
required this.webUiRootDir,
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.engineBuildDir,
required this.wasmReleaseOutDir,
required this.dartSdkDir,
});
@@ -71,6 +76,9 @@ class Environment {
/// The Dart script that's currently running.
final io.File self;
/// Whether the environment is a macOS arm environment.
final bool isMacosArm;
/// Path to the "web_ui" package sources.
final io.Directory webUiRootDir;
@@ -86,7 +94,7 @@ class Environment {
final io.Directory outDir;
/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;
final io.Directory engineBuildDir;
/// The output directory for the wasm_release build.
///

View File

@@ -24,14 +24,56 @@ then
fi
NINJA_PATH=`which autoninja`
KERNEL_NAME=`uname`
CPU_NAME=`uname -m`
ENGINE_SRC_DIR="$(dirname $(dirname $(dirname $(dirname ${FELT_DIR}))))"
FLUTTER_DIR="${ENGINE_SRC_DIR}/flutter"
SDK_PREBUILTS_DIR="${FLUTTER_DIR}/prebuilts"
if [ -z "${DART_SDK_DIR}"]
then
if [[ $KERNEL_NAME == *"Darwin"* ]]
then
TARGET_OS="macos"
elif [[ $KERNEL_NAME == *"Linux"* ]]
then
TARGET_OS="linux"
else
echo "Unrecognized kernel name: ${KERNEL_NAME}"
exit 1
fi
if [[ $CPU_NAME == *"x86_64"* ]]
then
TARGET_ARCH="x64"
elif [[ $CPU_NAME == *"arm64"* ]]
then
TARGET_ARCH="arm64"
else
echo "Unrecognized architecture: ${CPU_NAME}"
exit 1
fi
PREBUILT_TARGET="${TARGET_OS}-${TARGET_ARCH}"
DART_SDK_DIR="${SDK_PREBUILTS_DIR}/${PREBUILT_TARGET}/dart-sdk"
if [ ! -d "$DART_SDK_DIR" ]
then
echo "Prebuilt dart sdk for ${PREBUILT_TARGET} not found."
echo "Note: You can specify your own path to a built dart sdk with the DART_SDK_DIR environment variable."
exit 1
fi
else
if [ ! -d "$DART_SDK_DIR" ]
then
echo "Explicitly specified dart SDK not found at ${DART_SDK_DIR}."
exit 1
fi
fi
WEB_UI_DIR="${FLUTTER_DIR}/lib/web_ui"
DEV_DIR="${WEB_UI_DIR}/dev"
OUT_DIR="${ENGINE_SRC_DIR}/out"
HOST_DEBUG_UNOPT_DIR="${ENGINE_SRC_DIR}/out/host_debug_unopt"
DART_SDK_DIR="${ENGINE_SRC_DIR}/out/host_debug_unopt/dart-sdk"
GN="${FLUTTER_DIR}/tools/gn"
DART_TOOL_DIR="${WEB_UI_DIR}/.dart_tool"
DART_PATH="$DART_SDK_DIR/bin/dart"
SNAPSHOT_PATH="${DART_TOOL_DIR}/felt.snapshot"
@@ -39,12 +81,9 @@ STAMP_PATH="${DART_TOOL_DIR}/felt.snapshot.stamp"
SCRIPT_PATH="${DEV_DIR}/felt.dart"
REVISION="$(cd "$FLUTTER_DIR"; git rev-parse HEAD)"
if [ ! -f "${DART_PATH}" ]
if [[ "$FELT_DEBUG" == "true" || "$FELT_DEBUG" == "1" ]]
then
echo "Compiling the Dart SDK."
gclient sync
$GN --unoptimized --full-dart-sdk
"$NINJA_PATH" -C "$HOST_DEBUG_UNOPT_DIR"
FELT_DEBUG_FLAGS="--enable-vm-service --pause-isolates-on-start"
fi
install_deps() {
@@ -55,7 +94,6 @@ install_deps() {
(cd "$FLUTTER_DIR/web_sdk/web_engine_tester"; $DART_PATH pub get)
}
KERNEL_NAME=`uname`
if [[ $KERNEL_NAME == *"Darwin"* ]]
then
echo "Running on MacOS. Will check the file and user limits."
@@ -104,7 +142,7 @@ if [[ "$FELT_USE_SNAPSHOT" == "false" || "$FELT_USE_SNAPSHOT" == "0" ]]; then
rm -f "$SNAPSHOT_PATH"
rm -f "$STAMP_PATH"
install_deps
$DART_SDK_DIR/bin/dart "$DEV_DIR/felt.dart" $@
$DART_SDK_DIR/bin/dart $FELT_DEBUG_FLAGS "$DEV_DIR/felt.dart" $@
else
# Create a new snapshot if any of the following is true:
# * SNAPSHOT_PATH is not a file, or
@@ -120,5 +158,5 @@ else
echo "$REVISION" > "$STAMP_PATH"
fi
$DART_SDK_DIR/bin/dart --packages="$WEB_UI_DIR/.dart_tool/package_config.json" "$SNAPSHOT_PATH" $@
$DART_SDK_DIR/bin/dart $FELT_DEBUG_FLAGS --packages="$WEB_UI_DIR/.dart_tool/package_config.json" "$SNAPSHOT_PATH" $@
fi

View File

@@ -22,14 +22,18 @@ FOR %%a IN ("%TMP:~0,-1%") DO SET ENGINE_SRC_DIR=%%~dpa
SET ENGINE_SRC_DIR=%ENGINE_SRC_DIR:~0,-1%
SET OUT_DIR=%ENGINE_SRC_DIR%\out
SET HOST_DEBUG_UNOPT_DIR=%OUT_DIR%\host_debug_unopt
SET DART_SDK_DIR=%HOST_DEBUG_UNOPT_DIR%\dart-sdk
SET DART_BIN=%DART_SDK_DIR%\bin\dart
SET FLUTTER_DIR=%ENGINE_SRC_DIR%\flutter
SET WEB_UI_DIR=%FLUTTER_DIR%\lib\web_ui
SET DEV_DIR=%WEB_UI_DIR%\dev
SET FELT_PATH=%DEV_DIR%\felt.dart
SET DART_TOOL_DIR=%WEB_UI_DIR%\.dart_tool
SET SNAPSHOT_PATH=%DART_TOOL_DIR%\felt.snapshot
SET SDK_PREBUILTS_DIR=%FLUTTER_DIR%\prebuilts
SET PREBUILT_TARGET=windows-x64
IF NOT DEFINED DART_SDK_DIR (
SET DART_SDK_DIR=%SDK_PREBUILTS_DIR%\%PREBUILT_TARGET%\dart-sdk
)
SET DART_BIN=%DART_SDK_DIR%\bin\dart
SET needsHostDebugUnoptRebuild=0
for %%x in (%*) do (

View File

@@ -27,12 +27,16 @@ FOR %%a IN ("%FLUTTER_DIR:~0,-1%") DO SET ENGINE_SRC_DIR=%%~dpa
SET DEV_DIR="%WEB_UI_DIR%dev"
SET OUT_DIR="%ENGINE_SRC_DIR%out"
SET HOST_DEBUG_UNOPT_DIR="%ENGINE_SRC_DIR%out\host_debug_unopt"
SET DART_SDK_DIR=%ENGINE_SRC_DIR%out\host_debug_unopt\dart-sdk
SET SCRIPT_PATH="%DEV_DIR%felt.dart"
SET STAMP_PATH="%DART_TOOL_DIR%felt.snapshot.stamp"
SET GN="%FLUTTER_DIR%tools\gn"
SET DART_TOOL_DIR="%WEB_UI_DIR%.dart_tool"
SET SNAPSHOT_PATH="%DART_TOOL_DIR%felt.snapshot"
SET SDK_PREBUILTS_DIR=%FLUTTER_DIR%\prebuilts
SET PREBUILT_TARGET=windows-x64
IF NOT DEFINED DART_SDK_DIR (
SET DART_SDK_DIR=%SDK_PREBUILTS_DIR%\%PREBUILT_TARGET%\dart-sdk
)
:: Set revision from using git in Flutter directory.
CD %FLUTTER_DIR%

View File

@@ -42,8 +42,6 @@ class Environment {
required this.engineSrcDir,
required this.engineToolsDir,
required this.outDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});
static Environment _prepareEnvironmentFromEngineDir(
@@ -52,18 +50,12 @@ class Environment {
io.Directory(pathlib.join(engineSrcDir.path, 'flutter', 'tools'));
final io.Directory outDir =
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory dartSdkDir =
io.Directory(pathlib.join(hostDebugUnoptDir.path, 'dart-sdk'));
final io.Directory webUiRootDir = io.Directory(
pathlib.join(engineSrcDir.path, 'flutter', 'lib', 'web_ui'));
for (final io.Directory expectedDirectory in <io.Directory>[
engineSrcDir,
outDir,
hostDebugUnoptDir,
dartSdkDir,
webUiRootDir
]) {
if (!expectedDirectory.existsSync()) {
@@ -77,8 +69,6 @@ class Environment {
engineSrcDir: engineSrcDir,
engineToolsDir: engineToolsDir,
outDir: outDir,
hostDebugUnoptDir: hostDebugUnoptDir,
dartSdkDir: dartSdkDir,
);
}
@@ -99,18 +89,6 @@ class Environment {
/// This is where you'll find the ninja output, such as the Dart SDK.
final io.Directory outDir;
/// The "host_debug_unopt" build of the Dart SDK.
final io.Directory hostDebugUnoptDir;
/// The root of the Dart SDK.
final io.Directory dartSdkDir;
/// The "dart" executable file.
String get dartExecutable => pathlib.join(dartSdkDir.path, 'bin', 'dart');
/// The "pub" executable file.
String get pubExecutable => pathlib.join(dartSdkDir.path, 'bin', 'pub');
/// Path to where github.com/flutter/engine is checked out inside the engine workspace.
io.Directory get flutterDirectory =>
io.Directory(pathlib.join(engineSrcDir.path, 'flutter'));