Unverified Commit ecf6a663 authored by Kevin Moore's avatar Kevin Moore Committed by GitHub

Add omit-type-checks flag for wasm builds (#124341)

Add omit-type-checks flag for wasm builds
parent da767d99
......@@ -274,6 +274,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
'-D$dartDefine',
...WasmCompilerConfig.fromBuildSystemEnvironment(environment.defines).toCommandOptions(),
'--packages=.dart_tool/package_config.json',
'--dart-sdk=$dartSdkPath',
'--multi-root-scheme',
......
......@@ -97,18 +97,19 @@ class BuildWebCommand extends BuildSubCommand {
//
if (featureFlags.isFlutterWebWasmEnabled) {
argParser.addSeparator('Experimental options');
argParser.addFlag(
FlutterOptions.kWebWasmFlag,
help: 'Compile to WebAssembly rather than JavaScript.\nSee $kWasmPreviewUri for more information.',
negatable: false,
);
} else {
// Add the flag as hidden. Will give a helpful error message in [runCommand] below.
argParser.addFlag(
FlutterOptions.kWebWasmFlag,
hide: true,
);
}
argParser.addFlag(
FlutterOptions.kWebWasmFlag,
help: 'Compile to WebAssembly rather than JavaScript.\nSee $kWasmPreviewUri for more information.',
negatable: false,
hide: !featureFlags.isFlutterWebWasmEnabled,
);
argParser.addFlag(
'omit-type-checks',
help: 'Omit type checks in Wasm output.',
negatable: false,
hide: !featureFlags.isFlutterWebWasmEnabled,
);
}
final FileSystem _fileSystem;
......@@ -139,7 +140,9 @@ class BuildWebCommand extends BuildSubCommand {
if (!featureFlags.isFlutterWebWasmEnabled) {
throwToolExit('Compiling to WebAssembly (wasm) is only available on the master channel.');
}
compilerConfig = const WasmCompilerConfig();
compilerConfig = WasmCompilerConfig(
omitTypeChecks: boolArg('omit-type-checks'),
);
} else {
compilerConfig = JsCompilerConfig(
csp: boolArg('csp'),
......
......@@ -128,11 +128,34 @@ class JsCompilerConfig extends WebCompilerConfig {
/// Configuration for the Wasm compiler.
class WasmCompilerConfig extends WebCompilerConfig {
const WasmCompilerConfig();
const WasmCompilerConfig({
required this.omitTypeChecks,
});
/// 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',
);
/// Build environment for [omitTypeChecks];
static const String kOmitTypeChecks = 'WasmOmitTypeChecks';
/// If `omit-type-checks` should be passed to `dart2wasm`.
final bool omitTypeChecks;
@override
bool get isWasm => true;
@override
Map<String, String> toBuildSystemEnvironment() => const <String, String>{};
Map<String, String> toBuildSystemEnvironment() => <String, String>{
kOmitTypeChecks: omitTypeChecks.toString(),
};
List<String> toCommandOptions() => <String>[
if (omitTypeChecks) '--omit-type-checks',
];
}
......@@ -810,6 +810,41 @@ void main() {
ProcessManager: () => processManager,
}));
test('Dart2WasmTarget invokes dart2wasm with omit checks', () => testbed.run(() async {
environment.defines[kBuildMode] = 'release';
environment.defines[WasmCompilerConfig.kOmitTypeChecks] = 'true';
final File depFile = environment.buildDir.childFile('dart2wasm.d');
processManager.addCommand(FakeCommand(
command: <String>[
'bin/cache/dart-sdk/bin/dartaotruntime',
'--disable-dart-dev',
'bin/cache/dart-sdk/bin/snapshots/dart2wasm_product.snapshot',
'-Ddart.vm.product=true',
'--omit-type-checks',
'--packages=.dart_tool/package_config.json',
'--dart-sdk=bin/cache/dart-sdk',
'--multi-root-scheme',
'org-dartlang-sdk',
'--multi-root',
'bin/cache/flutter_web_sdk',
'--multi-root',
'bin/cache',
'--libraries-spec',
'bin/cache/flutter_web_sdk/libraries.json',
'--depfile=${depFile.absolute.path}',
environment.buildDir.childFile('main.dart').absolute.path,
environment.buildDir.childFile('main.dart.wasm').absolute.path,
])
);
await Dart2WasmTarget(WebRendererMode.canvaskit).build(environment);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
}));
test('Dart2WasmTarget with skwasm renderer adds extra flags', () => testbed.run(() async {
environment.defines[kBuildMode] = 'release';
final File depFile = environment.buildDir.childFile('dart2wasm.d');
......
......@@ -45,6 +45,7 @@ void main() {
'TargetFile': 'target',
'HasWebPlugins': 'false',
'ServiceWorkerStrategy': 'serviceWorkerStrategy',
'WasmOmitTypeChecks': 'false',
'BuildMode': 'debug',
'DartObfuscation': 'false',
'TrackWidgetCreation': 'true',
......@@ -68,7 +69,7 @@ void main() {
'target',
BuildInfo.debug,
'serviceWorkerStrategy',
compilerConfig: const WasmCompilerConfig(),
compilerConfig: const WasmCompilerConfig(omitTypeChecks: false),
);
expect(logger.statusText, contains('Compiling target for the Web...'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment