Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cc0fdef

Browse files
authored
[web][felt] Add 'archive' target + 'profile' mode (#40060)
[web][felt] Add 'archive' target + 'profile' mode
1 parent 89627fd commit cc0fdef

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

lib/web_ui/dev/build.dart

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:io' show Directory;
76

87
import 'package:args/command_runner.dart';
98
import 'package:path/path.dart' as path;
@@ -13,12 +12,18 @@ import 'environment.dart';
1312
import 'pipeline.dart';
1413
import 'utils.dart';
1514

15+
enum RuntimeMode {
16+
profile,
17+
release,
18+
}
19+
1620
const Map<String, String> targetAliases = <String, String>{
1721
'sdk': 'flutter/web_sdk',
1822
'web_sdk': 'flutter/web_sdk',
1923
'canvaskit': 'flutter/third_party/canvaskit:canvaskit_group',
2024
'canvaskit_chromium': 'flutter/third_party/canvaskit:canvaskit_chromium_group',
2125
'skwasm': 'flutter/lib/web_ui/skwasm',
26+
'archive': 'flutter/web_sdk:flutter_web_sdk_archive',
2227
};
2328

2429
class BuildCommand extends Command<bool> with ArgUtils<bool> {
@@ -34,6 +39,12 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
3439
help: 'Build the host build instead of the wasm build, which is '
3540
'currently needed for `flutter run --local-engine` to work.'
3641
);
42+
argParser.addFlag(
43+
'profile',
44+
help: 'Build in profile mode instead of release mode. In this mode, the '
45+
'output will be located at "out/wasm_profile".\nThis only applies to '
46+
'the wasm build. The host build is always built in release mode.',
47+
);
3748
}
3849

3950
@override
@@ -46,15 +57,22 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
4657

4758
bool get host => boolArg('host');
4859

60+
RuntimeMode get runtimeMode =>
61+
boolArg('profile') ? RuntimeMode.profile : RuntimeMode.release;
62+
4963
List<String> get targets => argResults?.rest ?? <String>[];
5064

5165
@override
5266
FutureOr<bool> run() async {
5367
final FilePath libPath = FilePath.fromWebUi('lib');
5468
final List<PipelineStep> steps = <PipelineStep>[
55-
GnPipelineStep(host: host),
69+
GnPipelineStep(
70+
host: host,
71+
runtimeMode: runtimeMode,
72+
),
5673
NinjaPipelineStep(
57-
buildDirectory: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir,
74+
host: host,
75+
runtimeMode: runtimeMode,
5876
targets: targets.map((String target) => targetAliases[target] ?? target),
5977
),
6078
];
@@ -82,16 +100,27 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
82100
class GnPipelineStep extends ProcessStep {
83101
GnPipelineStep({
84102
required this.host,
103+
required this.runtimeMode,
85104
});
86105

87106
final bool host;
107+
final RuntimeMode runtimeMode;
88108

89109
@override
90110
String get description => 'gn';
91111

92112
@override
93113
bool get isSafeToInterrupt => false;
94114

115+
String get runtimeModeFlag {
116+
switch (runtimeMode) {
117+
case RuntimeMode.profile:
118+
return 'profile';
119+
case RuntimeMode.release:
120+
return 'release';
121+
}
122+
}
123+
95124
List<String> get _gnArgs {
96125
if (host) {
97126
return <String>[
@@ -101,7 +130,7 @@ class GnPipelineStep extends ProcessStep {
101130
} else {
102131
return <String>[
103132
'--web',
104-
'--runtime-mode=release',
133+
'--runtime-mode=$runtimeModeFlag',
105134
];
106135
}
107136
}
@@ -120,18 +149,33 @@ class GnPipelineStep extends ProcessStep {
120149
///
121150
/// Can be safely interrupted.
122151
class NinjaPipelineStep extends ProcessStep {
123-
NinjaPipelineStep({required this.buildDirectory, required this.targets});
152+
NinjaPipelineStep({
153+
required this.host,
154+
required this.runtimeMode,
155+
required this.targets,
156+
});
124157

125158
@override
126159
String get description => 'ninja';
127160

128161
@override
129162
bool get isSafeToInterrupt => true;
130163

131-
/// The directory to build.
132-
final Directory buildDirectory;
133-
164+
final bool host;
134165
final Iterable<String> targets;
166+
final RuntimeMode runtimeMode;
167+
168+
String get buildDirectory {
169+
if (host) {
170+
return environment.hostDebugUnoptDir.path;
171+
}
172+
switch (runtimeMode) {
173+
case RuntimeMode.profile:
174+
return environment.wasmProfileOutDir.path;
175+
case RuntimeMode.release:
176+
return environment.wasmReleaseOutDir.path;
177+
}
178+
}
135179

136180
@override
137181
Future<ProcessManager> createProcess() {
@@ -140,7 +184,7 @@ class NinjaPipelineStep extends ProcessStep {
140184
'autoninja',
141185
<String>[
142186
'-C',
143-
buildDirectory.path,
187+
buildDirectory,
144188
...targets,
145189
],
146190
);

lib/web_ui/dev/environment.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Environment {
3030
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
3131
final io.Directory wasmReleaseOutDir =
3232
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
33+
final io.Directory wasmProfileOutDir =
34+
io.Directory(pathlib.join(outDir.path, 'wasm_profile'));
3335
final io.Directory hostDebugUnoptDir =
3436
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
3537
final io.Directory dartSdkDir = dartExecutable.parent.parent;
@@ -54,6 +56,7 @@ class Environment {
5456
engineToolsDir: engineToolsDir,
5557
outDir: outDir,
5658
wasmReleaseOutDir: wasmReleaseOutDir,
59+
wasmProfileOutDir: wasmProfileOutDir,
5760
hostDebugUnoptDir: hostDebugUnoptDir,
5861
dartSdkDir: dartSdkDir,
5962
);
@@ -67,6 +70,7 @@ class Environment {
6770
required this.engineToolsDir,
6871
required this.outDir,
6972
required this.wasmReleaseOutDir,
73+
required this.wasmProfileOutDir,
7074
required this.hostDebugUnoptDir,
7175
required this.dartSdkDir,
7276
});
@@ -96,6 +100,9 @@ class Environment {
96100
/// We build CanvasKit in release mode to reduce code size.
97101
final io.Directory wasmReleaseOutDir;
98102

103+
/// The output directory for the wasm_profile build.
104+
final io.Directory wasmProfileOutDir;
105+
99106
/// The output directory for the host_debug_unopt build.
100107
final io.Directory hostDebugUnoptDir;
101108

0 commit comments

Comments
 (0)