-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Resolve synthetic compilation dir /emsdk/emscripten
to obtain actual path for better source map
#20779
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
base: main
Are you sure you want to change the base?
Conversation
Seems like a good idea. I wonder if we can write a test for this, or modify an existing source map test to ensure this is working. |
tools/wasm-sourcemap.py
Outdated
@@ -230,6 +230,9 @@ def read_dwarf_entries(wasm, options): | |||
for file in re.finditer(r"file_names\[\s*(\d+)\]:\s+name: \"([^\"]*)\"\s+dir_index: (\d+)", line_chunk): | |||
dir = include_directories[file.group(3)] | |||
file_path = (dir + '/' if file.group(2)[0] != '/' else '') + file.group(2) | |||
if file_path.startswith('/emsdk/emscripten/'): | |||
sub_dir = os.path.relpath(file_path, '/emsdk/emscripten') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can factor out this constant which is duplicated here and also shared with system_libs.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Will address reviews and reopen after #20776 merged. |
…l path for better source map
c26df4a
to
0910f74
Compare
Hi @sbc100, I added a test for this change. Could you please take another look? Thanks! |
0910f74
to
1fac270
Compare
self.run_process(wasm_map_cmd, stdout=PIPE, stderr=PIPE) | ||
output = read_file('a.out.wasm.map') | ||
# has an actual path to the source file of system library, not a dummy path (/emsdk/emscripten/**) | ||
self.assertIn('"system/lib/compiler-rt/stack_ops.S"', output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use assertContains here instead?
'-o', 'a.out.wasm.map', | ||
test_file('other/wasm_sourcemap_resolve_dummy_comp_dir/foo.wasm'), | ||
'--basepath=' + path_from_root()] | ||
self.run_process(wasm_map_cmd, stdout=PIPE, stderr=PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe don't capture stdout and stderr here since if this command ever fails it could be good to show the output.
'--dwarfdump-output', | ||
test_file('other/wasm_sourcemap_resolve_dummy_comp_dir/foo.wasm.dump'), | ||
'-o', 'a.out.wasm.map', | ||
test_file('other/wasm_sourcemap_resolve_dummy_comp_dir/foo.wasm'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use use just compile test/hello_world.c
here rather then checking in the foo.wasm
binary?
Also it looks like you accidentally added the .dump
file to git too.
I noticed a couple of things here: One is that the paths used in DWARF (which is used both to generate the source maps, and also with the Chrome C++ debugger) don't match the paths in the source maps. The other is that while the DWARF stays deterministic, the source map does not. Is this what we want? Since the source map is just as much a part of the build output as the wasm file; so with this patch it's not possible to get a deterministic source map even if a user wanted to. I also took a look at the current DWARF-generation behavior of emcc and noticed that when we build with embuilder we use the deterministic output, but when emcc builds system libs on demand, it doesn't. This doesn't have anything to do with your proposed change here of course, but it seems odd since if a user uses a library version that's not prebuilt with emsdk, then I don't know if there's a way to even get deterministic output in that case. And then I noticed that when I used the deterministic embuilder build, all of the fields in the source map actually seem to be using relative paths (e.g. 'system/lib/compiler-rt') and I didn't see any appearance of the dummy path in the source map at all. So I'm wondering whether I'm compiling somehow differently than you are, and I'd like to understand your use case better before we make a fix. |
Provide source map settings to emcc (resolves #23686, resolves #22189) : - for embedding the sources content in the source map : `-gsource-map=inline`. - for applying path prefix substitution : `-sSOURCE_MAP_PREFIXES=["<old>=<new>"]`. Update documentation accordingly. Fix source file resolver : - Always fall back to the given filepath if prefix not provided or doesn't match. - Fix source content loading when no `--load-prefix` is given/needed. - Fix relative path in "sources" field when`--prefix` is given but doesn't match the given file. - Cache filepaths with no/unmatched prefix as well. - Resolve deterministic prefix when loading source content (related: #20779). - Don't emit relative paths for sources with a deterministic prefix. Improve existing test for wasm-sourcemap.py : - Parameterize `test_wasm_sourcemap()` and do proper checks according to the combinations of options given. - Fix regex for checking the "mappings" field (was checking only the first character). Add test for emcc covering the basic use cases where : - no option is given (users do path substitution as needed via their client or server configuration). - different prefixes are provided for source files and emscripten dependencies. - source content is embedded in the sourcemap.
Provide source map settings to emcc (resolves emscripten-core#23686, resolves emscripten-core#22189) : - for embedding the sources content in the source map : `-gsource-map=inline`. - for applying path prefix substitution : `-sSOURCE_MAP_PREFIXES=["<old>=<new>"]`. Update documentation accordingly. Fix source file resolver : - Always fall back to the given filepath if prefix not provided or doesn't match. - Fix source content loading when no `--load-prefix` is given/needed. - Fix relative path in "sources" field when`--prefix` is given but doesn't match the given file. - Cache filepaths with no/unmatched prefix as well. - Resolve deterministic prefix when loading source content (related: emscripten-core#20779). - Don't emit relative paths for sources with a deterministic prefix. Improve existing test for wasm-sourcemap.py : - Parameterize `test_wasm_sourcemap()` and do proper checks according to the combinations of options given. - Fix regex for checking the "mappings" field (was checking only the first character). Add test for emcc covering the basic use cases where : - no option is given (users do path substitution as needed via their client or server configuration). - different prefixes are provided for source files and emscripten dependencies. - source content is embedded in the sourcemap.
We are using a synthetic path
/emsdk/emscripten
as a compilation directory for building prebuilt system libraries in order to achieve a deterministic build, not being affected by the directory structure of buildbot.However, those dummy paths still remain in the final source map, making it unable to locate system source files while debugging.
This change replaces
/emsdk/emscripten
with the actual path to be able to locate system source files.