Skip to content

Instantly share code, notes, and snippets.

@yurydelendik
Created June 23, 2017 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurydelendik/bd36e8d470a2bdd2238a15556083363b to your computer and use it in GitHub Desktop.
Save yurydelendik/bd36e8d470a2bdd2238a15556083363b to your computer and use it in GitHub Desktop.
Patch for emcc to enable source maps for wasm
diff --git a/emcc.py b/emcc.py
index fdbefe008..54d989c16 100755
--- a/emcc.py
+++ b/emcc.py
@@ -145,6 +145,7 @@ class EmccOptions(object):
self.exclude_files = []
self.ignore_dynamic_linking = False
self.shell_path = shared.path_from_root('src', 'shell.html')
+ self.source_map_base = None
self.js_libraries = []
self.bind = False
self.emrun = False
@@ -1771,7 +1772,7 @@ There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR P
if shared.Settings.CYBERDWARF:
execute([shared.PYTHON, shared.path_from_root('tools', 'emdebug_cd_merger.py'), target + '.cd', target+'.symbols'])
- if options.debug_level >= 4:
+ if options.debug_level >= 4 and not shared.Settings.BINARYEN:
emit_source_maps(target, optimizer.js_transform_tempfiles)
# track files that will need native eols
@@ -1956,6 +1957,11 @@ def parse_args(newargs):
options.shell_path = newargs[i+1]
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i].startswith('--source-map-base'):
+ check_bad_eq(newargs[i])
+ options.source_map_base = newargs[i+1]
+ newargs[i] = ''
+ newargs[i+1] = ''
elif newargs[i].startswith('--js-library'):
check_bad_eq(newargs[i])
options.js_libraries.append(newargs[i+1])
@@ -2243,6 +2249,9 @@ def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
# emit text (at least until wasm gains support for debug info in binaries)
target_binary = options.debug_level < 3
if target_binary:
+ cmd += ['--source-map=' + wasm_binary_target + '.map']
+ if options.source_map_base:
+ cmd += ['--source-map-url=' + options.source_map_base + wasm_binary_target + '.map']
cmd += ['-o', wasm_binary_target]
else:
cmd += ['-o', wasm_text_target, '-S']
@@ -2254,6 +2263,9 @@ def do_binaryen(final, target, asm_target, options, memfile, wasm_binary_target,
if not target_binary:
cmd = [os.path.join(binaryen_bin, 'wasm-as'), wasm_text_target, '-o', wasm_binary_target]
if options.debug_level >= 2 or options.profiling_funcs:
+ cmd += ['--source-map=' + wasm_binary_target + '.map']
+ if options.source_map_base:
+ cmd += ['--source-map-url=' + options.source_map_base + wasm_binary_target + '.map']
cmd += ['-g']
logging.debug('wasm-as (text => binary): ' + ' '.join(cmd))
subprocess.check_call(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment