Revert Dual Web Compile changes (#143175)
Dual Web Compile has had some issues where `flutter test` is not respecting the `--web-renderer` flag for some reason. I haven't gotten entirely to the bottom of the issue, but for now we need to rever these changes while I investigate. This reverts the following PRs: https://github.com/flutter/flutter/pull/143128 https://github.com/flutter/flutter/pull/141396 While doing this revert, I had a few merge conflicts with https://github.com/flutter/flutter/pull/142760, and I tried to resolve the merge conflicts within the spirit of that PR's change, but @chingjun I might need your input on whether the imports I have modified are okay with regards to the change you were making.
This commit is contained in:
@@ -12,6 +12,7 @@ import 'base/os.dart';
|
||||
import 'base/utils.dart';
|
||||
import 'convert.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'web/compile.dart';
|
||||
|
||||
/// Whether icon font subsetting is enabled by default.
|
||||
const bool kIconTreeShakerEnabledDefault = true;
|
||||
@@ -35,6 +36,7 @@ class BuildInfo {
|
||||
List<String>? dartDefines,
|
||||
this.bundleSkSLPath,
|
||||
List<String>? dartExperiments,
|
||||
this.webRenderer = WebRendererMode.auto,
|
||||
required this.treeShakeIcons,
|
||||
this.performanceMeasurementFile,
|
||||
this.packagesPath = '.dart_tool/package_config.json', // TODO(zanderso): make this required and remove the default.
|
||||
@@ -128,6 +130,9 @@ class BuildInfo {
|
||||
/// A list of Dart experiments.
|
||||
final List<String> dartExperiments;
|
||||
|
||||
/// When compiling to web, which web renderer mode we are using (html, canvaskit, auto)
|
||||
final WebRendererMode webRenderer;
|
||||
|
||||
/// The name of a file where flutter assemble will output performance
|
||||
/// information in a JSON format.
|
||||
///
|
||||
@@ -793,6 +798,10 @@ HostPlatform getCurrentHostPlatform() {
|
||||
return HostPlatform.linux_x64;
|
||||
}
|
||||
|
||||
FileSystemEntity getWebPlatformBinariesDirectory(Artifacts artifacts, WebRendererMode webRenderer) {
|
||||
return artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder);
|
||||
}
|
||||
|
||||
/// Returns the top-level build output directory.
|
||||
String getBuildDirectory([Config? config, FileSystem? fileSystem]) {
|
||||
// TODO(johnmccutchan): Stop calling this function as part of setting
|
||||
@@ -835,8 +844,8 @@ String getMacOSBuildDirectory() {
|
||||
}
|
||||
|
||||
/// Returns the web build output directory.
|
||||
String getWebBuildDirectory() {
|
||||
return globals.fs.path.join(getBuildDirectory(), 'web');
|
||||
String getWebBuildDirectory([bool isWasm = false]) {
|
||||
return globals.fs.path.join(getBuildDirectory(), isWasm ? 'web_wasm' : 'web');
|
||||
}
|
||||
|
||||
/// Returns the Linux build output directory.
|
||||
|
||||
@@ -136,15 +136,6 @@ abstract class Target {
|
||||
/// A list of zero or more depfiles, located directly under {BUILD_DIR}.
|
||||
List<String> get depfiles => const <String>[];
|
||||
|
||||
/// A string that differentiates different build variants from each other
|
||||
/// with regards to build flags or settings on the target. This string should
|
||||
/// represent each build variant as a different unique value. If this value
|
||||
/// changes between builds, the target will be invalidated and rebuilt.
|
||||
///
|
||||
/// By default, this returns null, which indicates there is only one build
|
||||
/// variant, and the target won't invalidate or rebuild due to this property.
|
||||
String? get buildKey => null;
|
||||
|
||||
/// Whether this target can be executed with the given [environment].
|
||||
///
|
||||
/// Returning `true` will cause [build] to be skipped. This is equivalent
|
||||
@@ -165,7 +156,6 @@ abstract class Target {
|
||||
<Node>[
|
||||
for (final Target target in dependencies) target._toNode(environment),
|
||||
],
|
||||
buildKey,
|
||||
environment,
|
||||
inputsFiles.containsNewDepfile,
|
||||
);
|
||||
@@ -191,11 +181,9 @@ abstract class Target {
|
||||
for (final File output in outputs) {
|
||||
outputPaths.add(output.path);
|
||||
}
|
||||
final String? key = buildKey;
|
||||
final Map<String, Object> result = <String, Object>{
|
||||
'inputs': inputPaths,
|
||||
'outputs': outputPaths,
|
||||
if (key != null) 'buildKey': key,
|
||||
};
|
||||
if (!stamp.existsSync()) {
|
||||
stamp.createSync();
|
||||
@@ -230,7 +218,6 @@ abstract class Target {
|
||||
/// This requires constants from the [Environment] to resolve the paths of
|
||||
/// inputs and the output stamp.
|
||||
Map<String, Object> toJson(Environment environment) {
|
||||
final String? key = buildKey;
|
||||
return <String, Object>{
|
||||
'name': name,
|
||||
'dependencies': <String>[
|
||||
@@ -242,7 +229,6 @@ abstract class Target {
|
||||
'outputs': <String>[
|
||||
for (final File file in resolveOutputs(environment).sources) file.path,
|
||||
],
|
||||
if (key != null) 'buildKey': key,
|
||||
'stamp': _findStampFile(environment).absolute.path,
|
||||
};
|
||||
}
|
||||
@@ -994,85 +980,49 @@ void verifyOutputDirectories(List<File> outputs, Environment environment, Target
|
||||
|
||||
/// A node in the build graph.
|
||||
class Node {
|
||||
factory Node(
|
||||
Target target,
|
||||
List<File> inputs,
|
||||
List<File> outputs,
|
||||
List<Node> dependencies,
|
||||
String? buildKey,
|
||||
Node(
|
||||
this.target,
|
||||
this.inputs,
|
||||
this.outputs,
|
||||
this.dependencies,
|
||||
Environment environment,
|
||||
bool missingDepfile,
|
||||
this.missingDepfile,
|
||||
) {
|
||||
final File stamp = target._findStampFile(environment);
|
||||
Map<String, Object?>? stampValues;
|
||||
|
||||
// If the stamp file doesn't exist, we haven't run this step before and
|
||||
// all inputs were added.
|
||||
if (stamp.existsSync()) {
|
||||
final String content = stamp.readAsStringSync();
|
||||
if (content.isEmpty) {
|
||||
stamp.deleteSync();
|
||||
} else {
|
||||
try {
|
||||
stampValues = castStringKeyedMap(json.decode(content));
|
||||
} on FormatException {
|
||||
// The json is malformed in some way.
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stampValues != null) {
|
||||
final String? previousBuildKey = stampValues['buildKey'] as String?;
|
||||
final Object? stampInputs = stampValues['inputs'];
|
||||
final Object? stampOutputs = stampValues['outputs'];
|
||||
if (stampInputs is List<Object?> && stampOutputs is List<Object?>) {
|
||||
final Set<String> previousInputs = stampInputs.whereType<String>().toSet();
|
||||
final Set<String> previousOutputs = stampOutputs.whereType<String>().toSet();
|
||||
return Node.withStamp(
|
||||
target,
|
||||
inputs,
|
||||
previousInputs,
|
||||
outputs,
|
||||
previousOutputs,
|
||||
dependencies,
|
||||
buildKey,
|
||||
previousBuildKey,
|
||||
missingDepfile,
|
||||
);
|
||||
}
|
||||
}
|
||||
return Node.withNoStamp(
|
||||
target,
|
||||
inputs,
|
||||
outputs,
|
||||
dependencies,
|
||||
buildKey,
|
||||
missingDepfile,
|
||||
);
|
||||
}
|
||||
|
||||
Node.withNoStamp(
|
||||
this.target,
|
||||
this.inputs,
|
||||
this.outputs,
|
||||
this.dependencies,
|
||||
this.buildKey,
|
||||
this.missingDepfile,
|
||||
) : previousInputs = <String>{},
|
||||
previousOutputs = <String>{},
|
||||
previousBuildKey = null,
|
||||
if (!stamp.existsSync()) {
|
||||
// No stamp file, not safe to skip.
|
||||
_dirty = true;
|
||||
|
||||
Node.withStamp(
|
||||
this.target,
|
||||
this.inputs,
|
||||
this.previousInputs,
|
||||
this.outputs,
|
||||
this.previousOutputs,
|
||||
this.dependencies,
|
||||
this.buildKey,
|
||||
this.previousBuildKey,
|
||||
this.missingDepfile,
|
||||
) : _dirty = false;
|
||||
return;
|
||||
}
|
||||
final String content = stamp.readAsStringSync();
|
||||
// Something went wrong writing the stamp file.
|
||||
if (content.isEmpty) {
|
||||
stamp.deleteSync();
|
||||
// Malformed stamp file, not safe to skip.
|
||||
_dirty = true;
|
||||
return;
|
||||
}
|
||||
Map<String, Object?>? values;
|
||||
try {
|
||||
values = castStringKeyedMap(json.decode(content));
|
||||
} on FormatException {
|
||||
// The json is malformed in some way.
|
||||
_dirty = true;
|
||||
return;
|
||||
}
|
||||
final Object? inputs = values?['inputs'];
|
||||
final Object? outputs = values?['outputs'];
|
||||
if (inputs is List<Object?> && outputs is List<Object?>) {
|
||||
inputs.cast<String?>().whereType<String>().forEach(previousInputs.add);
|
||||
outputs.cast<String?>().whereType<String>().forEach(previousOutputs.add);
|
||||
} else {
|
||||
// The json is malformed in some way.
|
||||
_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// The resolved input files.
|
||||
///
|
||||
@@ -1084,11 +1034,6 @@ class Node {
|
||||
/// These files may not yet exist if the target hasn't run yet.
|
||||
final List<File> outputs;
|
||||
|
||||
/// The current build key of the target
|
||||
///
|
||||
/// See `buildKey` in the `Target` class for more information.
|
||||
final String? buildKey;
|
||||
|
||||
/// Whether this node is missing a depfile.
|
||||
///
|
||||
/// This requires an additional pass of source resolution after the target
|
||||
@@ -1102,15 +1047,10 @@ class Node {
|
||||
final List<Node> dependencies;
|
||||
|
||||
/// Output file paths from the previous invocation of this build node.
|
||||
final Set<String> previousOutputs;
|
||||
final Set<String> previousOutputs = <String>{};
|
||||
|
||||
/// Input file paths from the previous invocation of this build node.
|
||||
final Set<String> previousInputs;
|
||||
|
||||
/// The buildKey from the previous invocation of this build node.
|
||||
///
|
||||
/// See `buildKey` in the `Target` class for more information.
|
||||
final String? previousBuildKey;
|
||||
final Set<String> previousInputs = <String>{};
|
||||
|
||||
/// One or more reasons why a task was invalidated.
|
||||
///
|
||||
@@ -1134,10 +1074,6 @@ class Node {
|
||||
FileSystem fileSystem,
|
||||
Logger logger,
|
||||
) {
|
||||
if (buildKey != previousBuildKey) {
|
||||
_invalidate(InvalidatedReasonKind.buildKeyChanged);
|
||||
_dirty = true;
|
||||
}
|
||||
final Set<String> currentOutputPaths = <String>{
|
||||
for (final File file in outputs) file.path,
|
||||
};
|
||||
@@ -1237,8 +1173,7 @@ class InvalidatedReason {
|
||||
InvalidatedReasonKind.inputChanged => 'The following inputs have updated contents: ${data.join(',')}',
|
||||
InvalidatedReasonKind.outputChanged => 'The following outputs have updated contents: ${data.join(',')}',
|
||||
InvalidatedReasonKind.outputMissing => 'The following outputs were missing: ${data.join(',')}',
|
||||
InvalidatedReasonKind.outputSetChanged => 'The following outputs were removed from the output set: ${data.join(',')}',
|
||||
InvalidatedReasonKind.buildKeyChanged => 'The target build key changed.',
|
||||
InvalidatedReasonKind.outputSetChanged => 'The following outputs were removed from the output set: ${data.join(',')}'
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1260,7 +1195,4 @@ enum InvalidatedReasonKind {
|
||||
|
||||
/// The set of expected output files changed.
|
||||
outputSetChanged,
|
||||
|
||||
/// The build key changed
|
||||
buildKeyChanged,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../web/compiler_config.dart';
|
||||
import '../web/compile.dart';
|
||||
import './build_system.dart';
|
||||
|
||||
/// Commonly used build [Target]s.
|
||||
@@ -14,7 +14,11 @@ abstract class BuildTargets {
|
||||
Target get releaseCopyFlutterBundle;
|
||||
Target get generateLocalizationsTarget;
|
||||
Target get dartPluginRegistrantTarget;
|
||||
Target webServiceWorker(FileSystem fileSystem, List<WebCompilerConfig> compileConfigs);
|
||||
Target webServiceWorker(
|
||||
FileSystem fileSystem, {
|
||||
required WebRendererMode webRenderer,
|
||||
required bool isWasm
|
||||
});
|
||||
}
|
||||
|
||||
/// BuildTargets that return NoOpTarget for every action.
|
||||
@@ -34,7 +38,11 @@ class NoOpBuildTargets extends BuildTargets {
|
||||
Target get dartPluginRegistrantTarget => const _NoOpTarget();
|
||||
|
||||
@override
|
||||
Target webServiceWorker(FileSystem fileSystem, List<WebCompilerConfig> compileConfigs) => const _NoOpTarget();
|
||||
Target webServiceWorker(
|
||||
FileSystem fileSystem, {
|
||||
required WebRendererMode webRenderer,
|
||||
required bool isWasm,
|
||||
}) => const _NoOpTarget();
|
||||
}
|
||||
|
||||
/// A [Target] that does nothing.
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
|
||||
import '../../artifacts.dart';
|
||||
@@ -23,23 +22,13 @@ import '../../project.dart';
|
||||
import '../../web/compile.dart';
|
||||
import '../../web/file_generators/flutter_service_worker_js.dart';
|
||||
import '../../web/file_generators/main_dart.dart' as main_dart;
|
||||
import '../../web/file_generators/wasm_bootstrap.dart' as wasm_bootstrap;
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import '../exceptions.dart';
|
||||
import 'assets.dart';
|
||||
import 'localizations.dart';
|
||||
|
||||
@visibleForTesting
|
||||
List<String> updateDartDefines(List<String> dartDefines, WebRendererMode webRenderer) {
|
||||
final Set<String> dartDefinesSet = dartDefines.toSet();
|
||||
if (!dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_AUTO_DETECT='))
|
||||
&& dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {
|
||||
dartDefinesSet.removeWhere((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='));
|
||||
}
|
||||
dartDefinesSet.addAll(webRenderer.dartDefines);
|
||||
return dartDefinesSet.toList();
|
||||
}
|
||||
|
||||
/// Generates an entry point for a web target.
|
||||
// Keep this in sync with build_runner/resident_web_runner.dart
|
||||
class WebEntrypointTarget extends Target {
|
||||
@@ -106,15 +95,11 @@ class WebEntrypointTarget extends Target {
|
||||
|
||||
/// Compiles a web entry point with dart2js.
|
||||
abstract class Dart2WebTarget extends Target {
|
||||
const Dart2WebTarget();
|
||||
const Dart2WebTarget(this.webRenderer);
|
||||
|
||||
final WebRendererMode webRenderer;
|
||||
Source get compilerSnapshot;
|
||||
|
||||
WebCompilerConfig get compilerConfig;
|
||||
|
||||
Map<String, Object?> get buildConfig;
|
||||
List<String> get buildFiles;
|
||||
|
||||
@override
|
||||
List<Target> get dependencies => const <Target>[
|
||||
WebEntrypointTarget(),
|
||||
@@ -131,19 +116,11 @@ abstract class Dart2WebTarget extends Target {
|
||||
];
|
||||
|
||||
@override
|
||||
List<Source> get outputs => buildFiles.map(
|
||||
(String file) => Source.pattern('{BUILD_DIR}/$file')
|
||||
).toList();
|
||||
|
||||
@override
|
||||
String get buildKey => compilerConfig.buildKey;
|
||||
List<Source> get outputs => const <Source>[];
|
||||
}
|
||||
|
||||
class Dart2JSTarget extends Dart2WebTarget {
|
||||
Dart2JSTarget(this.compilerConfig);
|
||||
|
||||
@override
|
||||
final JsCompilerConfig compilerConfig;
|
||||
Dart2JSTarget(super.webRenderer);
|
||||
|
||||
@override
|
||||
String get name => 'dart2js';
|
||||
@@ -163,12 +140,9 @@ class Dart2JSTarget extends Dart2WebTarget {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
|
||||
final JsCompilerConfig compilerConfig = JsCompilerConfig.fromBuildSystemEnvironment(environment.defines);
|
||||
final Artifacts artifacts = environment.artifacts;
|
||||
final String platformBinariesPath = artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder).path;
|
||||
final List<String> dartDefines = updateDartDefines(
|
||||
decodeDartDefines(environment.defines, kDartDefines),
|
||||
compilerConfig.renderer,
|
||||
);
|
||||
final String platformBinariesPath = getWebPlatformBinariesDirectory(artifacts, webRenderer).path;
|
||||
final List<String> sharedCommandOptions = <String>[
|
||||
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
|
||||
'--disable-dart-dev',
|
||||
@@ -180,7 +154,7 @@ class Dart2JSTarget extends Dart2WebTarget {
|
||||
'-Ddart.vm.profile=true'
|
||||
else
|
||||
'-Ddart.vm.product=true',
|
||||
for (final String dartDefine in dartDefines)
|
||||
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
|
||||
'-D$dartDefine',
|
||||
];
|
||||
|
||||
@@ -234,25 +208,10 @@ class Dart2JSTarget extends Dart2WebTarget {
|
||||
environment.buildDir.childFile('dart2js.d'),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, Object?> get buildConfig => <String, Object?>{
|
||||
'compileTarget': 'dart2js',
|
||||
'renderer': compilerConfig.renderer.name,
|
||||
'mainJsPath': 'main.dart.js',
|
||||
};
|
||||
|
||||
@override
|
||||
List<String> get buildFiles => <String>[
|
||||
'main.dart.js',
|
||||
];
|
||||
}
|
||||
|
||||
class Dart2WasmTarget extends Dart2WebTarget {
|
||||
Dart2WasmTarget(this.compilerConfig);
|
||||
|
||||
@override
|
||||
final WasmCompilerConfig compilerConfig;
|
||||
Dart2WasmTarget(super.webRenderer);
|
||||
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
@@ -260,6 +219,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
|
||||
if (buildModeEnvironment == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final WasmCompilerConfig compilerConfig = WasmCompilerConfig.fromBuildSystemEnvironment(environment.defines);
|
||||
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
|
||||
final Artifacts artifacts = environment.artifacts;
|
||||
final File outputWasmFile = environment.buildDir.childFile(
|
||||
@@ -267,12 +227,8 @@ class Dart2WasmTarget extends Dart2WebTarget {
|
||||
);
|
||||
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||
final String dartSdkPath = artifacts.getArtifactPath(Artifact.engineDartSdkPath, platform: TargetPlatform.web_javascript);
|
||||
final String platformBinariesPath = artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder).path;
|
||||
final String platformBinariesPath = getWebPlatformBinariesDirectory(artifacts, webRenderer).path;
|
||||
final String platformFilePath = environment.fileSystem.path.join(platformBinariesPath, 'dart2wasm_platform.dill');
|
||||
final List<String> dartDefines = updateDartDefines(
|
||||
decodeDartDefines(environment.defines, kDartDefines),
|
||||
compilerConfig.renderer,
|
||||
);
|
||||
|
||||
final List<String> compilationArgs = <String>[
|
||||
artifacts.getArtifactPath(Artifact.engineDartAotRuntime, platform: TargetPlatform.web_javascript),
|
||||
@@ -286,10 +242,10 @@ class Dart2WasmTarget extends Dart2WebTarget {
|
||||
else
|
||||
'-Ddart.vm.product=true',
|
||||
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
|
||||
for (final String dartDefine in dartDefines)
|
||||
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
|
||||
'-D$dartDefine',
|
||||
...compilerConfig.toCommandOptions(),
|
||||
if (compilerConfig.renderer == WebRendererMode.skwasm)
|
||||
if (webRenderer == WebRendererMode.skwasm)
|
||||
...<String>[
|
||||
'--import-shared-memory',
|
||||
'--shared-memory-max-pages=32768',
|
||||
@@ -354,75 +310,74 @@ class Dart2WasmTarget extends Dart2WebTarget {
|
||||
];
|
||||
|
||||
@override
|
||||
Map<String, Object?> get buildConfig => <String, Object?>{
|
||||
'compileTarget': 'dart2wasm',
|
||||
'renderer': compilerConfig.renderer.name,
|
||||
'mainWasmPath': 'main.dart.wasm',
|
||||
'jsSupportRuntimePath': 'main.dart.mjs',
|
||||
};
|
||||
|
||||
@override
|
||||
List<String> get buildFiles => <String>[
|
||||
'main.dart.wasm',
|
||||
'main.dart.mjs',
|
||||
List<Source> get outputs => const <Source>[
|
||||
Source.pattern('{OUTPUT_DIR}/main.dart.wasm'),
|
||||
Source.pattern('{OUTPUT_DIR}/main.dart.mjs'),
|
||||
];
|
||||
}
|
||||
|
||||
/// Unpacks the dart2js or dart2wasm compilation and resources to a given
|
||||
/// output directory.
|
||||
class WebReleaseBundle extends Target {
|
||||
WebReleaseBundle(List<WebCompilerConfig> configs) : this._withTargets(
|
||||
configs.map((WebCompilerConfig config) =>
|
||||
switch (config) {
|
||||
WasmCompilerConfig() => Dart2WasmTarget(config),
|
||||
JsCompilerConfig() => Dart2JSTarget(config),
|
||||
}
|
||||
).toList()
|
||||
);
|
||||
const WebReleaseBundle(this.webRenderer, {required this.isWasm});
|
||||
|
||||
const WebReleaseBundle._withTargets(this.compileTargets);
|
||||
final WebRendererMode webRenderer;
|
||||
final bool isWasm;
|
||||
|
||||
final List<Dart2WebTarget> compileTargets;
|
||||
|
||||
List<String> get buildFiles => compileTargets.fold(
|
||||
const Iterable<String>.empty(),
|
||||
(Iterable<String> current, Dart2WebTarget target) => current.followedBy(target.buildFiles)
|
||||
).toList();
|
||||
String get outputFileNameNoSuffix => 'main.dart';
|
||||
String get outputFileName => '$outputFileNameNoSuffix${isWasm ? '.wasm' : '.js'}';
|
||||
String get wasmJSRuntimeFileName => '$outputFileNameNoSuffix.mjs';
|
||||
|
||||
@override
|
||||
String get name => 'web_release_bundle';
|
||||
|
||||
@override
|
||||
List<Target> get dependencies => compileTargets;
|
||||
List<Target> get dependencies => <Target>[
|
||||
if (isWasm) Dart2WasmTarget(webRenderer) else Dart2JSTarget(webRenderer),
|
||||
];
|
||||
|
||||
@override
|
||||
List<Source> get inputs => <Source>[
|
||||
Source.pattern('{BUILD_DIR}/$outputFileName'),
|
||||
const Source.pattern('{PROJECT_DIR}/pubspec.yaml'),
|
||||
...buildFiles.map((String file) => Source.pattern('{BUILD_DIR}/$file'))
|
||||
if (isWasm) Source.pattern('{BUILD_DIR}/$wasmJSRuntimeFileName'),
|
||||
];
|
||||
|
||||
@override
|
||||
List<Source> get outputs => <Source>[
|
||||
...buildFiles.map((String file) => Source.pattern('{OUTPUT_DIR}/$file'))
|
||||
Source.pattern('{OUTPUT_DIR}/$outputFileName'),
|
||||
if (isWasm) Source.pattern('{OUTPUT_DIR}/$wasmJSRuntimeFileName'),
|
||||
];
|
||||
|
||||
@override
|
||||
List<String> get depfiles => const <String>[
|
||||
'dart2js.d',
|
||||
'flutter_assets.d',
|
||||
'web_resources.d',
|
||||
];
|
||||
|
||||
bool shouldCopy(String name) =>
|
||||
// Do not copy the deps file.
|
||||
(name.contains(outputFileName) && !name.endsWith('.deps')) ||
|
||||
(isWasm && name == wasmJSRuntimeFileName);
|
||||
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
for (final File outputFile in environment.buildDir.listSync(recursive: true).whereType<File>()) {
|
||||
final String basename = environment.fileSystem.path.basename(outputFile.path);
|
||||
if (buildFiles.contains(basename)) {
|
||||
if (shouldCopy(basename)) {
|
||||
outputFile.copySync(
|
||||
environment.outputDir.childFile(environment.fileSystem.path.basename(outputFile.path)).path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isWasm) {
|
||||
// TODO(jacksongardner): Enable icon tree shaking once dart2wasm can do a two-phase compile.
|
||||
// https://github.com/flutter/flutter/issues/117248
|
||||
environment.defines[kIconTreeShakerFlag] = 'false';
|
||||
}
|
||||
|
||||
createVersionFile(environment, environment.defines);
|
||||
final Directory outputDirectory = environment.outputDir.childDirectory('assets');
|
||||
outputDirectory.createSync(recursive: true);
|
||||
@@ -458,19 +413,10 @@ class WebReleaseBundle extends Target {
|
||||
// because it would need to be the hash for the entire bundle and not just the resource
|
||||
// in question.
|
||||
if (environment.fileSystem.path.basename(inputFile.path) == 'index.html') {
|
||||
final List<Map<String, Object?>> buildDescriptions = compileTargets.map(
|
||||
(Dart2WebTarget target) => target.buildConfig
|
||||
).toList();
|
||||
final Map<String, Object?> buildConfig = <String, Object?>{
|
||||
'engineRevision': globals.flutterVersion.engineRevision,
|
||||
'builds': buildDescriptions,
|
||||
};
|
||||
final String buildConfigString = '_flutter.buildConfig = ${jsonEncode(buildConfig)};';
|
||||
final IndexHtml indexHtml = IndexHtml(inputFile.readAsStringSync());
|
||||
indexHtml.applySubstitutions(
|
||||
baseHref: environment.defines[kBaseHref] ?? '/',
|
||||
serviceWorkerVersion: Random().nextInt(4294967296).toString(),
|
||||
buildConfig: buildConfigString,
|
||||
);
|
||||
outputFile.writeAsStringSync(indexHtml.content);
|
||||
continue;
|
||||
@@ -510,9 +456,11 @@ class WebReleaseBundle extends Target {
|
||||
/// These assets can be cached until a new version of the flutter web sdk is
|
||||
/// downloaded.
|
||||
class WebBuiltInAssets extends Target {
|
||||
const WebBuiltInAssets(this.fileSystem);
|
||||
const WebBuiltInAssets(this.fileSystem, this.webRenderer, {required this.isWasm});
|
||||
|
||||
final FileSystem fileSystem;
|
||||
final WebRendererMode webRenderer;
|
||||
final bool isWasm;
|
||||
|
||||
@override
|
||||
String get name => 'web_static_assets';
|
||||
@@ -543,6 +491,7 @@ class WebBuiltInAssets extends Target {
|
||||
|
||||
@override
|
||||
List<Source> get outputs => <Source>[
|
||||
if (isWasm) const Source.pattern('{BUILD_DIR}/main.dart.js'),
|
||||
const Source.pattern('{BUILD_DIR}/flutter.js'),
|
||||
for (final File file in _canvasKitFiles)
|
||||
Source.pattern('{BUILD_DIR}/canvaskit/${_filePathRelativeToCanvasKitDirectory(file)}'),
|
||||
@@ -556,6 +505,13 @@ class WebBuiltInAssets extends Target {
|
||||
file.copySync(targetPath);
|
||||
}
|
||||
|
||||
if (isWasm) {
|
||||
final File bootstrapFile = environment.outputDir.childFile('main.dart.js');
|
||||
bootstrapFile.writeAsStringSync(
|
||||
wasm_bootstrap.generateWasmBootstrapFile(webRenderer == WebRendererMode.skwasm)
|
||||
);
|
||||
}
|
||||
|
||||
// Write the flutter.js file
|
||||
final String flutterJsOut = fileSystem.path.join(environment.outputDir.path, 'flutter.js');
|
||||
final File flutterJsFile = fileSystem.file(fileSystem.path.join(
|
||||
@@ -568,18 +524,20 @@ class WebBuiltInAssets extends Target {
|
||||
|
||||
/// Generate a service worker for a web target.
|
||||
class WebServiceWorker extends Target {
|
||||
const WebServiceWorker(this.fileSystem, this.compileConfigs);
|
||||
const WebServiceWorker(this.fileSystem, this.webRenderer, {required this.isWasm});
|
||||
|
||||
final FileSystem fileSystem;
|
||||
final List<WebCompilerConfig> compileConfigs;
|
||||
final WebRendererMode webRenderer;
|
||||
final bool isWasm;
|
||||
|
||||
@override
|
||||
String get name => 'web_service_worker';
|
||||
|
||||
@override
|
||||
List<Target> get dependencies => <Target>[
|
||||
WebReleaseBundle(compileConfigs),
|
||||
WebBuiltInAssets(fileSystem),
|
||||
if (isWasm) Dart2WasmTarget(webRenderer) else Dart2JSTarget(webRenderer),
|
||||
WebReleaseBundle(webRenderer, isWasm: isWasm),
|
||||
WebBuiltInAssets(fileSystem, webRenderer, isWasm: isWasm),
|
||||
];
|
||||
|
||||
@override
|
||||
@@ -634,10 +592,6 @@ class WebServiceWorker extends Target {
|
||||
urlToHash,
|
||||
<String>[
|
||||
'main.dart.js',
|
||||
if (compileConfigs.any((WebCompilerConfig config) => config is WasmCompilerConfig)) ...<String>[
|
||||
'main.dart.wasm',
|
||||
'main.dart.mjs',
|
||||
],
|
||||
'index.html',
|
||||
if (urlToHash.containsKey('assets/AssetManifest.bin.json'))
|
||||
'assets/AssetManifest.bin.json',
|
||||
|
||||
@@ -138,50 +138,24 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
|
||||
}
|
||||
|
||||
final List<WebCompilerConfig> compilerConfigs;
|
||||
final WebCompilerConfig compilerConfig;
|
||||
if (boolArg('wasm')) {
|
||||
if (!featureFlags.isFlutterWebWasmEnabled) {
|
||||
throwToolExit('Compiling to WebAssembly (wasm) is only available on the master channel.');
|
||||
}
|
||||
if (stringArg(FlutterOptions.kWebRendererFlag) != argParser.defaultFor(FlutterOptions.kWebRendererFlag)) {
|
||||
throwToolExit('"--${FlutterOptions.kWebRendererFlag}" cannot be combined with "--${FlutterOptions.kWebWasmFlag}"');
|
||||
}
|
||||
globals.logger.printBox(
|
||||
title: 'Experimental feature',
|
||||
'''
|
||||
WebAssembly compilation is experimental.
|
||||
$kWasmMoreInfo''',
|
||||
compilerConfig = WasmCompilerConfig(
|
||||
omitTypeChecks: boolArg('omit-type-checks'),
|
||||
wasmOpt: WasmOptLevel.values.byName(stringArg('wasm-opt')!),
|
||||
);
|
||||
|
||||
compilerConfigs = <WebCompilerConfig>[
|
||||
WasmCompilerConfig(
|
||||
omitTypeChecks: boolArg('omit-type-checks'),
|
||||
wasmOpt: WasmOptLevel.values.byName(stringArg('wasm-opt')!),
|
||||
renderer: WebRendererMode.skwasm,
|
||||
),
|
||||
JsCompilerConfig(
|
||||
csp: boolArg('csp'),
|
||||
optimizationLevel: stringArg('dart2js-optimization') ?? JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
|
||||
dumpInfo: boolArg('dump-info'),
|
||||
nativeNullAssertions: boolArg('native-null-assertions'),
|
||||
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
||||
sourceMaps: boolArg('source-maps'),
|
||||
renderer: WebRendererMode.canvaskit,
|
||||
)];
|
||||
} else {
|
||||
WebRendererMode webRenderer = WebRendererMode.auto;
|
||||
if (argParser.options.containsKey(FlutterOptions.kWebRendererFlag)) {
|
||||
webRenderer = WebRendererMode.values.byName(stringArg(FlutterOptions.kWebRendererFlag)!);
|
||||
}
|
||||
compilerConfigs = <WebCompilerConfig>[JsCompilerConfig(
|
||||
compilerConfig = JsCompilerConfig(
|
||||
csp: boolArg('csp'),
|
||||
optimizationLevel: stringArg('dart2js-optimization') ?? JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
|
||||
dumpInfo: boolArg('dump-info'),
|
||||
nativeNullAssertions: boolArg('native-null-assertions'),
|
||||
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
||||
sourceMaps: boolArg('source-maps'),
|
||||
renderer: webRenderer,
|
||||
)];
|
||||
);
|
||||
}
|
||||
|
||||
final FlutterProject flutterProject = FlutterProject.current();
|
||||
@@ -231,7 +205,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
target,
|
||||
buildInfo,
|
||||
ServiceWorkerStrategy.fromCliName(stringArg('pwa-strategy')),
|
||||
compilerConfigs: compilerConfigs,
|
||||
compilerConfig: compilerConfig,
|
||||
baseHref: baseHref,
|
||||
outputDirectoryPath: outputDirectoryPath,
|
||||
);
|
||||
|
||||
@@ -29,7 +29,6 @@ import '../runner/flutter_command.dart';
|
||||
import '../runner/flutter_command_runner.dart';
|
||||
import '../tracing.dart';
|
||||
import '../vmservice.dart';
|
||||
import '../web/compile.dart';
|
||||
import '../web/web_runner.dart';
|
||||
import 'daemon.dart';
|
||||
|
||||
@@ -242,10 +241,6 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
final Map<String, String> webHeaders = featureFlags.isWebEnabled
|
||||
? extractWebHeaders()
|
||||
: const <String, String>{};
|
||||
final String? webRendererString = stringArg('web-renderer');
|
||||
final WebRendererMode webRenderer = (webRendererString != null)
|
||||
? WebRendererMode.values.byName(webRendererString)
|
||||
: WebRendererMode.auto;
|
||||
|
||||
if (buildInfo.mode.isRelease) {
|
||||
return DebuggingOptions.disabled(
|
||||
@@ -263,7 +258,6 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
webBrowserDebugPort: webBrowserDebugPort,
|
||||
webBrowserFlags: webBrowserFlags,
|
||||
webHeaders: webHeaders,
|
||||
webRenderer: webRenderer,
|
||||
enableImpeller: enableImpeller,
|
||||
enableVulkanValidation: enableVulkanValidation,
|
||||
uninstallFirst: uninstallFirst,
|
||||
@@ -313,7 +307,6 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArg('web-enable-expression-evaluation'),
|
||||
webLaunchUrl: featureFlags.isWebEnabled ? stringArg('web-launch-url') : null,
|
||||
webHeaders: webHeaders,
|
||||
webRenderer: webRenderer,
|
||||
vmserviceOutFile: stringArg('vmservice-out-file'),
|
||||
fastStart: argParser.options.containsKey('fast-start')
|
||||
&& boolArg('fast-start')
|
||||
|
||||
@@ -22,7 +22,6 @@ import '../test/runner.dart';
|
||||
import '../test/test_time_recorder.dart';
|
||||
import '../test/test_wrapper.dart';
|
||||
import '../test/watcher.dart';
|
||||
import '../web/compile.dart';
|
||||
|
||||
/// The name of the directory where Integration Tests are placed.
|
||||
///
|
||||
@@ -358,10 +357,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
);
|
||||
}
|
||||
|
||||
final String? webRendererString = stringArg('web-renderer');
|
||||
final WebRendererMode webRenderer = (webRendererString != null)
|
||||
? WebRendererMode.values.byName(webRendererString)
|
||||
: WebRendererMode.auto;
|
||||
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(
|
||||
buildInfo,
|
||||
startPaused: startPaused,
|
||||
@@ -374,7 +369,6 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
usingCISystem: usingCISystem,
|
||||
enableImpeller: ImpellerStatus.fromBool(argResults!['enable-impeller'] as bool?),
|
||||
debugLogsDirectoryPath: debugLogsDirectoryPath,
|
||||
webRenderer: webRenderer,
|
||||
);
|
||||
|
||||
String? testAssetDirectory;
|
||||
|
||||
@@ -18,7 +18,6 @@ import 'devfs.dart';
|
||||
import 'device_port_forwarder.dart';
|
||||
import 'project.dart';
|
||||
import 'vmservice.dart';
|
||||
import 'web/compile.dart';
|
||||
|
||||
DeviceManager? get deviceManager => context.get<DeviceManager>();
|
||||
|
||||
@@ -953,7 +952,6 @@ class DebuggingOptions {
|
||||
this.webEnableExpressionEvaluation = false,
|
||||
this.webHeaders = const <String, String>{},
|
||||
this.webLaunchUrl,
|
||||
this.webRenderer = WebRendererMode.auto,
|
||||
this.vmserviceOutFile,
|
||||
this.fastStart = false,
|
||||
this.nullAssertions = false,
|
||||
@@ -983,7 +981,6 @@ class DebuggingOptions {
|
||||
this.webBrowserFlags = const <String>[],
|
||||
this.webLaunchUrl,
|
||||
this.webHeaders = const <String, String>{},
|
||||
this.webRenderer = WebRendererMode.auto,
|
||||
this.cacheSkSL = false,
|
||||
this.traceAllowlist,
|
||||
this.enableImpeller = ImpellerStatus.platformDefault,
|
||||
@@ -1063,7 +1060,6 @@ class DebuggingOptions {
|
||||
required this.webEnableExpressionEvaluation,
|
||||
required this.webHeaders,
|
||||
required this.webLaunchUrl,
|
||||
required this.webRenderer,
|
||||
required this.vmserviceOutFile,
|
||||
required this.fastStart,
|
||||
required this.nullAssertions,
|
||||
@@ -1148,9 +1144,6 @@ class DebuggingOptions {
|
||||
/// Allow developers to add custom headers to web server
|
||||
final Map<String, String> webHeaders;
|
||||
|
||||
/// Which web renderer to use for the debugging session
|
||||
final WebRendererMode webRenderer;
|
||||
|
||||
/// A file where the VM Service URL should be written after the application is started.
|
||||
final String? vmserviceOutFile;
|
||||
final bool fastStart;
|
||||
@@ -1259,7 +1252,6 @@ class DebuggingOptions {
|
||||
'webEnableExpressionEvaluation': webEnableExpressionEvaluation,
|
||||
'webLaunchUrl': webLaunchUrl,
|
||||
'webHeaders': webHeaders,
|
||||
'webRenderer': webRenderer.name,
|
||||
'vmserviceOutFile': vmserviceOutFile,
|
||||
'fastStart': fastStart,
|
||||
'nullAssertions': nullAssertions,
|
||||
@@ -1315,7 +1307,6 @@ class DebuggingOptions {
|
||||
webEnableExpressionEvaluation: json['webEnableExpressionEvaluation']! as bool,
|
||||
webHeaders: (json['webHeaders']! as Map<dynamic, dynamic>).cast<String, String>(),
|
||||
webLaunchUrl: json['webLaunchUrl'] as String?,
|
||||
webRenderer: WebRendererMode.values.byName(json['webRenderer']! as String),
|
||||
vmserviceOutFile: json['vmserviceOutFile'] as String?,
|
||||
fastStart: json['fastStart']! as bool,
|
||||
nullAssertions: json['nullAssertions']! as bool,
|
||||
|
||||
@@ -78,14 +78,12 @@ class WebDriverService extends DriverService {
|
||||
buildInfo,
|
||||
port: debuggingOptions.port,
|
||||
hostname: debuggingOptions.hostname,
|
||||
webRenderer: debuggingOptions.webRenderer,
|
||||
)
|
||||
: DebuggingOptions.enabled(
|
||||
buildInfo,
|
||||
port: debuggingOptions.port,
|
||||
hostname: debuggingOptions.hostname,
|
||||
disablePortPublication: debuggingOptions.disablePortPublication,
|
||||
webRenderer: debuggingOptions.webRenderer,
|
||||
),
|
||||
stayResident: true,
|
||||
flutterProject: FlutterProject.current(),
|
||||
|
||||
@@ -62,7 +62,6 @@ class IndexHtml {
|
||||
void applySubstitutions({
|
||||
required String baseHref,
|
||||
required String? serviceWorkerVersion,
|
||||
String? buildConfig,
|
||||
}) {
|
||||
if (_content.contains(kBaseHrefPlaceholder)) {
|
||||
_content = _content.replaceAll(kBaseHrefPlaceholder, baseHref);
|
||||
@@ -82,12 +81,6 @@ class IndexHtml {
|
||||
"navigator.serviceWorker.register('flutter_service_worker.js?v=$serviceWorkerVersion')",
|
||||
);
|
||||
}
|
||||
if (buildConfig != null) {
|
||||
_content = _content.replaceFirst(
|
||||
'{{flutter_build_config}}',
|
||||
buildConfig,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import '../build_system/targets/common.dart';
|
||||
import '../build_system/targets/dart_plugin_registrant.dart';
|
||||
import '../build_system/targets/localizations.dart';
|
||||
import '../build_system/targets/web.dart';
|
||||
import '../web/compiler_config.dart';
|
||||
import '../web/compile.dart';
|
||||
|
||||
class BuildTargetsImpl extends BuildTargets {
|
||||
const BuildTargetsImpl();
|
||||
@@ -27,6 +27,9 @@ class BuildTargetsImpl extends BuildTargets {
|
||||
Target get dartPluginRegistrantTarget => const DartPluginRegistrantTarget();
|
||||
|
||||
@override
|
||||
Target webServiceWorker(FileSystem fileSystem, List<WebCompilerConfig> compileConfigs) =>
|
||||
WebServiceWorker(fileSystem, compileConfigs);
|
||||
Target webServiceWorker(
|
||||
FileSystem fileSystem, {
|
||||
required WebRendererMode webRenderer,
|
||||
required bool isWasm,
|
||||
}) => WebServiceWorker(fileSystem, webRenderer, isWasm: isWasm);
|
||||
}
|
||||
|
||||
@@ -117,9 +117,8 @@ class WebAssetServer implements AssetReader {
|
||||
this.internetAddress,
|
||||
this._modules,
|
||||
this._digests,
|
||||
this._nullSafetyMode, {
|
||||
required this.webRenderer,
|
||||
}) : basePath = _getIndexHtml().getBaseHref();
|
||||
this._nullSafetyMode,
|
||||
) : basePath = _getIndexHtml().getBaseHref();
|
||||
|
||||
// Fallback to "application/octet-stream" on null which
|
||||
// makes no claims as to the structure of the data.
|
||||
@@ -178,7 +177,6 @@ class WebAssetServer implements AssetReader {
|
||||
ExpressionCompiler? expressionCompiler,
|
||||
Map<String, String> extraHeaders,
|
||||
NullSafetyMode nullSafetyMode, {
|
||||
required WebRendererMode webRenderer,
|
||||
bool testMode = false,
|
||||
DwdsLauncher dwdsLauncher = Dwds.start,
|
||||
}) async {
|
||||
@@ -227,7 +225,6 @@ class WebAssetServer implements AssetReader {
|
||||
modules,
|
||||
digests,
|
||||
nullSafetyMode,
|
||||
webRenderer: webRenderer,
|
||||
);
|
||||
if (testMode) {
|
||||
return server;
|
||||
@@ -507,29 +504,16 @@ class WebAssetServer implements AssetReader {
|
||||
}
|
||||
|
||||
/// Determines what rendering backed to use.
|
||||
final WebRendererMode webRenderer;
|
||||
WebRendererMode webRenderer = WebRendererMode.html;
|
||||
|
||||
shelf.Response _serveIndex() {
|
||||
|
||||
final IndexHtml indexHtml = _getIndexHtml();
|
||||
|
||||
final Map<String, dynamic> buildConfig = <String, dynamic>{
|
||||
'engineRevision': globals.flutterVersion.engineRevision,
|
||||
'builds': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'compileTarget': 'dartdevc',
|
||||
'renderer': webRenderer.name,
|
||||
'mainJsPath': 'main.dart.js',
|
||||
},
|
||||
],
|
||||
};
|
||||
final String buildConfigString = '_flutter.buildConfig = ${jsonEncode(buildConfig)};';
|
||||
|
||||
indexHtml.applySubstitutions(
|
||||
// Currently, we don't support --base-href for the "run" command.
|
||||
baseHref: '/',
|
||||
serviceWorkerVersion: null,
|
||||
buildConfig: buildConfigString,
|
||||
);
|
||||
|
||||
final Map<String, String> headers = <String, String>{
|
||||
@@ -679,7 +663,6 @@ class WebDevFS implements DevFS {
|
||||
required this.nullAssertions,
|
||||
required this.nativeNullAssertions,
|
||||
required this.nullSafetyMode,
|
||||
required this.webRenderer,
|
||||
this.testMode = false,
|
||||
}) : _port = port;
|
||||
|
||||
@@ -703,7 +686,6 @@ class WebDevFS implements DevFS {
|
||||
final NullSafetyMode nullSafetyMode;
|
||||
final String? tlsCertPath;
|
||||
final String? tlsCertKeyPath;
|
||||
final WebRendererMode webRenderer;
|
||||
|
||||
late WebAssetServer webAssetServer;
|
||||
|
||||
@@ -803,11 +785,15 @@ class WebDevFS implements DevFS {
|
||||
expressionCompiler,
|
||||
extraHeaders,
|
||||
nullSafetyMode,
|
||||
webRenderer: webRenderer,
|
||||
testMode: testMode,
|
||||
);
|
||||
|
||||
final int selectedPort = webAssetServer.selectedPort;
|
||||
if (buildInfo.dartDefines.contains('FLUTTER_WEB_AUTO_DETECT=true')) {
|
||||
webAssetServer.webRenderer = WebRendererMode.auto;
|
||||
} else if (buildInfo.dartDefines.contains('FLUTTER_WEB_USE_SKIA=true')) {
|
||||
webAssetServer.webRenderer = WebRendererMode.canvaskit;
|
||||
}
|
||||
String url = '$hostname:$selectedPort';
|
||||
if (hostname == 'any') {
|
||||
url ='localhost:$selectedPort';
|
||||
|
||||
@@ -309,7 +309,6 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
|
||||
nullAssertions: debuggingOptions.nullAssertions,
|
||||
nullSafetyMode: debuggingOptions.buildInfo.nullSafetyMode,
|
||||
nativeNullAssertions: debuggingOptions.nativeNullAssertions,
|
||||
webRenderer: debuggingOptions.webRenderer,
|
||||
);
|
||||
Uri url = await device!.devFS!.create();
|
||||
if (debuggingOptions.tlsCertKeyPath != null && debuggingOptions.tlsCertPath != null) {
|
||||
@@ -340,12 +339,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
|
||||
target,
|
||||
debuggingOptions.buildInfo,
|
||||
ServiceWorkerStrategy.none,
|
||||
compilerConfigs: <WebCompilerConfig>[
|
||||
JsCompilerConfig.run(
|
||||
nativeNullAssertions: debuggingOptions.nativeNullAssertions,
|
||||
renderer: debuggingOptions.webRenderer,
|
||||
)
|
||||
]
|
||||
compilerConfig: JsCompilerConfig.run(nativeNullAssertions: debuggingOptions.nativeNullAssertions)
|
||||
);
|
||||
}
|
||||
await device!.device!.startApp(
|
||||
@@ -424,12 +418,7 @@ Please provide a valid TCP port (an integer between 0 and 65535, inclusive).
|
||||
target,
|
||||
debuggingOptions.buildInfo,
|
||||
ServiceWorkerStrategy.none,
|
||||
compilerConfigs: <WebCompilerConfig>[
|
||||
JsCompilerConfig.run(
|
||||
nativeNullAssertions: debuggingOptions.nativeNullAssertions,
|
||||
renderer: debuggingOptions.webRenderer,
|
||||
)
|
||||
],
|
||||
compilerConfig: JsCompilerConfig.run(nativeNullAssertions: debuggingOptions.nativeNullAssertions),
|
||||
);
|
||||
} on ToolExit {
|
||||
return OperationResult(1, 'Failed to recompile application.');
|
||||
|
||||
@@ -135,7 +135,7 @@ class FlutterDevice {
|
||||
}
|
||||
|
||||
final String platformDillPath = globals.fs.path.join(
|
||||
globals.artifacts!.getHostArtifact(HostArtifact.webPlatformKernelFolder).path,
|
||||
getWebPlatformBinariesDirectory(globals.artifacts!, buildInfo.webRenderer).path,
|
||||
platformDillName,
|
||||
);
|
||||
|
||||
|
||||
@@ -1263,7 +1263,13 @@ abstract class FlutterCommand extends Command<void> {
|
||||
: null;
|
||||
|
||||
final Map<String, Object?> defineConfigJsonMap = extractDartDefineConfigJsonMap();
|
||||
final List<String> dartDefines = extractDartDefines(defineConfigJsonMap: defineConfigJsonMap);
|
||||
List<String> dartDefines = extractDartDefines(defineConfigJsonMap: defineConfigJsonMap);
|
||||
|
||||
WebRendererMode webRenderer = WebRendererMode.auto;
|
||||
if (argParser.options.containsKey(FlutterOptions.kWebRendererFlag)) {
|
||||
webRenderer = WebRendererMode.values.byName(stringArg(FlutterOptions.kWebRendererFlag)!);
|
||||
dartDefines = updateDartDefines(dartDefines, webRenderer);
|
||||
}
|
||||
|
||||
if (argParser.options.containsKey(FlutterOptions.kWebResourcesCdnFlag)) {
|
||||
final bool hasLocalWebSdk = argParser.options.containsKey('local-web-sdk') && stringArg('local-web-sdk') != null;
|
||||
@@ -1311,6 +1317,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
dartDefines: dartDefines,
|
||||
bundleSkSLPath: bundleSkSLPath,
|
||||
dartExperiments: experiments,
|
||||
webRenderer: webRenderer,
|
||||
performanceMeasurementFile: performanceMeasurementFile,
|
||||
packagesPath: packagesPath ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
|
||||
nullSafetyMode: nullSafetyMode,
|
||||
@@ -1548,6 +1555,19 @@ abstract class FlutterCommand extends Command<void> {
|
||||
return jsonEncode(propertyMap);
|
||||
}
|
||||
|
||||
/// Updates dart-defines based on [webRenderer].
|
||||
@visibleForTesting
|
||||
static List<String> updateDartDefines(List<String> dartDefines, WebRendererMode webRenderer) {
|
||||
final Set<String> dartDefinesSet = dartDefines.toSet();
|
||||
if (!dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_AUTO_DETECT='))
|
||||
&& dartDefines.any((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='))) {
|
||||
dartDefinesSet.removeWhere((String d) => d.startsWith('FLUTTER_WEB_USE_SKIA='));
|
||||
}
|
||||
dartDefinesSet.addAll(webRenderer.dartDefines);
|
||||
return dartDefinesSet.toList();
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> extractWebHeaders() {
|
||||
final Map<String, String> webHeaders = <String, String>{};
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class WebTestCompiler {
|
||||
}
|
||||
|
||||
final String platformDillPath = _fileSystem.path.join(
|
||||
_artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder).path,
|
||||
getWebPlatformBinariesDirectory(_artifacts, buildInfo.webRenderer).path,
|
||||
platformDillName
|
||||
);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import '../version.dart';
|
||||
import 'compiler_config.dart';
|
||||
import 'file_generators/flutter_service_worker_js.dart';
|
||||
import 'migrations/scrub_generated_plugin_registrant.dart';
|
||||
import 'web_constants.dart';
|
||||
|
||||
export 'compiler_config.dart';
|
||||
|
||||
@@ -66,14 +67,23 @@ class WebBuilder {
|
||||
String target,
|
||||
BuildInfo buildInfo,
|
||||
ServiceWorkerStrategy serviceWorkerStrategy, {
|
||||
required List<WebCompilerConfig> compilerConfigs,
|
||||
required WebCompilerConfig compilerConfig,
|
||||
String? baseHref,
|
||||
String? outputDirectoryPath,
|
||||
}) async {
|
||||
if (compilerConfig.isWasm) {
|
||||
globals.logger.printBox(
|
||||
title: 'Experimental feature',
|
||||
'''
|
||||
WebAssembly compilation is experimental.
|
||||
$kWasmMoreInfo''',
|
||||
);
|
||||
}
|
||||
|
||||
final bool hasWebPlugins =
|
||||
(await findPlugins(flutterProject)).any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
|
||||
final Directory outputDirectory = outputDirectoryPath == null
|
||||
? _fileSystem.directory(getWebBuildDirectory())
|
||||
? _fileSystem.directory(getWebBuildDirectory(compilerConfig.isWasm))
|
||||
: _fileSystem.directory(outputDirectoryPath);
|
||||
outputDirectory.createSync(recursive: true);
|
||||
|
||||
@@ -89,7 +99,11 @@ class WebBuilder {
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
try {
|
||||
final BuildResult result = await _buildSystem.build(
|
||||
globals.buildTargets.webServiceWorker(_fileSystem, compilerConfigs),
|
||||
globals.buildTargets.webServiceWorker(
|
||||
_fileSystem,
|
||||
webRenderer: buildInfo.webRenderer,
|
||||
isWasm: compilerConfig.isWasm,
|
||||
),
|
||||
Environment(
|
||||
projectDir: _fileSystem.currentDirectory,
|
||||
outputDir: outputDirectory,
|
||||
@@ -99,6 +113,7 @@ class WebBuilder {
|
||||
kHasWebPlugins: hasWebPlugins.toString(),
|
||||
if (baseHref != null) kBaseHref: baseHref,
|
||||
kServiceWorkerStrategy: serviceWorkerStrategy.cliName,
|
||||
...compilerConfig.toBuildSystemEnvironment(),
|
||||
...buildInfo.toBuildSystemEnvironment(),
|
||||
},
|
||||
artifacts: globals.artifacts!,
|
||||
@@ -131,7 +146,8 @@ class WebBuilder {
|
||||
}
|
||||
|
||||
final String buildSettingsString = _buildEventAnalyticsSettings(
|
||||
configs: compilerConfigs,
|
||||
config: compilerConfig,
|
||||
buildInfo: buildInfo,
|
||||
);
|
||||
|
||||
BuildEvent(
|
||||
@@ -147,15 +163,14 @@ class WebBuilder {
|
||||
));
|
||||
|
||||
final Duration elapsedDuration = sw.elapsed;
|
||||
final String variableName = compilerConfigs.length > 1 ? 'dual-compile' : 'dart2js';
|
||||
_flutterUsage.sendTiming(
|
||||
'build',
|
||||
variableName,
|
||||
compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
|
||||
elapsedDuration,
|
||||
);
|
||||
_analytics.send(Event.timing(
|
||||
workflow: 'build',
|
||||
variableName: variableName,
|
||||
variableName: compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
|
||||
elapsedMilliseconds: elapsedDuration.inMilliseconds,
|
||||
));
|
||||
}
|
||||
@@ -242,18 +257,13 @@ const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsMapArtif
|
||||
};
|
||||
|
||||
String _buildEventAnalyticsSettings({
|
||||
required List<WebCompilerConfig> configs,
|
||||
required WebCompilerConfig config,
|
||||
required BuildInfo buildInfo,
|
||||
}) {
|
||||
final Map<String, Object> values = <String, Object>{};
|
||||
final List<String> renderers = <String>[];
|
||||
final List<String> targets = <String>[];
|
||||
for (final WebCompilerConfig config in configs) {
|
||||
values.addAll(config.buildEventAnalyticsValues);
|
||||
renderers.add(config.renderer.name);
|
||||
targets.add(config.compileTarget.name);
|
||||
}
|
||||
values['web-renderer'] = renderers.join(',');
|
||||
values['web-target'] = targets.join(',');
|
||||
final Map<String, Object> values = <String, Object>{
|
||||
...config.buildEventAnalyticsValues,
|
||||
'web-renderer': buildInfo.webRenderer.cliName,
|
||||
};
|
||||
|
||||
final List<String> sortedList = values.entries
|
||||
.map((MapEntry<String, Object> e) => '${e.key}: ${e.value};')
|
||||
|
||||
@@ -3,48 +3,58 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../base/utils.dart';
|
||||
import '../convert.dart';
|
||||
import 'compile.dart';
|
||||
|
||||
enum CompileTarget {
|
||||
js,
|
||||
wasm,
|
||||
}
|
||||
abstract class WebCompilerConfig {
|
||||
const WebCompilerConfig();
|
||||
|
||||
sealed class WebCompilerConfig {
|
||||
const WebCompilerConfig({required this.renderer});
|
||||
/// Returns `true` if `this` represents configuration for the Wasm compiler.
|
||||
///
|
||||
/// Otherwise, `false`–represents the JavaScript compiler.
|
||||
bool get isWasm;
|
||||
|
||||
/// Returns which target this compiler outputs (js or wasm)
|
||||
CompileTarget get compileTarget;
|
||||
final WebRendererMode renderer;
|
||||
Map<String, String> toBuildSystemEnvironment();
|
||||
|
||||
String get buildKey;
|
||||
|
||||
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{};
|
||||
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
|
||||
'wasm-compile': isWasm,
|
||||
};
|
||||
}
|
||||
|
||||
/// Configuration for the Dart-to-Javascript compiler (dart2js).
|
||||
class JsCompilerConfig extends WebCompilerConfig {
|
||||
const JsCompilerConfig({
|
||||
this.csp = false,
|
||||
this.dumpInfo = false,
|
||||
this.nativeNullAssertions = false,
|
||||
this.optimizationLevel = kDart2jsDefaultOptimizationLevel,
|
||||
this.noFrequencyBasedMinification = false,
|
||||
this.sourceMaps = true,
|
||||
super.renderer = WebRendererMode.auto,
|
||||
required this.csp,
|
||||
required this.dumpInfo,
|
||||
required this.nativeNullAssertions,
|
||||
required this.optimizationLevel,
|
||||
required this.noFrequencyBasedMinification,
|
||||
required this.sourceMaps,
|
||||
});
|
||||
|
||||
/// Instantiates [JsCompilerConfig] suitable for the `flutter run` command.
|
||||
const JsCompilerConfig.run({
|
||||
required bool nativeNullAssertions,
|
||||
required WebRendererMode renderer,
|
||||
}) : this(
|
||||
const JsCompilerConfig.run({required bool nativeNullAssertions})
|
||||
: this(
|
||||
csp: false,
|
||||
dumpInfo: false,
|
||||
nativeNullAssertions: nativeNullAssertions,
|
||||
noFrequencyBasedMinification: false,
|
||||
optimizationLevel: kDart2jsDefaultOptimizationLevel,
|
||||
renderer: renderer,
|
||||
sourceMaps: true,
|
||||
);
|
||||
|
||||
/// Creates a new [JsCompilerConfig] from build system environment values.
|
||||
///
|
||||
/// Should correspond exactly with [toBuildSystemEnvironment].
|
||||
factory JsCompilerConfig.fromBuildSystemEnvironment(
|
||||
Map<String, String> defines) =>
|
||||
JsCompilerConfig(
|
||||
csp: defines[kCspMode] == 'true',
|
||||
dumpInfo: defines[kDart2jsDumpInfo] == 'true',
|
||||
nativeNullAssertions: defines[kNativeNullAssertions] == 'true',
|
||||
optimizationLevel: defines[kDart2jsOptimization] ?? kDart2jsDefaultOptimizationLevel,
|
||||
noFrequencyBasedMinification: defines[kDart2jsNoFrequencyBasedMinification] == 'true',
|
||||
sourceMaps: defines[kSourceMapsEnabled] == 'true',
|
||||
);
|
||||
|
||||
/// The default optimization level for dart2js.
|
||||
///
|
||||
/// Maps to [kDart2jsOptimization].
|
||||
@@ -92,7 +102,17 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||
final bool sourceMaps;
|
||||
|
||||
@override
|
||||
CompileTarget get compileTarget => CompileTarget.js;
|
||||
bool get isWasm => false;
|
||||
|
||||
@override
|
||||
Map<String, String> toBuildSystemEnvironment() => <String, String>{
|
||||
kCspMode: csp.toString(),
|
||||
kDart2jsDumpInfo: dumpInfo.toString(),
|
||||
kNativeNullAssertions: nativeNullAssertions.toString(),
|
||||
kDart2jsNoFrequencyBasedMinification: noFrequencyBasedMinification.toString(),
|
||||
kDart2jsOptimization: optimizationLevel,
|
||||
kSourceMapsEnabled: sourceMaps.toString(),
|
||||
};
|
||||
|
||||
/// Arguments to use in both phases: full JS compile and CFE-only.
|
||||
List<String> toSharedCommandOptions() => <String>[
|
||||
@@ -110,29 +130,25 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||
if (noFrequencyBasedMinification) '--no-frequency-based-minification',
|
||||
if (csp) '--csp',
|
||||
];
|
||||
|
||||
@override
|
||||
String get buildKey {
|
||||
final Map<String, dynamic> settings = <String, dynamic>{
|
||||
'csp': csp,
|
||||
'dumpInfo': dumpInfo,
|
||||
'nativeNullAssertions': nativeNullAssertions,
|
||||
'noFrequencyBasedMinification': noFrequencyBasedMinification,
|
||||
'optimizationLevel': optimizationLevel,
|
||||
'sourceMaps': sourceMaps,
|
||||
};
|
||||
return jsonEncode(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for the Wasm compiler.
|
||||
class WasmCompilerConfig extends WebCompilerConfig {
|
||||
const WasmCompilerConfig({
|
||||
this.omitTypeChecks = false,
|
||||
this.wasmOpt = WasmOptLevel.defaultValue,
|
||||
super.renderer = WebRendererMode.auto,
|
||||
required this.omitTypeChecks,
|
||||
required this.wasmOpt,
|
||||
});
|
||||
|
||||
/// Creates a new [WasmCompilerConfig] from build system environment values.
|
||||
///
|
||||
/// Should correspond exactly with [toBuildSystemEnvironment].
|
||||
factory WasmCompilerConfig.fromBuildSystemEnvironment(
|
||||
Map<String, String> defines) =>
|
||||
WasmCompilerConfig(
|
||||
omitTypeChecks: defines[kOmitTypeChecks] == 'true',
|
||||
wasmOpt: WasmOptLevel.values.byName(defines[kRunWasmOpt]!),
|
||||
);
|
||||
|
||||
/// Build environment for [omitTypeChecks].
|
||||
static const String kOmitTypeChecks = 'WasmOmitTypeChecks';
|
||||
|
||||
@@ -146,31 +162,25 @@ class WasmCompilerConfig extends WebCompilerConfig {
|
||||
final WasmOptLevel wasmOpt;
|
||||
|
||||
@override
|
||||
CompileTarget get compileTarget => CompileTarget.wasm;
|
||||
bool get isWasm => true;
|
||||
|
||||
bool get runWasmOpt =>
|
||||
wasmOpt == WasmOptLevel.full || wasmOpt == WasmOptLevel.debug;
|
||||
bool get runWasmOpt => wasmOpt == WasmOptLevel.full || wasmOpt == WasmOptLevel.debug;
|
||||
|
||||
@override
|
||||
Map<String, String> toBuildSystemEnvironment() => <String, String>{
|
||||
kOmitTypeChecks: omitTypeChecks.toString(),
|
||||
kRunWasmOpt: wasmOpt.name,
|
||||
};
|
||||
|
||||
List<String> toCommandOptions() => <String>[
|
||||
if (omitTypeChecks) '--omit-type-checks',
|
||||
];
|
||||
if (omitTypeChecks) '--omit-type-checks',
|
||||
];
|
||||
|
||||
@override
|
||||
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
|
||||
...super.buildEventAnalyticsValues,
|
||||
kOmitTypeChecks: omitTypeChecks.toString(),
|
||||
kRunWasmOpt: wasmOpt.name,
|
||||
};
|
||||
|
||||
@override
|
||||
String get buildKey {
|
||||
final Map<String, dynamic> settings = <String, dynamic>{
|
||||
'omitTypeChecks': omitTypeChecks,
|
||||
'wasmOpt': wasmOpt.name,
|
||||
};
|
||||
return jsonEncode(settings);
|
||||
}
|
||||
|
||||
...super.buildEventAnalyticsValues,
|
||||
...toBuildSystemEnvironment(),
|
||||
};
|
||||
}
|
||||
|
||||
enum WasmOptLevel implements CliEnum {
|
||||
@@ -185,11 +195,8 @@ enum WasmOptLevel implements CliEnum {
|
||||
|
||||
@override
|
||||
String get helpText => switch (this) {
|
||||
WasmOptLevel.none =>
|
||||
'wasm-opt is not run. Fastest build; bigger, slower output.',
|
||||
WasmOptLevel.debug =>
|
||||
'Similar to `${WasmOptLevel.full.name}`, but member names are preserved. Debugging is easier, but size is a bit bigger.',
|
||||
WasmOptLevel.full =>
|
||||
'wasm-opt is run. Build time is slower, but output is smaller and faster.',
|
||||
};
|
||||
WasmOptLevel.none => 'wasm-opt is not run. Fastest build; bigger, slower output.',
|
||||
WasmOptLevel.debug => 'Similar to `${WasmOptLevel.full.name}`, but member names are preserved. Debugging is easier, but size is a bit bigger.',
|
||||
WasmOptLevel.full => 'wasm-opt is run. Build time is slower, but output is smaller and faster.',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user