From 7cc3c8bdb6d3edb51a2e66bfeb7ddcc6c1ff8542 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 24 Oct 2023 13:39:46 -0400 Subject: [PATCH] Make FrontendServerClient start the frontend server from AOT snapshot by default --- .../lib/src/frontend_server_client.dart | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/frontend_server_client/lib/src/frontend_server_client.dart b/frontend_server_client/lib/src/frontend_server_client.dart index cd91511d5..563ea446a 100644 --- a/frontend_server_client/lib/src/frontend_server_client.dart +++ b/frontend_server_client/lib/src/frontend_server_client.dart @@ -40,6 +40,15 @@ class FrontendServerClient { /// The [outputDillPath] determines where the primary output should be, and /// some targets may output additional files based on that file name (by /// adding file extensions for instance). + /// + /// When the [frontendServerPath] argument is provided, the frontend server + /// will be started from the specified file. The specified file can either be + /// a Dart source file or an AppJIT snapshot. + /// + /// When the [frontendServerPath] argument is provided, setting [debug] to + /// true permits debuggers to attach to the frontend server. When the + /// [frontendServerPath] argument is omitted, the value of the [debug] + /// argument is ignored. static Future start( String entrypoint, String outputDillPath, @@ -60,9 +69,7 @@ class FrontendServerClient { List additionalSources = const [], String? nativeAssets, }) async { - var feServer = await Process.start(Platform.resolvedExecutable, [ - if (debug) '--observe', - frontendServerPath ?? _feServerPath, + final commonArguments = [ '--sdk-root', sdkRoot ?? sdkDir, '--platform=$platformKernel', @@ -90,7 +97,34 @@ class FrontendServerClient { '--native-assets', nativeAssets, ], - ]); + ]; + late final Process feServer; + if (frontendServerPath != null) { + feServer = await Process.start( + Platform.resolvedExecutable, + [ + if (debug) '--observe', + frontendServerPath, + ] + + commonArguments, + ); + } else if (File(_feServerAotSnapshotPath).existsSync()) { + feServer = await Process.start( + _dartAotRuntimePath, + [_feServerAotSnapshotPath] + commonArguments, + ); + } else { + // AOT snapshots cannot be generated on IA32, so we need this fallback + // branch until support for IA32 is dropped (https://dartbug.com/49969). + feServer = await Process.start( + Platform.resolvedExecutable, + [ + if (debug) '--observe', + _feServerAppJitSnapshotPath, + ] + + commonArguments, + ); + } var feServerStdoutLines = StreamQueue(feServer.stdout .transform(utf8.decoder) .transform(const LineSplitter())); @@ -407,5 +441,10 @@ enum _RejectState { done, } -final _feServerPath = +final _dartAotRuntimePath = p.join(sdkDir, 'bin', 'dartaotruntime'); + +final _feServerAppJitSnapshotPath = p.join(sdkDir, 'bin', 'snapshots', 'frontend_server.dart.snapshot'); + +final _feServerAotSnapshotPath = + p.join(sdkDir, 'bin', 'snapshots', 'frontend_server_aot.dart.snapshot');