Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed source files in source map file #22189

Open
verhovsky opened this issue Jul 4, 2024 · 5 comments · May be fixed by #22190
Open

Embed source files in source map file #22189

verhovsky opened this issue Jul 4, 2024 · 5 comments · May be fixed by #22190

Comments

@verhovsky
Copy link

verhovsky commented Jul 4, 2024

I want to generate a source map when compiling my C code that includes all the source files in the source map file itself instead of having to serve all the source code files alongside the source map file. This can be done by adding a sourcesContent key to the source map file. Otherwise I would have to upload 93 C files to npm with my JavaScript library.

wasm-sourcemap.py includes support for doing this already with the --sources argument

parser.add_argument('-s', '--sources', action='store_true', help='read and embed source files from file system into source map')

but there's no way to pass that argument from the emcc command

emscripten/tools/building.py

Lines 1107 to 1111 in b3c2567

sourcemap_cmd = [sys.executable, '-E', path_from_root('tools/wasm-sourcemap.py'),
wasm_file,
'--dwarfdump=' + LLVM_DWARFDUMP,
'-o', map_file,
'--basepath=' + base_path]

This could be a -gsource-maps-with-contents option or -gsource-map -s EMIT_SOURCE_CONTENTS. But neither seems ideal, I honestly expected this would be the default behavior and how source map files would work. Copying C files to serve them over HTTP on your domain just for this is weird. The source map file should just provide the source...

tree-sitter/tree-sitter#3381

@verhovsky verhovsky linked a pull request Jul 5, 2024 that will close this issue
@sbc100
Copy link
Collaborator

sbc100 commented Jul 6, 2024

I think the normal way that folks deal with this issue it to use path substitution and server the sources form localhost: https://developer.chrome.com/blog/wasm-debugging-2020.

Embedding the all of the source files in the source map seems like it could lead to absolutely enourmous source maps so I'm not sure we would want to make that the default.

@dschuff @pfaffe @RReverser WDYT?

@verhovsky
Copy link
Author

I am compiling a JavaScript library for npm. I want the source map to also work for downstream users when someone develops a website using the library. Users of the library probably won't bother to copy files out of node_modules/ to serve them for their source maps and they definitely won't bother with writing paths out in Chrome settings. They'll just use the library without source maps, so the choice is really between absolutely enormous source maps or no source maps.

As a datapoint, the sourcesContent for me would be 800KB, less than the 1MB wasm file.

$ cat $(jq -r '.sources[]' tree-sitter.wasm.map) | wc -c
847334
$ wc -c tree-sitter.wasm
1055249 tree-sitter.wasm

@sbc100
Copy link
Collaborator

sbc100 commented Jul 8, 2024

(Sorry, the wasm-debugging link I sent above was for DWARF debugging. It probably not relevant to source map debugging)

@pfaffe
Copy link
Collaborator

pfaffe commented Jul 8, 2024

The request makes sense in general, but don't make it the default. As default, it could cause quite the surprise for any user who doesn't want to ship their sources.

@verhovsky
Copy link
Author

What's the point of making a source map with -gsource-map if you don't want to ship your sources?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants