From 05d4db7a8542babb3593afb74c2bfeb02b382bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 1 Aug 2024 10:37:53 +0200 Subject: [PATCH] [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 https://github.com/WebAssembly/binaryen/pull/6794 and https://github.com/WebAssembly/binaryen/pull/6795. --- pkg/dartdev/lib/src/commands/compile.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/dartdev/lib/src/commands/compile.dart b/pkg/dartdev/lib/src/commands/compile.dart index fca82f0dc43b..36d9e38d9894 100644 --- a/pkg/dartdev/lib/src/commands/compile.dart +++ b/pkg/dartdev/lib/src/commands/compile.dart @@ -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, @@ -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', @@ -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) {