Skip to content

Commit

Permalink
[dart2wasm] Pass source map to wasm-opt when optimizing
Browse files Browse the repository at this point in the history
To be able to know when we are generating a source map, make `dart
compile wasm` aware of the `--no-source-maps` flag.

Note: wasm-opt currently cannot handle the mappings we generate. This
will be merged after WebAssembly/binaryen#6794
and WebAssembly/binaryen#6795.
  • Loading branch information
osa1 committed Aug 1, 2024
1 parent ae3dbcd commit 05d4db7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/dartdev/lib/src/commands/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@ class CompileWasmCommand extends CompileSubcommandCommand {
},
hide: !verbose,
)
..addFlag(
'no-source-maps',
help: 'Do not generate a source map file.',
negatable: false,
)
..addOption(
packagesOption.flag,
abbr: packagesOption.abbr,
Expand Down Expand Up @@ -814,6 +819,7 @@ class CompileWasmCommand extends CompileSubcommandCommand {
if (args.flag('print-wasm')) '--print-wasm',
if (args.flag('print-kernel')) '--print-kernel',
if (args.flag('enable-asserts')) '--enable-asserts',
if (args.flag('no-source-maps')) '--no-source-maps',
for (final define in defines) '-D$define',
if (maxPages != null) ...[
'--import-shared-memory',
Expand Down Expand Up @@ -843,14 +849,26 @@ class CompileWasmCommand extends CompileSubcommandCommand {
}

final bool strip = args.flag('strip-wasm');
final bool generateSourceMap = !args.flag('no-source-maps');

if (runWasmOpt) {
final unoptFile = '$outputFileBasename.unopt.wasm';
File(outputFile).renameSync(unoptFile);

final unoptSourceMapFile = '$outputFileBasename.unopt.wasm.map';
if (generateSourceMap) {
File('$outputFile.map').renameSync(unoptSourceMapFile);
}

final flags = [
...binaryenFlags,
if (!strip) '-g',
if (generateSourceMap) ...[
'-ism',
unoptSourceMapFile,
'-osm',
'$outputFile.map'
]
];

if (verbose) {
Expand Down

0 comments on commit 05d4db7

Please sign in to comment.