-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Sourcemap improvements #23741
base: main
Are you sure you want to change the base?
Sourcemap improvements #23741
Conversation
- 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.
…ist when present.
- 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).
This allows to provide sourcemap settings to emcc via -s options. Each setting maps to an option used in tools/wasm-sourcemap.py : - `INLINE_SOURCES` => `--sources` - `SOURCE_MAP_PREFIXES` => `--prefix` - `INLINE_SOURCES_PREFIXES` => `--load-prefix`
This covers 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
I realized while doing tests that we won't ever need to provide this option (along with `INLINE_SOURCES` for loading sources content in the sourcemap), since all sources are known by emcc and can be resolved properly, including paths with deterministic prefix.
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.
This looks awesome, thanks for working on it!
The only part that gives me some hesitation is that addition of two new settings. If possible we try to avoid adding new settings but this might be a case when they are needed.
I wonder if INLINE_SOURCES
could be replaced with -gsource-map=inline
?
I also wonder if this is really two different uses? How common do you thing the embedding of sources will be compared to the use of prefixes? What kind of use case fo you see for both of them? Could we split this PR into two for these two features perhaps?
(Also, thanks for fixing the typo, we can probably land that as its own cleanup PR right away).
Sure, I chose the -s option because it was easier to implement. I will do that tomorrow.
Yes, if we embed the sources content, we don't need to use path substitution, and conversely if we use prefixes it implies we don't have inline content.
I tried both :
The tests might covers some combinations since the options are not mutually exclusive, but yes using both doesn't make sense. |
I would prefer not honestly. Both features require the path resolver fix to work properly, which represents most of the code change (if we ignore the tests). The tests also share the same code for different options. |
Fair enough. I think we can land this as one change then, once we have finished bikeshedding the settings naming. BTW, gcc and clang already have |
I'm not sure about But I noticed we use that to replace the emscripten path with the synthetic path here : emscripten/tools/system_libs.py Lines 589 to 593 in 273f021
and, for example when SDL is required, I noticed most of the lib files that are cached won't have their path prefix replaced. If I provide mappings to emcc via |
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.
Nice!
Please document -gsource-map=inline
option in emcc --help
, which is in site/source/docs/tools_reference/emcc.rst
. May as well also mention that SOURCE_MAP_PREFIXES
may be useful, there.
Sorry I'm late to this party, I have a few questions. Mostly I'm concerned about making the source map behavior as close to or consistent with the DWARF behavior as possible, and as deterministic as possible (aside of course from the usual considerations already mentioned). I think |
I think that is what I was suggesting in #23741 (comment). i'm not sure about extending the meaning of those existing flags (which I think today are no link time, but only compile time flags). Maybe its a good idea? Maybe too magical? |
@lvlte I'm curious what you think main use case for |
The usage would be exactly the same as for the
How would users obtain the same output using Speaking about this, anyone knows why most of the cached lib files don't have a deterministic prefix ? |
But we don't currently use that flag do we? I guess I'm curious how folks have been using source maps without this, assuming its necessary? Or have source maps been broken since we switch to the using a deterministic prefix?
I think the idea would be that you would write
They should all use the prefix I think. Can you give an example of one that does not using the prefix? |
Personally I was using path substitution in Chrome, but we can't do that with Firefox for example.
Even before the switch, all sources outside the compilation dir would end up with some Regarding
The simplest would be to take this example (or any example that relies on SDL I think), from that, I get 35% of the emscripten files (all cached files except one) without the prefix. |
9fe508d
to
d2c0aae
Compare
Regarding SDL and such; maybe we should configure the ports builder to use the same flags as embuilder uses for the core libraries. |
Good call: #23777 |
Provide source map settings to emcc (resolves #23686, resolves #22189) :
-gsource-map=inline
.-sSOURCE_MAP_PREFIXES=["<old>=<new>"]
.Update documentation accordingly.
Fix source file resolver :
--load-prefix
is given/needed.--prefix
is given but doesn't match the given file./emsdk/emscripten
to obtain actual path for better source map #20779).Improve existing test for wasm-sourcemap.py :
test_wasm_sourcemap()
and do proper checks according to the combinations of options given.Add test for emcc covering the basic use cases where :