Skip to content

Commit 05d4db7

Browse files
committed
[dart2wasm] Pass source map to wasm-opt when optimizing
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.
1 parent ae3dbcd commit 05d4db7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/dartdev/lib/src/commands/compile.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ class CompileWasmCommand extends CompileSubcommandCommand {
707707
},
708708
hide: !verbose,
709709
)
710+
..addFlag(
711+
'no-source-maps',
712+
help: 'Do not generate a source map file.',
713+
negatable: false,
714+
)
710715
..addOption(
711716
packagesOption.flag,
712717
abbr: packagesOption.abbr,
@@ -814,6 +819,7 @@ class CompileWasmCommand extends CompileSubcommandCommand {
814819
if (args.flag('print-wasm')) '--print-wasm',
815820
if (args.flag('print-kernel')) '--print-kernel',
816821
if (args.flag('enable-asserts')) '--enable-asserts',
822+
if (args.flag('no-source-maps')) '--no-source-maps',
817823
for (final define in defines) '-D$define',
818824
if (maxPages != null) ...[
819825
'--import-shared-memory',
@@ -843,14 +849,26 @@ class CompileWasmCommand extends CompileSubcommandCommand {
843849
}
844850

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

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

858+
final unoptSourceMapFile = '$outputFileBasename.unopt.wasm.map';
859+
if (generateSourceMap) {
860+
File('$outputFile.map').renameSync(unoptSourceMapFile);
861+
}
862+
851863
final flags = [
852864
...binaryenFlags,
853865
if (!strip) '-g',
866+
if (generateSourceMap) ...[
867+
'-ism',
868+
unoptSourceMapFile,
869+
'-osm',
870+
'$outputFile.map'
871+
]
854872
];
855873

856874
if (verbose) {

0 commit comments

Comments
 (0)