Skip to content

Commit

Permalink
flutter tool: add experimental output during wasm build (#124166)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Apr 6, 2023
1 parent 667220c commit f3e8ae7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/flutter_tools/lib/src/commands/build_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../globals.dart' as globals;
import '../html_utils.dart';
import '../project.dart';
import '../runner/flutter_command.dart'
show DevelopmentArtifact, FlutterCommandResult;
show DevelopmentArtifact, FlutterCommandResult, FlutterOptions;
import '../web/compile.dart';
import 'build.dart';

Expand Down Expand Up @@ -98,14 +98,14 @@ class BuildWebCommand extends BuildSubCommand {
if (featureFlags.isFlutterWebWasmEnabled) {
argParser.addSeparator('Experimental options');
argParser.addFlag(
'wasm',
help: 'Compile to WebAssembly rather than JavaScript.',
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(
'wasm',
FlutterOptions.kWebWasmFlag,
hide: true,
);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ class BuildWebCommand extends BuildSubCommand {
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
}

final bool wasmRequested = boolArg('wasm');
final bool wasmRequested = boolArg(FlutterOptions.kWebWasmFlag);
if (wasmRequested && !featureFlags.isFlutterWebWasmEnabled) {
throwToolExit('Compiling to WebAssembly (wasm) is only available on the master channel.');
}
Expand Down
1 change: 1 addition & 0 deletions packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class FlutterOptions {
static const String kWebBrowserFlag = 'web-browser-flag';
static const String kWebRendererFlag = 'web-renderer';
static const String kWebResourcesCdnFlag = 'web-resources-cdn';
static const String kWebWasmFlag = 'wasm';
}

/// flutter command categories for usage.
Expand Down
11 changes: 11 additions & 0 deletions packages/flutter_tools/lib/src/web/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class WebBuilder {
bool noFrequencyBasedMinification = false,
String? outputDirectoryPath,
}) async {
if (isWasm) {
globals.logger.printBox(
title: 'Experimental feature',
'''
WebAssembly compilation is experimental.
See $kWasmPreviewUri for more information.''',
);
}

final bool hasWebPlugins =
(await findPlugins(flutterProject)).any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
final Directory outputDirectory = outputDirectoryPath == null
Expand Down Expand Up @@ -165,3 +174,5 @@ const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsMapArtif
NullSafetyMode.unsound: HostArtifact.webPrecompiledSdkSourcemaps,
},
};

const String kWasmPreviewUri = 'https://flutter.dev/wasm';

0 comments on commit f3e8ae7

Please sign in to comment.