mirror of
https://github.com/flutter/flutter
synced 2024-09-13 05:11:45 +00:00
Reverts flutter/flutter#143517 Initiated by: dnfield Reason for reverting: broke CI, see https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20web_benchmarks_skwasm/3446/overview Original PR Author: mkustermann Reviewed By: {eyebrowsoffire} This change reverts the following previous change: Original Description: * Make `flutter build web` have one option that determins the optimization level: `-O<level>` / `--optimization-level=<level>` => Defaulting to -O4 => Will apply to both dart2js and dart2wasm * Deprecate `--dart2js-optimization=O<level>` * Disentagle concept of optimization from concept of static symbols => Add a `--strip-wasm` / `--no-strip-wasm` flag that determins whether static symbols are kept in the resulting wasm file. * Remove copy&past'ed code in the tests for wasm build tests * Cleanup some artifacts code, now that we no longer use `wasm-opt` inside flutter tools
This commit is contained in:
parent
ea3d066237
commit
86ca31d005
|
@ -34,9 +34,9 @@ Future<TaskResult> runWebBenchmark(WebBenchmarkOptions benchmarkOptions) async {
|
||||||
await evalFlutter('build', options: <String>[
|
await evalFlutter('build', options: <String>[
|
||||||
'web',
|
'web',
|
||||||
if (benchmarkOptions.useWasm) ...<String>[
|
if (benchmarkOptions.useWasm) ...<String>[
|
||||||
'--O4',
|
|
||||||
'--wasm',
|
'--wasm',
|
||||||
'--no-strip-wasm',
|
'--wasm-opt=debug',
|
||||||
|
'--omit-type-checks',
|
||||||
],
|
],
|
||||||
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
|
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
|
||||||
if (!benchmarkOptions.useWasm) '--web-renderer=${benchmarkOptions.webRenderer}',
|
if (!benchmarkOptions.useWasm) '--web-renderer=${benchmarkOptions.webRenderer}',
|
||||||
|
|
|
@ -44,6 +44,8 @@ enum Artifact {
|
||||||
dart2jsSnapshot,
|
dart2jsSnapshot,
|
||||||
/// The dart snapshot of the dart2wasm compiler.
|
/// The dart snapshot of the dart2wasm compiler.
|
||||||
dart2wasmSnapshot,
|
dart2wasmSnapshot,
|
||||||
|
/// The wasm-opt binary that ships with the dart-sdk
|
||||||
|
wasmOptBinary,
|
||||||
|
|
||||||
/// The root of the Linux desktop sources.
|
/// The root of the Linux desktop sources.
|
||||||
linuxDesktopPath,
|
linuxDesktopPath,
|
||||||
|
@ -192,6 +194,8 @@ String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [ BuildMod
|
||||||
return 'dart2js.dart.snapshot';
|
return 'dart2js.dart.snapshot';
|
||||||
case Artifact.dart2wasmSnapshot:
|
case Artifact.dart2wasmSnapshot:
|
||||||
return 'dart2wasm_product.snapshot';
|
return 'dart2wasm_product.snapshot';
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
|
return 'wasm-opt$exe';
|
||||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||||
return 'frontend_server_aot.dart.snapshot';
|
return 'frontend_server_aot.dart.snapshot';
|
||||||
case Artifact.linuxDesktopPath:
|
case Artifact.linuxDesktopPath:
|
||||||
|
@ -562,6 +566,7 @@ class CachedArtifacts implements Artifacts {
|
||||||
case Artifact.engineDartAotRuntime:
|
case Artifact.engineDartAotRuntime:
|
||||||
case Artifact.dart2jsSnapshot:
|
case Artifact.dart2jsSnapshot:
|
||||||
case Artifact.dart2wasmSnapshot:
|
case Artifact.dart2wasmSnapshot:
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||||
case Artifact.constFinder:
|
case Artifact.constFinder:
|
||||||
case Artifact.flutterFramework:
|
case Artifact.flutterFramework:
|
||||||
|
@ -603,6 +608,7 @@ class CachedArtifacts implements Artifacts {
|
||||||
case Artifact.engineDartAotRuntime:
|
case Artifact.engineDartAotRuntime:
|
||||||
case Artifact.dart2jsSnapshot:
|
case Artifact.dart2jsSnapshot:
|
||||||
case Artifact.dart2wasmSnapshot:
|
case Artifact.dart2wasmSnapshot:
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||||
case Artifact.constFinder:
|
case Artifact.constFinder:
|
||||||
case Artifact.flutterMacOSFramework:
|
case Artifact.flutterMacOSFramework:
|
||||||
|
@ -662,6 +668,7 @@ class CachedArtifacts implements Artifacts {
|
||||||
case Artifact.engineDartAotRuntime:
|
case Artifact.engineDartAotRuntime:
|
||||||
case Artifact.dart2jsSnapshot:
|
case Artifact.dart2jsSnapshot:
|
||||||
case Artifact.dart2wasmSnapshot:
|
case Artifact.dart2wasmSnapshot:
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||||
case Artifact.icuData:
|
case Artifact.icuData:
|
||||||
case Artifact.isolateSnapshotData:
|
case Artifact.isolateSnapshotData:
|
||||||
|
@ -701,6 +708,11 @@ class CachedArtifacts implements Artifacts {
|
||||||
_dartSdkPath(_cache), 'bin', 'snapshots',
|
_dartSdkPath(_cache), 'bin', 'snapshots',
|
||||||
_artifactToFileName(artifact, _platform),
|
_artifactToFileName(artifact, _platform),
|
||||||
);
|
);
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
|
return _fileSystem.path.join(
|
||||||
|
_dartSdkPath(_cache), 'bin', 'utils',
|
||||||
|
_artifactToFileName(artifact, _platform),
|
||||||
|
);
|
||||||
case Artifact.flutterTester:
|
case Artifact.flutterTester:
|
||||||
case Artifact.vmSnapshotData:
|
case Artifact.vmSnapshotData:
|
||||||
case Artifact.isolateSnapshotData:
|
case Artifact.isolateSnapshotData:
|
||||||
|
@ -1027,6 +1039,8 @@ class CachedLocalEngineArtifacts implements Artifacts {
|
||||||
case Artifact.dart2wasmSnapshot:
|
case Artifact.dart2wasmSnapshot:
|
||||||
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
case Artifact.frontendServerSnapshotForEngineDartSdk:
|
||||||
return _fileSystem.path.join(_getDartSdkPath(), 'bin', 'snapshots', artifactFileName);
|
return _fileSystem.path.join(_getDartSdkPath(), 'bin', 'snapshots', artifactFileName);
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
|
return _fileSystem.path.join(_getDartSdkPath(), 'bin', 'utils', artifactFileName);
|
||||||
case Artifact.flutterToolsFileGenerators:
|
case Artifact.flutterToolsFileGenerators:
|
||||||
return _getFileGeneratorsPath();
|
return _getFileGeneratorsPath();
|
||||||
case Artifact.flutterPreviewDevice:
|
case Artifact.flutterPreviewDevice:
|
||||||
|
@ -1164,6 +1178,11 @@ class CachedLocalWebSdkArtifacts implements Artifacts {
|
||||||
_getDartSdkPath(), 'bin', 'snapshots',
|
_getDartSdkPath(), 'bin', 'snapshots',
|
||||||
_artifactToFileName(artifact, _platform, mode),
|
_artifactToFileName(artifact, _platform, mode),
|
||||||
);
|
);
|
||||||
|
case Artifact.wasmOptBinary:
|
||||||
|
return _fileSystem.path.join(
|
||||||
|
_getDartSdkPath(), 'bin', 'utils',
|
||||||
|
_artifactToFileName(artifact, _platform, mode),
|
||||||
|
);
|
||||||
case Artifact.genSnapshot:
|
case Artifact.genSnapshot:
|
||||||
case Artifact.flutterTester:
|
case Artifact.flutterTester:
|
||||||
case Artifact.flutterFramework:
|
case Artifact.flutterFramework:
|
||||||
|
|
|
@ -55,18 +55,6 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
usesWebRendererOption();
|
usesWebRendererOption();
|
||||||
usesWebResourcesCdnFlag();
|
usesWebResourcesCdnFlag();
|
||||||
|
|
||||||
//
|
|
||||||
// Common compilation options among JavaScript and Wasm
|
|
||||||
//
|
|
||||||
argParser.addOption(
|
|
||||||
'optimization-level',
|
|
||||||
abbr: 'O',
|
|
||||||
help:
|
|
||||||
'Sets the optimization level used for Dart compilation to JavaScript/Wasm.',
|
|
||||||
defaultsTo: '${WebCompilerConfig.kDefaultOptimizationLevel}',
|
|
||||||
allowed: const <String>['1', '2', '3', '4'],
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// JavaScript compilation options
|
// JavaScript compilation options
|
||||||
//
|
//
|
||||||
|
@ -84,9 +72,10 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
);
|
);
|
||||||
argParser.addOption('dart2js-optimization',
|
argParser.addOption('dart2js-optimization',
|
||||||
help: 'Sets the optimization level used for Dart compilation to JavaScript. '
|
help: 'Sets the optimization level used for Dart compilation to JavaScript. '
|
||||||
'Deprecated: Please use "-O=<level>" / "--optimization-level=<level>".',
|
'Valid values range from O1 to O4.',
|
||||||
allowed: const <String>['O1', 'O2', 'O3', 'O4'],
|
defaultsTo: JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
|
||||||
);
|
allowed: const <String>['O1', 'O2', 'O3', 'O4'],
|
||||||
|
);
|
||||||
argParser.addFlag('dump-info', negatable: false,
|
argParser.addFlag('dump-info', negatable: false,
|
||||||
help: 'Passes "--dump-info" to the Javascript compiler which generates '
|
help: 'Passes "--dump-info" to the Javascript compiler which generates '
|
||||||
'information about the generated code is a .js.info.json file.'
|
'information about the generated code is a .js.info.json file.'
|
||||||
|
@ -109,9 +98,19 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
hide: !featureFlags.isFlutterWebWasmEnabled,
|
hide: !featureFlags.isFlutterWebWasmEnabled,
|
||||||
);
|
);
|
||||||
argParser.addFlag(
|
argParser.addFlag(
|
||||||
'strip-wasm',
|
'omit-type-checks',
|
||||||
help: 'Whether to strip the resulting wasm file of static symbol names.',
|
help: 'Omit type checks in Wasm output.\n'
|
||||||
defaultsTo: true,
|
'Reduces code size and improves performance, but may affect runtime correctness. Use with care.',
|
||||||
|
negatable: false,
|
||||||
|
hide: !featureFlags.isFlutterWebWasmEnabled,
|
||||||
|
);
|
||||||
|
argParser.addOption(
|
||||||
|
'wasm-opt',
|
||||||
|
help:
|
||||||
|
'Optimize output wasm using the Binaryen (https://github.com/WebAssembly/binaryen) tool.',
|
||||||
|
defaultsTo: WasmOptLevel.defaultValue.cliName,
|
||||||
|
allowed: WasmOptLevel.values.map<String>((WasmOptLevel e) => e.cliName),
|
||||||
|
allowedHelp: CliEnum.allowedHelp(WasmOptLevel.values),
|
||||||
hide: !featureFlags.isFlutterWebWasmEnabled,
|
hide: !featureFlags.isFlutterWebWasmEnabled,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -139,13 +138,6 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
|
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
|
||||||
}
|
}
|
||||||
|
|
||||||
final int optimizationLevel = int.parse(stringArg('optimization-level')!);
|
|
||||||
|
|
||||||
final String? dart2jsOptimizationLevelValue = stringArg('dart2js-optimization');
|
|
||||||
final int jsOptimizationLevel = dart2jsOptimizationLevelValue != null
|
|
||||||
? int.parse(dart2jsOptimizationLevelValue.substring(1))
|
|
||||||
: optimizationLevel;
|
|
||||||
|
|
||||||
final List<WebCompilerConfig> compilerConfigs;
|
final List<WebCompilerConfig> compilerConfigs;
|
||||||
if (boolArg('wasm')) {
|
if (boolArg('wasm')) {
|
||||||
if (!featureFlags.isFlutterWebWasmEnabled) {
|
if (!featureFlags.isFlutterWebWasmEnabled) {
|
||||||
|
@ -163,13 +155,13 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
|
|
||||||
compilerConfigs = <WebCompilerConfig>[
|
compilerConfigs = <WebCompilerConfig>[
|
||||||
WasmCompilerConfig(
|
WasmCompilerConfig(
|
||||||
optimizationLevel: optimizationLevel,
|
omitTypeChecks: boolArg('omit-type-checks'),
|
||||||
stripWasm: boolArg('strip-wasm'),
|
wasmOpt: WasmOptLevel.values.byName(stringArg('wasm-opt')!),
|
||||||
renderer: WebRendererMode.skwasm,
|
renderer: WebRendererMode.skwasm,
|
||||||
),
|
),
|
||||||
JsCompilerConfig(
|
JsCompilerConfig(
|
||||||
csp: boolArg('csp'),
|
csp: boolArg('csp'),
|
||||||
optimizationLevel: jsOptimizationLevel,
|
optimizationLevel: stringArg('dart2js-optimization') ?? JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
|
||||||
dumpInfo: boolArg('dump-info'),
|
dumpInfo: boolArg('dump-info'),
|
||||||
nativeNullAssertions: boolArg('native-null-assertions'),
|
nativeNullAssertions: boolArg('native-null-assertions'),
|
||||||
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
||||||
|
@ -183,7 +175,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||||
}
|
}
|
||||||
compilerConfigs = <WebCompilerConfig>[JsCompilerConfig(
|
compilerConfigs = <WebCompilerConfig>[JsCompilerConfig(
|
||||||
csp: boolArg('csp'),
|
csp: boolArg('csp'),
|
||||||
optimizationLevel: jsOptimizationLevel,
|
optimizationLevel: stringArg('dart2js-optimization') ?? JsCompilerConfig.kDart2jsDefaultOptimizationLevel,
|
||||||
dumpInfo: boolArg('dump-info'),
|
dumpInfo: boolArg('dump-info'),
|
||||||
nativeNullAssertions: boolArg('native-null-assertions'),
|
nativeNullAssertions: boolArg('native-null-assertions'),
|
||||||
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
noFrequencyBasedMinification: boolArg('no-frequency-based-minification'),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import '../base/utils.dart';
|
||||||
import '../convert.dart';
|
import '../convert.dart';
|
||||||
import 'compile.dart';
|
import 'compile.dart';
|
||||||
|
|
||||||
|
@ -11,18 +12,7 @@ enum CompileTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class WebCompilerConfig {
|
sealed class WebCompilerConfig {
|
||||||
const WebCompilerConfig({required this.renderer, required this.optimizationLevel});
|
const WebCompilerConfig({required this.renderer});
|
||||||
|
|
||||||
/// The default optimization level for dart2js/dart2wasm.
|
|
||||||
static const int kDefaultOptimizationLevel = 4;
|
|
||||||
|
|
||||||
/// Build environment flag for [optimizationLevel].
|
|
||||||
static const String kOptimizationLevel = 'OptimizationLevel';
|
|
||||||
|
|
||||||
/// The compiler optimization level.
|
|
||||||
///
|
|
||||||
/// Valid values are O1 (lowest, profile default) to O4 (highest, release default).
|
|
||||||
final int optimizationLevel;
|
|
||||||
|
|
||||||
/// Returns which target this compiler outputs (js or wasm)
|
/// Returns which target this compiler outputs (js or wasm)
|
||||||
CompileTarget get compileTarget;
|
CompileTarget get compileTarget;
|
||||||
|
@ -30,14 +20,7 @@ sealed class WebCompilerConfig {
|
||||||
|
|
||||||
String get buildKey;
|
String get buildKey;
|
||||||
|
|
||||||
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
|
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{};
|
||||||
'optimizationLevel': optimizationLevel,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, dynamic> get _buildKeyMap => <String, dynamic>{
|
|
||||||
'optimizationLevel': optimizationLevel,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration for the Dart-to-Javascript compiler (dart2js).
|
/// Configuration for the Dart-to-Javascript compiler (dart2js).
|
||||||
|
@ -46,7 +29,7 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
this.csp = false,
|
this.csp = false,
|
||||||
this.dumpInfo = false,
|
this.dumpInfo = false,
|
||||||
this.nativeNullAssertions = false,
|
this.nativeNullAssertions = false,
|
||||||
super.optimizationLevel = WebCompilerConfig.kDefaultOptimizationLevel,
|
this.optimizationLevel = kDart2jsDefaultOptimizationLevel,
|
||||||
this.noFrequencyBasedMinification = false,
|
this.noFrequencyBasedMinification = false,
|
||||||
this.sourceMaps = true,
|
this.sourceMaps = true,
|
||||||
super.renderer = WebRendererMode.auto,
|
super.renderer = WebRendererMode.auto,
|
||||||
|
@ -58,10 +41,18 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
required WebRendererMode renderer,
|
required WebRendererMode renderer,
|
||||||
}) : this(
|
}) : this(
|
||||||
nativeNullAssertions: nativeNullAssertions,
|
nativeNullAssertions: nativeNullAssertions,
|
||||||
optimizationLevel: WebCompilerConfig.kDefaultOptimizationLevel ,
|
optimizationLevel: kDart2jsDefaultOptimizationLevel,
|
||||||
renderer: renderer,
|
renderer: renderer,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// The default optimization level for dart2js.
|
||||||
|
///
|
||||||
|
/// Maps to [kDart2jsOptimization].
|
||||||
|
static const String kDart2jsDefaultOptimizationLevel = 'O4';
|
||||||
|
|
||||||
|
/// Build environment flag for [optimizationLevel].
|
||||||
|
static const String kDart2jsOptimization = 'Dart2jsOptimization';
|
||||||
|
|
||||||
/// Build environment flag for [dumpInfo].
|
/// Build environment flag for [dumpInfo].
|
||||||
static const String kDart2jsDumpInfo = 'Dart2jsDumpInfo';
|
static const String kDart2jsDumpInfo = 'Dart2jsDumpInfo';
|
||||||
|
|
||||||
|
@ -91,6 +82,12 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
// TODO(kevmoo): consider renaming this to be "positive". Double negatives are confusing.
|
// TODO(kevmoo): consider renaming this to be "positive". Double negatives are confusing.
|
||||||
final bool noFrequencyBasedMinification;
|
final bool noFrequencyBasedMinification;
|
||||||
|
|
||||||
|
/// The compiler optimization level.
|
||||||
|
///
|
||||||
|
/// Valid values are O1 (lowest, profile default) to O4 (highest, release default).
|
||||||
|
// TODO(kevmoo): consider storing this as an [int] and validating it!
|
||||||
|
final String optimizationLevel;
|
||||||
|
|
||||||
/// `true` if the JavaScript compiler build should output source maps.
|
/// `true` if the JavaScript compiler build should output source maps.
|
||||||
final bool sourceMaps;
|
final bool sourceMaps;
|
||||||
|
|
||||||
|
@ -108,7 +105,7 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
/// Includes the contents of [toSharedCommandOptions].
|
/// Includes the contents of [toSharedCommandOptions].
|
||||||
List<String> toCommandOptions() => <String>[
|
List<String> toCommandOptions() => <String>[
|
||||||
...toSharedCommandOptions(),
|
...toSharedCommandOptions(),
|
||||||
'-O$optimizationLevel',
|
'-$optimizationLevel',
|
||||||
if (dumpInfo) '--dump-info',
|
if (dumpInfo) '--dump-info',
|
||||||
if (noFrequencyBasedMinification) '--no-frequency-based-minification',
|
if (noFrequencyBasedMinification) '--no-frequency-based-minification',
|
||||||
if (csp) '--csp',
|
if (csp) '--csp',
|
||||||
|
@ -117,11 +114,11 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
@override
|
@override
|
||||||
String get buildKey {
|
String get buildKey {
|
||||||
final Map<String, dynamic> settings = <String, dynamic>{
|
final Map<String, dynamic> settings = <String, dynamic>{
|
||||||
...super._buildKeyMap,
|
|
||||||
'csp': csp,
|
'csp': csp,
|
||||||
'dumpInfo': dumpInfo,
|
'dumpInfo': dumpInfo,
|
||||||
'nativeNullAssertions': nativeNullAssertions,
|
'nativeNullAssertions': nativeNullAssertions,
|
||||||
'noFrequencyBasedMinification': noFrequencyBasedMinification,
|
'noFrequencyBasedMinification': noFrequencyBasedMinification,
|
||||||
|
'optimizationLevel': optimizationLevel,
|
||||||
'sourceMaps': sourceMaps,
|
'sourceMaps': sourceMaps,
|
||||||
};
|
};
|
||||||
return jsonEncode(settings);
|
return jsonEncode(settings);
|
||||||
|
@ -131,33 +128,79 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||||
/// Configuration for the Wasm compiler.
|
/// Configuration for the Wasm compiler.
|
||||||
class WasmCompilerConfig extends WebCompilerConfig {
|
class WasmCompilerConfig extends WebCompilerConfig {
|
||||||
const WasmCompilerConfig({
|
const WasmCompilerConfig({
|
||||||
super.optimizationLevel = WebCompilerConfig.kDefaultOptimizationLevel,
|
this.omitTypeChecks = false,
|
||||||
this.stripWasm = true,
|
this.wasmOpt = WasmOptLevel.defaultValue,
|
||||||
super.renderer = WebRendererMode.auto,
|
super.renderer = WebRendererMode.auto,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Build environment for [stripWasm].
|
/// Build environment for [omitTypeChecks].
|
||||||
static const String kStripWasm = 'StripWasm';
|
static const String kOmitTypeChecks = 'WasmOmitTypeChecks';
|
||||||
|
|
||||||
/// Whether to strip the wasm file of static symbols.
|
/// Build environment for [wasmOpt].
|
||||||
final bool stripWasm;
|
static const String kRunWasmOpt = 'RunWasmOpt';
|
||||||
|
|
||||||
|
/// If `omit-type-checks` should be passed to `dart2wasm`.
|
||||||
|
final bool omitTypeChecks;
|
||||||
|
|
||||||
|
/// Run wasm-opt on the resulting module.
|
||||||
|
final WasmOptLevel wasmOpt;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
CompileTarget get compileTarget => CompileTarget.wasm;
|
CompileTarget get compileTarget => CompileTarget.wasm;
|
||||||
|
|
||||||
List<String> toCommandOptions() {
|
List<String> toCommandOptions() {
|
||||||
return <String>[
|
// -O1: Optimizes
|
||||||
'-O$optimizationLevel',
|
// -O2: Same as -O1 but also minifies (still semantics preserving)
|
||||||
'--${stripWasm? 'no-' : ''}name-section',
|
// -O3: Same as -O2 but also omits implicit type checks.
|
||||||
];
|
// -O4: Same as -O3 but also omits explicit type checks.
|
||||||
|
// (NOTE: This differs from dart2js -O4 semantics atm.)
|
||||||
|
|
||||||
|
// Ortogonal: The name section is always kept by default and we emit it only
|
||||||
|
// in [WasmOptLevel.full] mode (similar to `--strip` of static symbols in
|
||||||
|
// AOT mode).
|
||||||
|
final String level = !omitTypeChecks ? '-O2' : '-O4';
|
||||||
|
return switch (wasmOpt) {
|
||||||
|
WasmOptLevel.none => <String>['-O0'],
|
||||||
|
WasmOptLevel.debug => <String>[level, '--no-minify'],
|
||||||
|
WasmOptLevel.full => <String>[level, '--no-name-section'],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
|
||||||
|
...super.buildEventAnalyticsValues,
|
||||||
|
kOmitTypeChecks: omitTypeChecks.toString(),
|
||||||
|
kRunWasmOpt: wasmOpt.name,
|
||||||
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get buildKey {
|
String get buildKey {
|
||||||
final Map<String, dynamic> settings = <String, dynamic>{
|
final Map<String, dynamic> settings = <String, dynamic>{
|
||||||
...super._buildKeyMap,
|
'omitTypeChecks': omitTypeChecks,
|
||||||
'stripWasm': stripWasm,
|
'wasmOpt': wasmOpt.name,
|
||||||
};
|
};
|
||||||
return jsonEncode(settings);
|
return jsonEncode(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum WasmOptLevel implements CliEnum {
|
||||||
|
full,
|
||||||
|
debug,
|
||||||
|
none;
|
||||||
|
|
||||||
|
static const WasmOptLevel defaultValue = WasmOptLevel.full;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cliName => name;
|
||||||
|
|
||||||
|
@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.',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -427,6 +427,13 @@ void main() {
|
||||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
||||||
'bin', 'snapshots', 'dart2js.dart.snapshot'),
|
'bin', 'snapshots', 'dart2js.dart.snapshot'),
|
||||||
);
|
);
|
||||||
|
expect(
|
||||||
|
artifacts.getArtifactPath(
|
||||||
|
Artifact.wasmOptBinary,
|
||||||
|
platform: TargetPlatform.web_javascript),
|
||||||
|
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
||||||
|
'bin', 'utils', 'wasm-opt'),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('getEngineType', () {
|
testWithoutContext('getEngineType', () {
|
||||||
|
|
|
@ -615,6 +615,7 @@ void main() {
|
||||||
|
|
||||||
test('Dart2JSTarget calls dart2js with expected args in release with dart2js optimization override', () => testbed.run(() async {
|
test('Dart2JSTarget calls dart2js with expected args in release with dart2js optimization override', () => testbed.run(() async {
|
||||||
environment.defines[kBuildMode] = 'release';
|
environment.defines[kBuildMode] = 'release';
|
||||||
|
environment.defines[JsCompilerConfig.kDart2jsOptimization] = 'O3';
|
||||||
processManager.addCommand(FakeCommand(
|
processManager.addCommand(FakeCommand(
|
||||||
command: <String>[
|
command: <String>[
|
||||||
..._kDart2jsLinuxArgs,
|
..._kDart2jsLinuxArgs,
|
||||||
|
@ -643,7 +644,7 @@ void main() {
|
||||||
|
|
||||||
await Dart2JSTarget(
|
await Dart2JSTarget(
|
||||||
const JsCompilerConfig(
|
const JsCompilerConfig(
|
||||||
optimizationLevel: 3,
|
optimizationLevel: 'O3',
|
||||||
sourceMaps: false,
|
sourceMaps: false,
|
||||||
)
|
)
|
||||||
).build(environment);
|
).build(environment);
|
||||||
|
@ -900,61 +901,176 @@ void main() {
|
||||||
ProcessManager: () => processManager,
|
ProcessManager: () => processManager,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (final WebRendererMode renderer in <WebRendererMode>[WebRendererMode.canvaskit, WebRendererMode.skwasm]) {
|
test('Dart2WasmTarget invokes dart2wasm with dart defines', () => testbed.run(() async {
|
||||||
for (int level = 1; level <= 4; level++) {
|
environment.defines[kBuildMode] = 'profile';
|
||||||
for (final bool strip in <bool>[true, false]) {
|
environment.defines[WasmCompilerConfig.kRunWasmOpt] = WasmOptLevel.defaultValue.name;
|
||||||
for (final List<String> defines in const <List<String>>[<String>[], <String>['FOO=bar', 'BAZ=qux']]) {
|
environment.defines[kDartDefines] = encodeDartDefines(<String>['FOO=bar', 'BAZ=qux']);
|
||||||
test('Dart2WasmTarget invokes dart2wasm with renderer=$renderer, -O$level, stripping=$strip, defines=$defines', () => testbed.run(() async {
|
|
||||||
environment.defines[kBuildMode] = 'release';
|
|
||||||
environment.defines[kDartDefines] = encodeDartDefines(defines);
|
|
||||||
|
|
||||||
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||||
|
|
||||||
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
||||||
processManager.addCommand(FakeCommand(
|
processManager.addCommand(FakeCommand(
|
||||||
command: <String>[
|
command: <String>[
|
||||||
..._kDart2WasmLinuxArgs,
|
..._kDart2WasmLinuxArgs,
|
||||||
if (renderer == WebRendererMode.skwasm) ...<String>[
|
'-Ddart.vm.profile=true',
|
||||||
'--extra-compiler-option=--import-shared-memory',
|
'-DFOO=bar',
|
||||||
'--extra-compiler-option=--shared-memory-max-pages=32768',
|
'-DBAZ=qux',
|
||||||
],
|
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
||||||
'-Ddart.vm.product=true',
|
'-DFLUTTER_WEB_USE_SKIA=true',
|
||||||
...defines.map((String define) => '-D$define'),
|
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
||||||
if (renderer == WebRendererMode.skwasm) ...<String>[
|
'-O2',
|
||||||
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
'--no-name-section',
|
||||||
'-DFLUTTER_WEB_USE_SKIA=false',
|
'-o',
|
||||||
'-DFLUTTER_WEB_USE_SKWASM=true',
|
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
||||||
],
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
if (renderer == WebRendererMode.canvaskit) ...<String>[
|
],
|
||||||
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo'))
|
||||||
'-DFLUTTER_WEB_USE_SKIA=true',
|
);
|
||||||
],
|
|
||||||
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
|
||||||
'-O$level',
|
|
||||||
if (strip) '--no-name-section' else '--name-section',
|
|
||||||
'-o',
|
|
||||||
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
|
||||||
environment.buildDir.childFile('main.dart').absolute.path,
|
|
||||||
],
|
|
||||||
onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo'))
|
|
||||||
);
|
|
||||||
|
|
||||||
await Dart2WasmTarget(
|
await Dart2WasmTarget(
|
||||||
WasmCompilerConfig(
|
const WasmCompilerConfig(
|
||||||
optimizationLevel: level,
|
renderer: WebRendererMode.canvaskit
|
||||||
stripWasm: strip,
|
)
|
||||||
renderer: renderer,
|
).build(environment);
|
||||||
)
|
|
||||||
).build(environment);
|
|
||||||
|
|
||||||
expect(outputJsFile.existsSync(), isTrue);
|
expect(outputJsFile.existsSync(), isTrue);
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
ProcessManager: () => processManager,
|
ProcessManager: () => processManager,
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
}
|
test('Dart2WasmTarget invokes dart2wasm with omit checks', () => testbed.run(() async {
|
||||||
}
|
environment.defines[kBuildMode] = 'release';
|
||||||
}
|
environment.defines[WasmCompilerConfig.kRunWasmOpt] = WasmOptLevel.defaultValue.name;
|
||||||
|
environment.defines[WasmCompilerConfig.kOmitTypeChecks] = 'true';
|
||||||
|
|
||||||
|
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||||
|
|
||||||
|
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
..._kDart2WasmLinuxArgs,
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
||||||
|
'-DFLUTTER_WEB_USE_SKIA=true',
|
||||||
|
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
||||||
|
'-O4',
|
||||||
|
'--no-name-section',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
||||||
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
|
],
|
||||||
|
onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo'))
|
||||||
|
);
|
||||||
|
|
||||||
|
await Dart2WasmTarget(
|
||||||
|
const WasmCompilerConfig(
|
||||||
|
omitTypeChecks: true,
|
||||||
|
renderer: WebRendererMode.canvaskit
|
||||||
|
)
|
||||||
|
).build(environment);
|
||||||
|
|
||||||
|
expect(outputJsFile.existsSync(), isTrue);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('Dart2WasmTarget invokes dart2wasm and wasm-opt with debug info in wasmopt debug mode', () => testbed.run(() async {
|
||||||
|
environment.defines[kBuildMode] = 'release';
|
||||||
|
environment.defines[WasmCompilerConfig.kRunWasmOpt] = WasmOptLevel.debug.name;
|
||||||
|
|
||||||
|
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||||
|
|
||||||
|
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
..._kDart2WasmLinuxArgs,
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
||||||
|
'-DFLUTTER_WEB_USE_SKIA=true',
|
||||||
|
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
||||||
|
'-O2',
|
||||||
|
'--no-minify',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
||||||
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
|
], onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo')));
|
||||||
|
|
||||||
|
await Dart2WasmTarget(
|
||||||
|
const WasmCompilerConfig(
|
||||||
|
wasmOpt: WasmOptLevel.debug,
|
||||||
|
renderer: WebRendererMode.canvaskit
|
||||||
|
)
|
||||||
|
).build(environment);
|
||||||
|
|
||||||
|
expect(outputJsFile.existsSync(), isTrue);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('Dart2WasmTarget invokes dart2wasm (but not wasm-opt) with wasm-opt none option', () => testbed.run(() async {
|
||||||
|
environment.defines[kBuildMode] = 'debug';
|
||||||
|
environment.defines[WasmCompilerConfig.kRunWasmOpt] = WasmOptLevel.none.name;
|
||||||
|
|
||||||
|
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||||
|
|
||||||
|
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
..._kDart2WasmLinuxArgs,
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
||||||
|
'-DFLUTTER_WEB_USE_SKIA=true',
|
||||||
|
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
||||||
|
'-O0',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
||||||
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
|
], onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo')));
|
||||||
|
|
||||||
|
await Dart2WasmTarget(
|
||||||
|
const WasmCompilerConfig(
|
||||||
|
wasmOpt: WasmOptLevel.none,
|
||||||
|
renderer: WebRendererMode.canvaskit
|
||||||
|
)
|
||||||
|
).build(environment);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('Dart2WasmTarget with skwasm renderer adds extra flags', () => testbed.run(() async {
|
||||||
|
environment.defines[kBuildMode] = 'release';
|
||||||
|
environment.defines[WasmCompilerConfig.kRunWasmOpt] = WasmOptLevel.defaultValue.name;
|
||||||
|
final File depFile = environment.buildDir.childFile('dart2wasm.d');
|
||||||
|
|
||||||
|
final File outputJsFile = environment.buildDir.childFile('main.dart.mjs');
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
..._kDart2WasmLinuxArgs,
|
||||||
|
'--extra-compiler-option=--import-shared-memory',
|
||||||
|
'--extra-compiler-option=--shared-memory-max-pages=32768',
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-DFLUTTER_WEB_AUTO_DETECT=false',
|
||||||
|
'-DFLUTTER_WEB_USE_SKIA=false',
|
||||||
|
'-DFLUTTER_WEB_USE_SKWASM=true',
|
||||||
|
'--extra-compiler-option=--depfile=${depFile.absolute.path}',
|
||||||
|
'-O2',
|
||||||
|
'--no-name-section',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('main.dart.wasm').absolute.path,
|
||||||
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
|
],
|
||||||
|
onRun: (_) => outputJsFile..createSync()..writeAsStringSync('foo'))
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
await Dart2WasmTarget(
|
||||||
|
const WasmCompilerConfig(
|
||||||
|
renderer: WebRendererMode.skwasm,
|
||||||
|
)
|
||||||
|
).build(environment);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
}));
|
||||||
|
|
||||||
test('Generated service worker is empty with none-strategy', () => testbed.run(() {
|
test('Generated service worker is empty with none-strategy', () => testbed.run(() {
|
||||||
final String fileGeneratorsPath =
|
final String fileGeneratorsPath =
|
||||||
|
|
|
@ -74,8 +74,7 @@ void main() {
|
||||||
ServiceWorkerStrategy.offlineFirst,
|
ServiceWorkerStrategy.offlineFirst,
|
||||||
compilerConfigs: <WebCompilerConfig>[
|
compilerConfigs: <WebCompilerConfig>[
|
||||||
const WasmCompilerConfig(
|
const WasmCompilerConfig(
|
||||||
optimizationLevel: 0,
|
wasmOpt: WasmOptLevel.none,
|
||||||
stripWasm: false,
|
|
||||||
renderer: WebRendererMode.skwasm,
|
renderer: WebRendererMode.skwasm,
|
||||||
),
|
),
|
||||||
const JsCompilerConfig.run(
|
const JsCompilerConfig.run(
|
||||||
|
@ -104,8 +103,7 @@ void main() {
|
||||||
label: 'web-compile',
|
label: 'web-compile',
|
||||||
parameters: CustomDimensions(
|
parameters: CustomDimensions(
|
||||||
buildEventSettings:
|
buildEventSettings:
|
||||||
'optimizationLevel: 4; web-renderer: skwasm,canvaskit; web-target: wasm,js;',
|
'RunWasmOpt: none; WasmOmitTypeChecks: false; web-renderer: skwasm,canvaskit; web-target: wasm,js;',
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -118,7 +116,7 @@ void main() {
|
||||||
Event.flutterBuildInfo(
|
Event.flutterBuildInfo(
|
||||||
label: 'web-compile',
|
label: 'web-compile',
|
||||||
buildType: 'web',
|
buildType: 'web',
|
||||||
settings: 'optimizationLevel: 4; web-renderer: skwasm,canvaskit; web-target: wasm,js;',
|
settings: 'RunWasmOpt: none; WasmOmitTypeChecks: false; web-renderer: skwasm,canvaskit; web-target: wasm,js;',
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue