forked from firka/flutter
flutter_tool: only enable wasm compile in master channel (#121755)
flutter_tool: only enable wasm compile in master channel
This commit is contained in:
@@ -43,10 +43,19 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
'to view and debug the original source code of a compiled and minified Dart '
|
||||
'application.'
|
||||
);
|
||||
argParser.addFlag(
|
||||
'wasm',
|
||||
help: 'Compile to WebAssembly rather than Javascript (experimental).'
|
||||
);
|
||||
|
||||
if (featureFlags.isFlutterWebWasmEnabled) {
|
||||
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',
|
||||
defaultsTo: kOfflineFirst,
|
||||
@@ -108,6 +117,12 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
if (!featureFlags.isWebEnabled) {
|
||||
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 String target = stringArgDeprecated('target')!;
|
||||
final BuildInfo buildInfo = await getBuildInfo();
|
||||
@@ -146,7 +161,7 @@ class BuildWebCommand extends BuildSubCommand {
|
||||
stringArgDeprecated('pwa-strategy')!,
|
||||
boolArgDeprecated('source-maps'),
|
||||
boolArgDeprecated('native-null-assertions'),
|
||||
boolArgDeprecated('wasm'),
|
||||
wasmRequested,
|
||||
baseHref: baseHref,
|
||||
dart2jsOptimization: stringArgDeprecated('dart2js-optimization') ?? kDart2jsDefaultOptimizationLevel,
|
||||
outputDirectoryPath: outputDirectoryPath,
|
||||
|
||||
@@ -47,6 +47,9 @@ abstract class FeatureFlags {
|
||||
/// Whether fast single widget reloads are enabled.
|
||||
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.
|
||||
///
|
||||
/// Prefer using one of the specific getters above instead of this API.
|
||||
@@ -64,8 +67,14 @@ const List<Feature> allFeatures = <Feature>[
|
||||
flutterIOSFeature,
|
||||
flutterFuchsiaFeature,
|
||||
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.
|
||||
const Feature flutterWebFeature = Feature.fullyEnabled(
|
||||
name: 'Flutter for web',
|
||||
@@ -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.
|
||||
///
|
||||
/// All settings are optional, and if not provided will generally default to
|
||||
|
||||
@@ -47,6 +47,9 @@ class FlutterFeatureFlags implements FeatureFlags {
|
||||
@override
|
||||
bool get isSingleWidgetReloadEnabled => isEnabled(singleWidgetReload);
|
||||
|
||||
@override
|
||||
bool get isFlutterWebWasmEnabled => isEnabled(flutterWebWasm);
|
||||
|
||||
@override
|
||||
bool isEnabled(Feature feature) {
|
||||
final String currentChannel = _flutterVersion.channel;
|
||||
|
||||
Reference in New Issue
Block a user