Commit e8a47b6d authored by Adam Barth's avatar Adam Barth

Add --interpreter to flutter build aot (#4159)

This patch teaches flutter build aot to build `app.a` for use with the Dart
interpreter.
parent cb7a6908
...@@ -30,7 +30,8 @@ class BuildAotCommand extends FlutterCommand { ...@@ -30,7 +30,8 @@ class BuildAotCommand extends FlutterCommand {
..addOption('target-platform', ..addOption('target-platform',
defaultsTo: 'android-arm', defaultsTo: 'android-arm',
allowed: <String>['android-arm', 'ios'] allowed: <String>['android-arm', 'ios']
); )
..addFlag('interpreter');
} }
@override @override
...@@ -51,7 +52,8 @@ class BuildAotCommand extends FlutterCommand { ...@@ -51,7 +52,8 @@ class BuildAotCommand extends FlutterCommand {
findMainDartFile(argResults['target']), findMainDartFile(argResults['target']),
platform, platform,
getBuildMode(), getBuildMode(),
outputPath: argResults['output-dir'] outputPath: argResults['output-dir'],
interpreter: argResults['interpreter']
); );
if (outputPath == null) if (outputPath == null)
return 1; return 1;
...@@ -70,7 +72,8 @@ String buildAotSnapshot( ...@@ -70,7 +72,8 @@ String buildAotSnapshot(
String mainPath, String mainPath,
TargetPlatform platform, TargetPlatform platform,
BuildMode buildMode, { BuildMode buildMode, {
String outputPath: _kDefaultAotOutputDir String outputPath: _kDefaultAotOutputDir,
bool interpreter: false
}) { }) {
if (!isAotBuildMode(buildMode)) { if (!isAotBuildMode(buildMode)) {
printError('${getModeName(buildMode)} mode does not support AOT compilation.'); printError('${getModeName(buildMode)} mode does not support AOT compilation.');
...@@ -124,6 +127,7 @@ String buildAotSnapshot( ...@@ -124,6 +127,7 @@ String buildAotSnapshot(
String skyEngineSdkExt = _getSdkExtensionPath(packagesPath, 'sky_engine'); String skyEngineSdkExt = _getSdkExtensionPath(packagesPath, 'sky_engine');
String uiPath = path.join(skyEngineSdkExt, 'dart_ui.dart'); String uiPath = path.join(skyEngineSdkExt, 'dart_ui.dart');
String jniPath = path.join(skyEngineSdkExt, 'dart_jni', 'jni.dart');
String vmServicePath = path.join(skyEngineSdkExt, 'dart', 'runtime', 'bin', 'vmservice', 'vmservice_io.dart'); String vmServicePath = path.join(skyEngineSdkExt, 'dart', 'runtime', 'bin', 'vmservice', 'vmservice_io.dart');
List<String> filePaths = <String>[ List<String> filePaths = <String>[
...@@ -131,12 +135,12 @@ String buildAotSnapshot( ...@@ -131,12 +135,12 @@ String buildAotSnapshot(
vmEntryPoints, vmEntryPoints,
mojoInternalPath, mojoInternalPath,
uiPath, uiPath,
jniPath,
vmServicePath, vmServicePath,
]; ];
// These paths are used only on Android. // These paths are used only on Android.
String vmEntryPointsAndroid; String vmEntryPointsAndroid;
String jniPathAndroid;
// These paths are used only on iOS. // These paths are used only on iOS.
String snapshotDartIOS; String snapshotDartIOS;
...@@ -147,10 +151,8 @@ String buildAotSnapshot( ...@@ -147,10 +151,8 @@ String buildAotSnapshot(
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
case TargetPlatform.android_x86: case TargetPlatform.android_x86:
vmEntryPointsAndroid = path.join(entryPointsDir, 'dart_vm_entry_points_android.txt'); vmEntryPointsAndroid = path.join(entryPointsDir, 'dart_vm_entry_points_android.txt');
jniPathAndroid = path.join(skyEngineSdkExt, 'dart_jni', 'jni.dart');
filePaths.addAll(<String>[ filePaths.addAll(<String>[
vmEntryPointsAndroid, vmEntryPointsAndroid,
jniPathAndroid,
]); ]);
break; break;
case TargetPlatform.ios: case TargetPlatform.ios:
...@@ -175,13 +177,19 @@ String buildAotSnapshot( ...@@ -175,13 +177,19 @@ String buildAotSnapshot(
genSnapshot, genSnapshot,
'--vm_isolate_snapshot=$vmIsolateSnapshot', '--vm_isolate_snapshot=$vmIsolateSnapshot',
'--isolate_snapshot=$isolateSnapshot', '--isolate_snapshot=$isolateSnapshot',
'--embedder_entry_points_manifest=$vmEntryPoints',
'--package_root=$packagesPath', '--package_root=$packagesPath',
'--url_mapping=dart:mojo.internal,$mojoInternalPath', '--url_mapping=dart:mojo.internal,$mojoInternalPath',
'--url_mapping=dart:ui,$uiPath', '--url_mapping=dart:ui,$uiPath',
'--url_mapping=dart:jni,$jniPath',
'--url_mapping=dart:vmservice_sky,$vmServicePath', '--url_mapping=dart:vmservice_sky,$vmServicePath',
]; ];
if (!interpreter) {
genSnapshotCmd.addAll(<String>[
'--embedder_entry_points_manifest=$vmEntryPoints',
]);
}
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
...@@ -190,14 +198,11 @@ String buildAotSnapshot( ...@@ -190,14 +198,11 @@ String buildAotSnapshot(
'--rodata_blob=$rodataBlob', '--rodata_blob=$rodataBlob',
'--instructions_blob=$instructionsBlob', '--instructions_blob=$instructionsBlob',
'--embedder_entry_points_manifest=$vmEntryPointsAndroid', '--embedder_entry_points_manifest=$vmEntryPointsAndroid',
'--url_mapping=dart:jni,$jniPathAndroid',
'--no-sim-use-hardfp', '--no-sim-use-hardfp',
]); ]);
break; break;
case TargetPlatform.ios: case TargetPlatform.ios:
genSnapshotCmd.addAll(<String>[ genSnapshotCmd.add(interpreter ? snapshotDartIOS : '--assembly=$assembly');
'--assembly=$assembly'
]);
break; break;
case TargetPlatform.darwin_x64: case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
...@@ -242,17 +247,22 @@ String buildAotSnapshot( ...@@ -242,17 +247,22 @@ String buildAotSnapshot(
String kDartVmIsolateSnapshotBufferO = path.join(outputDir.path, '$kDartVmIsolateSnapshotBuffer.o'); String kDartVmIsolateSnapshotBufferO = path.join(outputDir.path, '$kDartVmIsolateSnapshotBuffer.o');
String kDartIsolateSnapshotBufferO = path.join(outputDir.path, '$kDartIsolateSnapshotBuffer.o'); String kDartIsolateSnapshotBufferO = path.join(outputDir.path, '$kDartIsolateSnapshotBuffer.o');
runCheckedSync(<String>['xcrun', 'cc', '-c', assembly, '-o', assemblyO]); if (!interpreter)
runCheckedSync(<String>['xcrun', 'cc', '-c', assembly, '-o', assemblyO]);
runCheckedSync(<String>['xcrun', 'cc', '-c', kDartVmIsolateSnapshotBufferC, '-o', kDartVmIsolateSnapshotBufferO]); runCheckedSync(<String>['xcrun', 'cc', '-c', kDartVmIsolateSnapshotBufferC, '-o', kDartVmIsolateSnapshotBufferO]);
runCheckedSync(<String>['xcrun', 'cc', '-c', kDartIsolateSnapshotBufferC, '-o', kDartIsolateSnapshotBufferO]); runCheckedSync(<String>['xcrun', 'cc', '-c', kDartIsolateSnapshotBufferC, '-o', kDartIsolateSnapshotBufferO]);
String appLib = path.join(outputDir.path, 'app.a'); String appLib = path.join(outputDir.path, 'app.a');
runCheckedSync(<String>['rm', '-f', appLib]); runCheckedSync(<String>['rm', '-f', appLib]);
runCheckedSync(<String>[ List<String> archiveCommand = <String>[
'xcrun', 'ar', 'rcs', appLib, 'xcrun', 'ar', 'rcs', appLib,
assemblyO, kDartVmIsolateSnapshotBufferO, kDartIsolateSnapshotBufferO, kDartVmIsolateSnapshotBufferO,
]); kDartIsolateSnapshotBufferO,
];
if (!interpreter)
archiveCommand.add(assemblyO);
runCheckedSync(archiveCommand);
} }
return outputPath; return outputPath;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment