emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.44k stars 3.25k forks source link

Sourcemap absolute path issue #21900

Open dwz8 opened 2 months ago

dwz8 commented 2 months ago

Please include the following in your bug report:

Version of emscripten/emsdk: Please include the output emcc -v here emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.32 (eab98adf462c39f3c31d348331c4830bcaa36949) clang version 17.0.0 (https://github.com/llvm/llvm-project df82394e7a2d06506718cafa347bf7827c79fc4f) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: C:\Users\diete\emsdk\upstream\bin

emscripten is installed on drive C:\ the project is installed on drive D:\ sourcemap entries point correctly to relative paths on D:\ sourcemap entries use an unusable absolute path for emscripten related files

Test project including a simple sourcemap: https://github.com/dwz8/emtest

sbc100 commented 2 months ago

To be clear, this issue also occurs if emscripten and the project are on the same drive right?

You mentioned on the mailing list that the source map contained a path that looked like: myArea/myApp/C:/Users/myName/emsdk/upstream/emscripten.

It seems like that both is simply broken, regardless of which drive emsdk is on. Or is it the cast that these bad paths are not generated when emsdk is on the same drive as the project?

dwz8 commented 2 months ago

If emscripten and the project are on the same drive, the source will contain relative paths to the emscripten files:

{"version":3,"sources":["test.c","../Users/diete/emsdk/upstream/emscripten/system/lib/libc/emscripten_get_heap_size.c","...

So it looks as if the bad paths are only generated when emsdk and project reside on different drives.

sbc100 commented 2 months ago

What does that emscripten_get_heap_size.c line looks like in the broken source map?

dwz8 commented 2 months ago

{"version":3,"sources":["test.c","C:/Users/diete/emsdk/upstream/emscripten/system/lib/libc/emscripten_get_heap_size.c","C:/Users/diete/emsdk...

sbc100 commented 2 months ago

That looks correct to me. Do you know where the bad path (myArea/myApp/C:/Users/myName/emsdk/upstream/emscripten) path in your original report comes from?

dwz8 commented 2 months ago

C:/Users/myName/emsdk/upstream/emscripten is the correct installation path on my computer. The map file has of course been generated by emsdk. The issue may be that localhost can not manage any references across local drives. So localhost (or any other server) can only find the emsdk files if they are in the same "myArea" tree as the source files I think.

sbc100 commented 2 months ago

I'm not sure what you mean by "localhost" here. Are you referring to the http server you are using to serve your source files? If its asked to serve C:/Users/myName/emsdk/upstream/emscripten what can't it do that? Is there some fundamental reason? Is there any other solution you can imagine other than fixing the server here?

dwz8 commented 2 months ago

sorry for the confusion. For testing purposes I have Internet Information Server running on my computer. If I launch the project in a browser the URL will be http://localhost/myArea/myApp, because the default directory is set to D:\myArea. emsdk produces the sourcemap with relative paths for my source files, which is correct. The paths to emsdk files can't be relative (and could never be unless emsdk is installed on the same drive), so it uses the local file path, which can't work.

So either it is a prerequisite to keep emsdk and all projects on the same drive, or another way must be found so that the browser can find the emsdk files. For local testing as in my use case the local file path may suffice if the browser is able to use it.

sbc100 commented 2 months ago

so it uses the local file path, which can't work.

Why do you say it cannot work? Its seems like a limitation of the server "Internet Information Server"? Perhaps it is configurable or perhaps you could try a different server that does support absolute paths somehow?

It seems like either you need to find or configure as server that allows absolute paths, or you need to put emsdk in a place where it can be found using a relative path. I'm not sure this is something that can be fixed on the emscripten side.

dwz8 commented 2 months ago

Thanks for the suggestion, I will have a look at that. Chrome turns the absolute path in the map into file:myArea/myApp/C:/Users/diete/emsdk/upstream/emscripten So perhaps the issue is there. I will examine this further. Thanks for your attention!

sbc100 commented 2 months ago

Thanks for the suggestion, I will have a look at that. Chrome turns the absolute path in the map into file:myArea/myApp/C:/Users/diete/emsdk/upstream/emscripten

Oh I see.. that does seem wrong. So in that case no request is actually being sent to the server? That seems pretty strange.

dwz8 commented 2 months ago

I just ran the project in Firefox. It seems to sort out the absolute path correctly, however, when accessing the source file I see an error: unsupported protocol for sourcemap request c:/Users/diete/emsdk/upstream/emscripten/system/lib/dlmalloc.c

dwz8 commented 1 month ago

I have moved the emsdk folder into the path where its files can be addressed using a relative path in the source map. This works for me, and I don't have to wait for any changes in the browsers.

Thanks for your attention to this!