mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
[dart2wasm] Allow --minify/--no-minify to override defaults from -O<level>
* Allow --minify/--no-minify to override defaults from -O<level> * Remove the unused(!) --name-section option from pkg/dart2wasm/* => Stripping it only makes sense at the binaryen step * Make pkg/dart2wasm/tool/compile_benchmark support -g/--no-minify => Only useful for dart2wasm developers Issue https://github.com/dart-lang/sdk/issues/54675 Change-Id: I695e985897b212fc345dcfd776553a009723d3b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351121 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
ac212a05b6
commit
a46d59fe3b
5 changed files with 46 additions and 19 deletions
|
@ -25,8 +25,6 @@ final List<Option> options = [
|
|||
defaultsTo: _d.translatorOptions.importSharedMemory),
|
||||
Flag("inlining", (o, value) => o.translatorOptions.inlining = value,
|
||||
defaultsTo: _d.translatorOptions.inlining),
|
||||
Flag("name-section", (o, value) => o.translatorOptions.nameSection = value,
|
||||
defaultsTo: _d.translatorOptions.nameSection),
|
||||
Flag("minify", (o, value) => o.translatorOptions.minify = value,
|
||||
defaultsTo: _d.translatorOptions.minify),
|
||||
Flag("polymorphic-specialization",
|
||||
|
|
|
@ -33,7 +33,6 @@ class TranslatorOptions {
|
|||
bool importSharedMemory = false;
|
||||
bool inlining = true;
|
||||
bool jsCompatibility = false;
|
||||
bool nameSection = true;
|
||||
bool omitImplicitTypeChecks = false;
|
||||
bool omitExplicitTypeChecks = false;
|
||||
bool polymorphicSpecialization = false;
|
||||
|
|
|
@ -79,6 +79,11 @@ while [ $# -gt 0 ]; do
|
|||
shift
|
||||
;;
|
||||
|
||||
-g | --name-section)
|
||||
BINARYEN_FLAGS+=("-g")
|
||||
shift
|
||||
;;
|
||||
|
||||
--compiler-asserts)
|
||||
SNAPSHOT_NAME="dart2wasm_asserts"
|
||||
VM_ARGS+=("--enable-asserts")
|
||||
|
|
|
@ -555,10 +555,12 @@ class CompileWasmCommand extends CompileSubcommandCommand {
|
|||
|
||||
final List<String> optimizationLevel0Flags = _flagList('''
|
||||
--no-inlining
|
||||
--no-minify
|
||||
'''); // end of optimizationLevel0Flags
|
||||
|
||||
final List<String> optimizationLevel1Flags = _flagList('''
|
||||
--inlining
|
||||
--no-minify
|
||||
'''); // end of optimizationLevel1Flags
|
||||
|
||||
final List<String> optimizationLevel2Flags = _flagList('''
|
||||
|
@ -595,15 +597,16 @@ class CompileWasmCommand extends CompileSubcommandCommand {
|
|||
)
|
||||
..addFlag(
|
||||
'minify',
|
||||
defaultsTo: false,
|
||||
defaultsTo: null,
|
||||
negatable: true,
|
||||
help: 'Generate minified output.',
|
||||
help: 'Minify names that are needed at runtime (such as class names). '
|
||||
'Affects e.g. `<obj>.runtimeType.toString()`).',
|
||||
hide: !verbose,
|
||||
)
|
||||
..addFlag(
|
||||
'name-section',
|
||||
defaultsTo: false,
|
||||
negatable: false,
|
||||
defaultsTo: true,
|
||||
negatable: true,
|
||||
help: 'Include a name section with printable function names.',
|
||||
hide: !verbose,
|
||||
)
|
||||
|
@ -731,6 +734,36 @@ class CompileWasmCommand extends CompileSubcommandCommand {
|
|||
final optimizationLevel = int.parse(args['optimization-level']);
|
||||
final runWasmOpt = optimizationLevel >= 1;
|
||||
|
||||
void handleOverride(List<String> flags, String name, bool? value) {
|
||||
// If no override provided, default to what -O implies.D
|
||||
if (value == null) return;
|
||||
|
||||
if (value) {
|
||||
// Explicitly opt into the flag, irrespective of -O settings.
|
||||
flags.removeWhere((option) => option == '--no-$name');
|
||||
if (!flags.contains('--$name')) {
|
||||
flags.add('--$name');
|
||||
}
|
||||
} else {
|
||||
// Explicit opt out of the flag, irrespective of -O settings.
|
||||
flags.removeWhere((option) => option == '--$name');
|
||||
if (!flags.contains('--no-$name')) {
|
||||
flags.add('--no-$name');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final optimizationFlags = (switch (optimizationLevel) {
|
||||
0 => optimizationLevel0Flags,
|
||||
1 => optimizationLevel1Flags,
|
||||
2 => optimizationLevel2Flags,
|
||||
3 => optimizationLevel3Flags,
|
||||
4 => optimizationLevel4Flags,
|
||||
_ => throw 'unreachable',
|
||||
})
|
||||
.toList();
|
||||
handleOverride(optimizationFlags, 'minify', args['minify']);
|
||||
|
||||
final dart2wasmCommand = [
|
||||
sdk.dartAotRuntime,
|
||||
sdk.dart2wasmSnapshot,
|
||||
|
@ -749,17 +782,9 @@ class CompileWasmCommand extends CompileSubcommandCommand {
|
|||
],
|
||||
|
||||
// First we pass flags based on the optimization level.
|
||||
...switch (optimizationLevel) {
|
||||
0 => optimizationLevel0Flags,
|
||||
1 => optimizationLevel1Flags,
|
||||
2 => optimizationLevel2Flags,
|
||||
3 => optimizationLevel3Flags,
|
||||
4 => optimizationLevel4Flags,
|
||||
_ => throw 'unreachable',
|
||||
},
|
||||
// Then we pass flags that were opted into explicitly.
|
||||
if (args['name-section']) '--name-section',
|
||||
if (args['minify']) '--minify',
|
||||
...optimizationFlags,
|
||||
|
||||
// Then we pass any extra compiler flags through.
|
||||
...extraCompilerOptions,
|
||||
|
||||
path.absolute(sourcePath),
|
||||
|
|
|
@ -580,8 +580,8 @@ class Dart2WasmCompilerConfiguration extends CompilerConfiguration {
|
|||
CommandArtifact computeCompilationArtifact(String tempDir,
|
||||
List<String> arguments, Map<String, String> environmentOverrides) {
|
||||
var compilerArguments = [
|
||||
...arguments,
|
||||
..._configuration.dart2wasmOptions,
|
||||
...arguments,
|
||||
];
|
||||
|
||||
var inputFile = arguments.last;
|
||||
|
|
Loading…
Reference in a new issue