-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Sourcemap improvements #23741
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
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? |
I think maybe we should a ChangeLog entry for this? |
Head branch was pushed to by a user without write access
Sorry, can you resolve conflict and merge/rebase main one more time? |
No problem, it should be ok now :) |
Oops, I realize now that version 4.0.5 was already released.. I'm gonna update the changelog accordingly. Sorry you will need to re-enable auto-merge again. |
Head branch was pushed to by a user without write access
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.
Looks like this caused a failure on the windows emscripten-releases builder: https://ci.chromium.org/ui/p/emscripten-releases/builders/try/win/b8720422682063060497/overview
|
Ok I will look into it tomorrow. |
Probably just some kind of windows pathname issue. |
This test was recently add in emscripten-core#23741 but currently fails on windows.
This test was recently add in #23741 but currently fails on windows.
Normalize prefixes instead of expecting windows users to do it. See #23741 (comment) The tests now pass on windows.
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 :