Skip to content

Commit 7cc3c8b

Browse files
committed
Make FrontendServerClient start the frontend server from AOT snapshot by default
1 parent 2d8e9c2 commit 7cc3c8b

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

frontend_server_client/lib/src/frontend_server_client.dart

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class FrontendServerClient {
4040
/// The [outputDillPath] determines where the primary output should be, and
4141
/// some targets may output additional files based on that file name (by
4242
/// adding file extensions for instance).
43+
///
44+
/// When the [frontendServerPath] argument is provided, the frontend server
45+
/// will be started from the specified file. The specified file can either be
46+
/// a Dart source file or an AppJIT snapshot.
47+
///
48+
/// When the [frontendServerPath] argument is provided, setting [debug] to
49+
/// true permits debuggers to attach to the frontend server. When the
50+
/// [frontendServerPath] argument is omitted, the value of the [debug]
51+
/// argument is ignored.
4352
static Future<FrontendServerClient> start(
4453
String entrypoint,
4554
String outputDillPath,
@@ -60,9 +69,7 @@ class FrontendServerClient {
6069
List<String> additionalSources = const [],
6170
String? nativeAssets,
6271
}) async {
63-
var feServer = await Process.start(Platform.resolvedExecutable, [
64-
if (debug) '--observe',
65-
frontendServerPath ?? _feServerPath,
72+
final commonArguments = <String>[
6673
'--sdk-root',
6774
sdkRoot ?? sdkDir,
6875
'--platform=$platformKernel',
@@ -90,7 +97,34 @@ class FrontendServerClient {
9097
'--native-assets',
9198
nativeAssets,
9299
],
93-
]);
100+
];
101+
late final Process feServer;
102+
if (frontendServerPath != null) {
103+
feServer = await Process.start(
104+
Platform.resolvedExecutable,
105+
<String>[
106+
if (debug) '--observe',
107+
frontendServerPath,
108+
] +
109+
commonArguments,
110+
);
111+
} else if (File(_feServerAotSnapshotPath).existsSync()) {
112+
feServer = await Process.start(
113+
_dartAotRuntimePath,
114+
<String>[_feServerAotSnapshotPath] + commonArguments,
115+
);
116+
} else {
117+
// AOT snapshots cannot be generated on IA32, so we need this fallback
118+
// branch until support for IA32 is dropped (https://dartbug.com/49969).
119+
feServer = await Process.start(
120+
Platform.resolvedExecutable,
121+
<String>[
122+
if (debug) '--observe',
123+
_feServerAppJitSnapshotPath,
124+
] +
125+
commonArguments,
126+
);
127+
}
94128
var feServerStdoutLines = StreamQueue(feServer.stdout
95129
.transform(utf8.decoder)
96130
.transform(const LineSplitter()));
@@ -407,5 +441,10 @@ enum _RejectState {
407441
done,
408442
}
409443

410-
final _feServerPath =
444+
final _dartAotRuntimePath = p.join(sdkDir, 'bin', 'dartaotruntime');
445+
446+
final _feServerAppJitSnapshotPath =
411447
p.join(sdkDir, 'bin', 'snapshots', 'frontend_server.dart.snapshot');
448+
449+
final _feServerAotSnapshotPath =
450+
p.join(sdkDir, 'bin', 'snapshots', 'frontend_server_aot.dart.snapshot');

0 commit comments

Comments
 (0)