Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io' show Directory;

import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;
Expand All @@ -13,12 +12,18 @@ import 'environment.dart';
import 'pipeline.dart';
import 'utils.dart';

enum RuntimeMode {
profile,
release,
}

const Map<String, String> targetAliases = <String, String>{
'sdk': 'flutter/web_sdk',
'web_sdk': 'flutter/web_sdk',
'canvaskit': 'flutter/third_party/canvaskit:canvaskit_group',
'canvaskit_chromium': 'flutter/third_party/canvaskit:canvaskit_chromium_group',
'skwasm': 'flutter/lib/web_ui/skwasm',
'archive': 'flutter/web_sdk:flutter_web_sdk_archive',
};

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

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

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

RuntimeMode get runtimeMode =>
boolArg('profile') ? RuntimeMode.profile : RuntimeMode.release;

List<String> get targets => argResults?.rest ?? <String>[];

@override
FutureOr<bool> run() async {
final FilePath libPath = FilePath.fromWebUi('lib');
final List<PipelineStep> steps = <PipelineStep>[
GnPipelineStep(host: host),
GnPipelineStep(
host: host,
runtimeMode: runtimeMode,
),
NinjaPipelineStep(
buildDirectory: host ? environment.hostDebugUnoptDir : environment.wasmReleaseOutDir,
host: host,
runtimeMode: runtimeMode,
targets: targets.map((String target) => targetAliases[target] ?? target),
),
];
Expand Down Expand Up @@ -82,16 +100,27 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
class GnPipelineStep extends ProcessStep {
GnPipelineStep({
required this.host,
required this.runtimeMode,
});

final bool host;
final RuntimeMode runtimeMode;

@override
String get description => 'gn';

@override
bool get isSafeToInterrupt => false;

String get runtimeModeFlag {
switch (runtimeMode) {
case RuntimeMode.profile:
return 'profile';
case RuntimeMode.release:
return 'release';
}
}

List<String> get _gnArgs {
if (host) {
return <String>[
Expand All @@ -101,7 +130,7 @@ class GnPipelineStep extends ProcessStep {
} else {
return <String>[
'--web',
'--runtime-mode=release',
'--runtime-mode=$runtimeModeFlag',
];
}
}
Expand All @@ -120,18 +149,33 @@ class GnPipelineStep extends ProcessStep {
///
/// Can be safely interrupted.
class NinjaPipelineStep extends ProcessStep {
NinjaPipelineStep({required this.buildDirectory, required this.targets});
NinjaPipelineStep({
required this.host,
required this.runtimeMode,
required this.targets,
});

@override
String get description => 'ninja';

@override
bool get isSafeToInterrupt => true;

/// The directory to build.
final Directory buildDirectory;

final bool host;
final Iterable<String> targets;
final RuntimeMode runtimeMode;

String get buildDirectory {
if (host) {
return environment.hostDebugUnoptDir.path;
}
switch (runtimeMode) {
case RuntimeMode.profile:
return environment.wasmProfileOutDir.path;
case RuntimeMode.release:
return environment.wasmReleaseOutDir.path;
}
}

@override
Future<ProcessManager> createProcess() {
Expand All @@ -140,7 +184,7 @@ class NinjaPipelineStep extends ProcessStep {
'autoninja',
<String>[
'-C',
buildDirectory.path,
buildDirectory,
...targets,
],
);
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/dev/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Environment {
io.Directory(pathlib.join(engineSrcDir.path, 'out'));
final io.Directory wasmReleaseOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_release'));
final io.Directory wasmProfileOutDir =
io.Directory(pathlib.join(outDir.path, 'wasm_profile'));
final io.Directory hostDebugUnoptDir =
io.Directory(pathlib.join(outDir.path, 'host_debug_unopt'));
final io.Directory dartSdkDir = dartExecutable.parent.parent;
Expand All @@ -54,6 +56,7 @@ class Environment {
engineToolsDir: engineToolsDir,
outDir: outDir,
wasmReleaseOutDir: wasmReleaseOutDir,
wasmProfileOutDir: wasmProfileOutDir,
hostDebugUnoptDir: hostDebugUnoptDir,
dartSdkDir: dartSdkDir,
);
Expand All @@ -67,6 +70,7 @@ class Environment {
required this.engineToolsDir,
required this.outDir,
required this.wasmReleaseOutDir,
required this.wasmProfileOutDir,
required this.hostDebugUnoptDir,
required this.dartSdkDir,
});
Expand Down Expand Up @@ -96,6 +100,9 @@ class Environment {
/// We build CanvasKit in release mode to reduce code size.
final io.Directory wasmReleaseOutDir;

/// The output directory for the wasm_profile build.
final io.Directory wasmProfileOutDir;

/// The output directory for the host_debug_unopt build.
final io.Directory hostDebugUnoptDir;

Expand Down