Revert Dual Web Compile changes (#143175)

Dual Web Compile has had some issues where `flutter test` is not respecting the `--web-renderer` flag for some reason. I haven't gotten entirely to the bottom of the issue, but for now we need to rever these changes while I investigate. This reverts the following PRs:

https://github.com/flutter/flutter/pull/143128
https://github.com/flutter/flutter/pull/141396

While doing this revert, I had a few merge conflicts with https://github.com/flutter/flutter/pull/142760, and I tried to resolve the merge conflicts within the spirit of that PR's change, but @chingjun I might need your input on whether the imports I have modified are okay with regards to the change you were making.
This commit is contained in:
Jackson Gardner
2024-02-08 13:45:09 -08:00
committed by GitHub
parent 8d3c7b6f6a
commit 2efeeb47bc
32 changed files with 416 additions and 796 deletions

View File

@@ -24,6 +24,7 @@ import '../version.dart';
import 'compiler_config.dart';
import 'file_generators/flutter_service_worker_js.dart';
import 'migrations/scrub_generated_plugin_registrant.dart';
import 'web_constants.dart';
export 'compiler_config.dart';
@@ -66,14 +67,23 @@ class WebBuilder {
String target,
BuildInfo buildInfo,
ServiceWorkerStrategy serviceWorkerStrategy, {
required List<WebCompilerConfig> compilerConfigs,
required WebCompilerConfig compilerConfig,
String? baseHref,
String? outputDirectoryPath,
}) async {
if (compilerConfig.isWasm) {
globals.logger.printBox(
title: 'Experimental feature',
'''
WebAssembly compilation is experimental.
$kWasmMoreInfo''',
);
}
final bool hasWebPlugins =
(await findPlugins(flutterProject)).any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
final Directory outputDirectory = outputDirectoryPath == null
? _fileSystem.directory(getWebBuildDirectory())
? _fileSystem.directory(getWebBuildDirectory(compilerConfig.isWasm))
: _fileSystem.directory(outputDirectoryPath);
outputDirectory.createSync(recursive: true);
@@ -89,7 +99,11 @@ class WebBuilder {
final Stopwatch sw = Stopwatch()..start();
try {
final BuildResult result = await _buildSystem.build(
globals.buildTargets.webServiceWorker(_fileSystem, compilerConfigs),
globals.buildTargets.webServiceWorker(
_fileSystem,
webRenderer: buildInfo.webRenderer,
isWasm: compilerConfig.isWasm,
),
Environment(
projectDir: _fileSystem.currentDirectory,
outputDir: outputDirectory,
@@ -99,6 +113,7 @@ class WebBuilder {
kHasWebPlugins: hasWebPlugins.toString(),
if (baseHref != null) kBaseHref: baseHref,
kServiceWorkerStrategy: serviceWorkerStrategy.cliName,
...compilerConfig.toBuildSystemEnvironment(),
...buildInfo.toBuildSystemEnvironment(),
},
artifacts: globals.artifacts!,
@@ -131,7 +146,8 @@ class WebBuilder {
}
final String buildSettingsString = _buildEventAnalyticsSettings(
configs: compilerConfigs,
config: compilerConfig,
buildInfo: buildInfo,
);
BuildEvent(
@@ -147,15 +163,14 @@ class WebBuilder {
));
final Duration elapsedDuration = sw.elapsed;
final String variableName = compilerConfigs.length > 1 ? 'dual-compile' : 'dart2js';
_flutterUsage.sendTiming(
'build',
variableName,
compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
elapsedDuration,
);
_analytics.send(Event.timing(
workflow: 'build',
variableName: variableName,
variableName: compilerConfig.isWasm ? 'dart2wasm' : 'dart2js',
elapsedMilliseconds: elapsedDuration.inMilliseconds,
));
}
@@ -242,18 +257,13 @@ const Map<WebRendererMode, Map<NullSafetyMode, HostArtifact>> kDartSdkJsMapArtif
};
String _buildEventAnalyticsSettings({
required List<WebCompilerConfig> configs,
required WebCompilerConfig config,
required BuildInfo buildInfo,
}) {
final Map<String, Object> values = <String, Object>{};
final List<String> renderers = <String>[];
final List<String> targets = <String>[];
for (final WebCompilerConfig config in configs) {
values.addAll(config.buildEventAnalyticsValues);
renderers.add(config.renderer.name);
targets.add(config.compileTarget.name);
}
values['web-renderer'] = renderers.join(',');
values['web-target'] = targets.join(',');
final Map<String, Object> values = <String, Object>{
...config.buildEventAnalyticsValues,
'web-renderer': buildInfo.webRenderer.cliName,
};
final List<String> sortedList = values.entries
.map((MapEntry<String, Object> e) => '${e.key}: ${e.value};')

View File

@@ -3,48 +3,58 @@
// found in the LICENSE file.
import '../base/utils.dart';
import '../convert.dart';
import 'compile.dart';
enum CompileTarget {
js,
wasm,
}
abstract class WebCompilerConfig {
const WebCompilerConfig();
sealed class WebCompilerConfig {
const WebCompilerConfig({required this.renderer});
/// Returns `true` if `this` represents configuration for the Wasm compiler.
///
/// Otherwise, `false`–represents the JavaScript compiler.
bool get isWasm;
/// Returns which target this compiler outputs (js or wasm)
CompileTarget get compileTarget;
final WebRendererMode renderer;
Map<String, String> toBuildSystemEnvironment();
String get buildKey;
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{};
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
'wasm-compile': isWasm,
};
}
/// Configuration for the Dart-to-Javascript compiler (dart2js).
class JsCompilerConfig extends WebCompilerConfig {
const JsCompilerConfig({
this.csp = false,
this.dumpInfo = false,
this.nativeNullAssertions = false,
this.optimizationLevel = kDart2jsDefaultOptimizationLevel,
this.noFrequencyBasedMinification = false,
this.sourceMaps = true,
super.renderer = WebRendererMode.auto,
required this.csp,
required this.dumpInfo,
required this.nativeNullAssertions,
required this.optimizationLevel,
required this.noFrequencyBasedMinification,
required this.sourceMaps,
});
/// Instantiates [JsCompilerConfig] suitable for the `flutter run` command.
const JsCompilerConfig.run({
required bool nativeNullAssertions,
required WebRendererMode renderer,
}) : this(
const JsCompilerConfig.run({required bool nativeNullAssertions})
: this(
csp: false,
dumpInfo: false,
nativeNullAssertions: nativeNullAssertions,
noFrequencyBasedMinification: false,
optimizationLevel: kDart2jsDefaultOptimizationLevel,
renderer: renderer,
sourceMaps: true,
);
/// Creates a new [JsCompilerConfig] from build system environment values.
///
/// Should correspond exactly with [toBuildSystemEnvironment].
factory JsCompilerConfig.fromBuildSystemEnvironment(
Map<String, String> defines) =>
JsCompilerConfig(
csp: defines[kCspMode] == 'true',
dumpInfo: defines[kDart2jsDumpInfo] == 'true',
nativeNullAssertions: defines[kNativeNullAssertions] == 'true',
optimizationLevel: defines[kDart2jsOptimization] ?? kDart2jsDefaultOptimizationLevel,
noFrequencyBasedMinification: defines[kDart2jsNoFrequencyBasedMinification] == 'true',
sourceMaps: defines[kSourceMapsEnabled] == 'true',
);
/// The default optimization level for dart2js.
///
/// Maps to [kDart2jsOptimization].
@@ -92,7 +102,17 @@ class JsCompilerConfig extends WebCompilerConfig {
final bool sourceMaps;
@override
CompileTarget get compileTarget => CompileTarget.js;
bool get isWasm => false;
@override
Map<String, String> toBuildSystemEnvironment() => <String, String>{
kCspMode: csp.toString(),
kDart2jsDumpInfo: dumpInfo.toString(),
kNativeNullAssertions: nativeNullAssertions.toString(),
kDart2jsNoFrequencyBasedMinification: noFrequencyBasedMinification.toString(),
kDart2jsOptimization: optimizationLevel,
kSourceMapsEnabled: sourceMaps.toString(),
};
/// Arguments to use in both phases: full JS compile and CFE-only.
List<String> toSharedCommandOptions() => <String>[
@@ -110,29 +130,25 @@ class JsCompilerConfig extends WebCompilerConfig {
if (noFrequencyBasedMinification) '--no-frequency-based-minification',
if (csp) '--csp',
];
@override
String get buildKey {
final Map<String, dynamic> settings = <String, dynamic>{
'csp': csp,
'dumpInfo': dumpInfo,
'nativeNullAssertions': nativeNullAssertions,
'noFrequencyBasedMinification': noFrequencyBasedMinification,
'optimizationLevel': optimizationLevel,
'sourceMaps': sourceMaps,
};
return jsonEncode(settings);
}
}
/// Configuration for the Wasm compiler.
class WasmCompilerConfig extends WebCompilerConfig {
const WasmCompilerConfig({
this.omitTypeChecks = false,
this.wasmOpt = WasmOptLevel.defaultValue,
super.renderer = WebRendererMode.auto,
required this.omitTypeChecks,
required this.wasmOpt,
});
/// 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',
wasmOpt: WasmOptLevel.values.byName(defines[kRunWasmOpt]!),
);
/// Build environment for [omitTypeChecks].
static const String kOmitTypeChecks = 'WasmOmitTypeChecks';
@@ -146,31 +162,25 @@ class WasmCompilerConfig extends WebCompilerConfig {
final WasmOptLevel wasmOpt;
@override
CompileTarget get compileTarget => CompileTarget.wasm;
bool get isWasm => true;
bool get runWasmOpt =>
wasmOpt == WasmOptLevel.full || wasmOpt == WasmOptLevel.debug;
bool get runWasmOpt => wasmOpt == WasmOptLevel.full || wasmOpt == WasmOptLevel.debug;
@override
Map<String, String> toBuildSystemEnvironment() => <String, String>{
kOmitTypeChecks: omitTypeChecks.toString(),
kRunWasmOpt: wasmOpt.name,
};
List<String> toCommandOptions() => <String>[
if (omitTypeChecks) '--omit-type-checks',
];
if (omitTypeChecks) '--omit-type-checks',
];
@override
Map<String, Object> get buildEventAnalyticsValues => <String, Object>{
...super.buildEventAnalyticsValues,
kOmitTypeChecks: omitTypeChecks.toString(),
kRunWasmOpt: wasmOpt.name,
};
@override
String get buildKey {
final Map<String, dynamic> settings = <String, dynamic>{
'omitTypeChecks': omitTypeChecks,
'wasmOpt': wasmOpt.name,
};
return jsonEncode(settings);
}
...super.buildEventAnalyticsValues,
...toBuildSystemEnvironment(),
};
}
enum WasmOptLevel implements CliEnum {
@@ -185,11 +195,8 @@ enum WasmOptLevel implements CliEnum {
@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.',
};
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.',
};
}