Skip to content

Embed source files in source map file #22189

Closed
@verhovsky

Description

@verhovsky

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 -ginline-source-map option or -gsource-map -s INLINE_SOURCE_MAP, which would match TypeScript's --inlineSourceMap. Though I expected this to be the default behavior. Serving C files over HTTP is weird.

My use case is that I have an npm package compiled with Emscripten and my source map requires files from ../../../../../../../opt/homebrew/Cellar/emscripten/3.1.61/libexec/system/lib/ and I have no idea how I could put that path in my npm module tree-sitter/tree-sitter#3381

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions