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

flutter_tool: only enable wasm compile in master channel (#121755)

flutter_tool: only enable wasm compile in master channel
parent aa588365
...@@ -43,10 +43,19 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -43,10 +43,19 @@ class BuildWebCommand extends BuildSubCommand {
'to view and debug the original source code of a compiled and minified Dart ' 'to view and debug the original source code of a compiled and minified Dart '
'application.' 'application.'
); );
argParser.addFlag(
'wasm', if (featureFlags.isFlutterWebWasmEnabled) {
help: 'Compile to WebAssembly rather than Javascript (experimental).' argParser.addFlag(
); 'wasm',
help: 'Compile to WebAssembly rather than JavaScript (experimental).',
);
} else {
// Add the flag as hidden. Will give a helpful error message in [runCommand] below.
argParser.addFlag(
'wasm',
hide: true,
);
}
argParser.addOption('pwa-strategy', argParser.addOption('pwa-strategy',
defaultsTo: kOfflineFirst, defaultsTo: kOfflineFirst,
...@@ -108,6 +117,12 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -108,6 +117,12 @@ class BuildWebCommand extends BuildSubCommand {
if (!featureFlags.isWebEnabled) { if (!featureFlags.isWebEnabled) {
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 bool wasmRequested = boolArg('wasm')!;
if (wasmRequested && !featureFlags.isFlutterWebWasmEnabled) {
throwToolExit('Compiling to WebAssembly (wasm) is only available on the master channel.');
}
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
final String target = stringArgDeprecated('target')!; final String target = stringArgDeprecated('target')!;
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
...@@ -146,7 +161,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -146,7 +161,7 @@ class BuildWebCommand extends BuildSubCommand {
stringArgDeprecated('pwa-strategy')!, stringArgDeprecated('pwa-strategy')!,
boolArgDeprecated('source-maps'), boolArgDeprecated('source-maps'),
boolArgDeprecated('native-null-assertions'), boolArgDeprecated('native-null-assertions'),
boolArgDeprecated('wasm'), wasmRequested,
baseHref: baseHref, baseHref: baseHref,
dart2jsOptimization: stringArgDeprecated('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel, dart2jsOptimization: stringArgDeprecated('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel,
outputDirectoryPath: outputDirectoryPath, outputDirectoryPath: outputDirectoryPath,
......
...@@ -47,6 +47,9 @@ abstract class FeatureFlags { ...@@ -47,6 +47,9 @@ abstract class FeatureFlags {
/// Whether fast single widget reloads are enabled. /// Whether fast single widget reloads are enabled.
bool get isSingleWidgetReloadEnabled => false; bool get isSingleWidgetReloadEnabled => false;
/// Whether WebAssembly compilation for Flutter Web is enabled.
bool get isFlutterWebWasmEnabled => false;
/// Whether a particular feature is enabled for the current channel. /// Whether a particular feature is enabled for the current channel.
/// ///
/// Prefer using one of the specific getters above instead of this API. /// Prefer using one of the specific getters above instead of this API.
...@@ -64,8 +67,14 @@ const List<Feature> allFeatures = <Feature>[ ...@@ -64,8 +67,14 @@ const List<Feature> allFeatures = <Feature>[
flutterIOSFeature, flutterIOSFeature,
flutterFuchsiaFeature, flutterFuchsiaFeature,
flutterCustomDevicesFeature, flutterCustomDevicesFeature,
flutterWebWasm,
]; ];
/// All current Flutter feature flags that can be configured.
///
/// [Feature.configSetting] is not `null`.
Iterable<Feature> get allConfigurableFeatures => allFeatures.where((Feature feature) => feature.configSetting != null);
/// The [Feature] for flutter web. /// The [Feature] for flutter web.
const Feature flutterWebFeature = Feature.fullyEnabled( const Feature flutterWebFeature = Feature.fullyEnabled(
name: 'Flutter for web', name: 'Flutter for web',
...@@ -145,6 +154,16 @@ const Feature singleWidgetReload = Feature( ...@@ -145,6 +154,16 @@ const Feature singleWidgetReload = Feature(
), ),
); );
/// Enabling WebAssembly compilation from `flutter build web`
const Feature flutterWebWasm = Feature(
name: 'WebAssembly compilation from flutter build web',
environmentOverride: 'FLUTTER_WEB_WASM',
master: FeatureChannelSetting(
available: true,
enabledByDefault: true,
),
);
/// A [Feature] is a process for conditionally enabling tool features. /// A [Feature] is a process for conditionally enabling tool features.
/// ///
/// All settings are optional, and if not provided will generally default to /// All settings are optional, and if not provided will generally default to
......
...@@ -47,6 +47,9 @@ class FlutterFeatureFlags implements FeatureFlags { ...@@ -47,6 +47,9 @@ class FlutterFeatureFlags implements FeatureFlags {
@override @override
bool get isSingleWidgetReloadEnabled => isEnabled(singleWidgetReload); bool get isSingleWidgetReloadEnabled => isEnabled(singleWidgetReload);
@override
bool get isFlutterWebWasmEnabled => isEnabled(flutterWebWasm);
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
final String currentChannel = _flutterVersion.channel; final String currentChannel = _flutterVersion.channel;
......
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
testConfig = Config.test(); testConfig = Config.test();
platform = FakePlatform(environment: <String, String>{}); platform = FakePlatform(environment: <String, String>{});
for (final Feature feature in allFeatures) { for (final Feature feature in allConfigurableFeatures) {
testConfig.setValue(feature.configSetting!, false); testConfig.setValue(feature.configSetting!, false);
} }
...@@ -81,6 +81,12 @@ void main() { ...@@ -81,6 +81,12 @@ void main() {
expect(featureFlags.isWebEnabled, true); expect(featureFlags.isWebEnabled, true);
}); });
testWithoutContext('Flutter web wasm only enable on master', () {
expect(flutterWebWasm.getSettingForChannel('master').enabledByDefault, isTrue);
expect(flutterWebWasm.getSettingForChannel('beta').enabledByDefault, isFalse);
expect(flutterWebWasm.getSettingForChannel('stable').enabledByDefault, isFalse);
});
testWithoutContext('Flutter web help string', () { testWithoutContext('Flutter web help string', () {
expect(flutterWebFeature.generateHelpMessage(), expect(flutterWebFeature.generateHelpMessage(),
'Enable or disable Flutter for web. ' 'Enable or disable Flutter for web. '
......
...@@ -80,7 +80,7 @@ void main() { ...@@ -80,7 +80,7 @@ void main() {
// contains all of the experiments in features.dart // contains all of the experiments in features.dart
expect((result.stdout as String).split('\n'), containsAll(<Matcher>[ expect((result.stdout as String).split('\n'), containsAll(<Matcher>[
for (final Feature feature in allFeatures) for (final Feature feature in allConfigurableFeatures)
contains(feature.configSetting), contains(feature.configSetting),
])); ]));
}); });
......
...@@ -6,6 +6,7 @@ import 'dart:io'; ...@@ -6,6 +6,7 @@ import 'dart:io';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/features.dart';
import '../src/common.dart'; import '../src/common.dart';
import 'test_utils.dart'; import 'test_utils.dart';
...@@ -33,18 +34,24 @@ void main() { ...@@ -33,18 +34,24 @@ void main() {
}); });
test('building web with --wasm produces expected files', () async { test('building web with --wasm produces expected files', () async {
final ProcessResult result = processManager.runSync(<String>[ final ProcessResult result = processManager.runSync(
flutterBin, <String>[
'build', flutterBin,
'web', 'build',
'--wasm', 'web',
], workingDirectory: exampleAppDir.path); '--wasm',
],
workingDirectory: exampleAppDir.path,
environment: <String, String>{
flutterWebWasm.environmentOverride!: 'true'
},
);
expect(result.exitCode, 0); expect(result.exitCode, 0);
final Directory appBuildDir = fileSystem.directory(fileSystem.path.join( final Directory appBuildDir = fileSystem.directory(fileSystem.path.join(
exampleAppDir.path, exampleAppDir.path,
'build', 'build',
'web_wasm' 'web_wasm',
)); ));
for (final String filename in const <String>[ for (final String filename in const <String>[
'flutter.js', 'flutter.js',
......
...@@ -413,6 +413,7 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -413,6 +413,7 @@ class TestFeatureFlags implements FeatureFlags {
this.isIOSEnabled = true, this.isIOSEnabled = true,
this.isFuchsiaEnabled = false, this.isFuchsiaEnabled = false,
this.areCustomDevicesEnabled = false, this.areCustomDevicesEnabled = false,
this.isFlutterWebWasmEnabled = false,
}); });
@override @override
...@@ -442,6 +443,9 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -442,6 +443,9 @@ class TestFeatureFlags implements FeatureFlags {
@override @override
final bool areCustomDevicesEnabled; final bool areCustomDevicesEnabled;
@override
final bool isFlutterWebWasmEnabled;
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
switch (feature) { switch (feature) {
......
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