Don't remove toString implementations while in debug mode. (#154216)

This matches the behavior of AOT/VM compilation.
This commit is contained in:
Jackson Gardner 2024-08-28 13:19:48 -07:00 committed by GitHub
parent d147e52d6a
commit b95548e31c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 11 deletions

View File

@ -284,6 +284,36 @@ class Dart2WasmTarget extends Dart2WebTarget {
@override
final WasmCompilerConfig compilerConfig;
/// List the preconfigured build options for a given build mode.
List<String> buildModeOptions(BuildMode mode, List<String> dartDefines) =>
switch (mode) {
BuildMode.debug => <String>[
// These checks allow the CLI to override the value of this define for unit
// testing the framework.
if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile')))
'-Ddart.vm.profile=false',
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
'-Ddart.vm.product=false',
],
BuildMode.profile => <String>[
// These checks allow the CLI to override the value of this define for
// benchmarks with most timeline traces disabled.
if (!dartDefines.any((String define) => define.startsWith('dart.vm.profile')))
'-Ddart.vm.profile=true',
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
'-Ddart.vm.product=false',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
],
BuildMode.release => <String>[
'-Ddart.vm.profile=false',
'-Ddart.vm.product=true',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
],
_ => throw Exception('Unknown BuildMode: $mode')
};
@override
Future<void> build(Environment environment) async {
final String? buildModeEnvironment = environment.defines[kBuildMode];
@ -297,6 +327,7 @@ class Dart2WasmTarget extends Dart2WebTarget {
final File depFile = environment.buildDir.childFile('dart2wasm.d');
final String platformBinariesPath = artifacts.getHostArtifact(HostArtifact.webPlatformKernelFolder).path;
final String platformFilePath = environment.fileSystem.path.join(platformBinariesPath, 'dart2wasm_platform.dill');
final List<String> dartDefines = computeDartDefines(environment);
final List<String> compilationArgs = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
@ -304,18 +335,13 @@ class Dart2WasmTarget extends Dart2WebTarget {
'wasm',
'--packages=${findPackageConfigFileOrDefault(environment.projectDir).path}',
'--extra-compiler-option=--platform=$platformFilePath',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
...buildModeOptions(buildMode, dartDefines),
if (compilerConfig.renderer == WebRendererMode.skwasm) ...<String>[
'--extra-compiler-option=--import-shared-memory',
'--extra-compiler-option=--shared-memory-max-pages=32768',
],
if (buildMode == BuildMode.profile)
'-Ddart.vm.profile=true'
else if (buildMode == BuildMode.release)
'-Ddart.vm.product=true',
...decodeCommaSeparated(environment.defines, kExtraFrontEndOptions),
for (final String dartDefine in computeDartDefines(environment))
for (final String dartDefine in dartDefines)
'-D$dartDefine',
'--extra-compiler-option=--depfile=${depFile.path}',

View File

@ -35,8 +35,6 @@ const List<String> _kDart2WasmLinuxArgs = <String> [
'wasm',
'--packages=/.dart_tool/package_config.json',
'--extra-compiler-option=--platform=HostArtifact.webPlatformKernelFolder/dart2wasm_platform.dill',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
];
void main() {
@ -1034,12 +1032,16 @@ void main() {
processManager.addCommand(FakeCommand(
command: <String>[
..._kDart2WasmLinuxArgs,
'-Ddart.vm.profile=${buildMode == 'profile'}',
'-Ddart.vm.product=${buildMode == 'release'}',
if (buildMode != 'debug') ...<String>[
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
],
if (renderer == WebRendererMode.skwasm) ...<String>[
'--extra-compiler-option=--import-shared-memory',
'--extra-compiler-option=--shared-memory-max-pages=32768',
],
if (buildMode != 'debug')
'-Ddart.vm.${buildMode == 'release' ? 'product' : 'profile' }=true',
...defines.map((String define) => '-D$define'),
if (renderer == WebRendererMode.skwasm) ...<String>[
'-DFLUTTER_WEB_AUTO_DETECT=false',