[bazel] Fix emsdk python path issue on Windows.#1685
[bazel] Fix emsdk python path issue on Windows.#1685kalmard0 wants to merge 1 commit intoemscripten-core:mainfrom
Conversation
Tested with bazel 8.6.0 with git bash as the main shell and `build --action_env=EM_FROZEN_CACHE=0`. Without this change, my build fails with the error: ``` The system cannot find the path specified. emcc: error: subprocess 1/1 failed (returned 1)! (cmdline: 'C:\bazel\build_root\pn2yxrdx\execroot\_main\external\emsdk++emscripten_deps+emscripten_bin_win\emscripten\em++.bat' -c -O2 -Wall -fno-unroll-loops -g -sSTRICT -Werror -sMEMORY64=1 '-ffile-prefix-map=C:\bazel\build_root\pn2yxrdx\execroot\_main\external\emsdk++emscripten_deps+emscripten_bin_win\emscripten=/emsdk/emscripten' '-ffile-prefix-map=..\..\..=/emsdk/emscripten' -fdebug-compilation-dir=/emsdk/emscripten -std=c++20 ../../../system/lib/embind/bind.cpp) ```
|
I wonder if we could find a way to instead make |
The As far as I understand, Bazel provides either I think that the proposed change in this PR is the best possible solution and consistent with unix version (the For more details about the reasons why an absolute path can't be resolved within the Starlark, you can see the explanation from the absolute expert on Bazel from whom I learned a lot - Google's Gemini 😅 |
|
The reason I'm not totally sure about this patch is that its in the Also, why is it needed in the .bat file but not on the equivalent I will defer to others on all things bazel though so LGTM aside from the above questions/concerns. |
I see... The culprit is I've never tried building on Mac/Linux with a disabled frozen cache - maybe the Linux/Mac will encounter the same problem. Bazel goes to great lengths to prevent escaping the sandbox and attempting to modify read-only folders. If you need to use a non-default cache, there is already a mechanism for that using the cache extension. See the README for details. However, even this extension has problems with hermeticity - even though it's technically hermetic, the built cache is different on every machine, so remote caching and remote build do not work. I fixed that in my PR, where you can use embuilder to build the non-default cache on one machine, deploy the cache on some server, and then use the new @kalmard0, what problem are you trying to solve? Why are you using |
| set EM_CONFIG=%ROOT_DIR%\%EM_CONFIG_PATH% | ||
|
|
||
| :: If EMSDK_PYTHON is a relative path, make it absolute using ROOT_DIR. | ||
| :: This is needed because emscripten system library generation invokes compilers |
There was a problem hiding this comment.
The library generation should always be disabled in Bazel, as it is not hermetic and won't work with remote builds.
I should avoid doing reviews at late hours 😅 - I saw the path being "absolutized" for a totally different variable than it was written in code 😅 |
Do you know the reason for this? I would hope our libraries were hermetic.. perhaps we can fix that in emscripten if they not? |
I don't know. But you can run embuilder with the same flags twice, even on the same machine, the SHA256 of the resulting binaries will be different... This is enough to invalidate the Bazel cache. And even if you somehow manage to make |
|
|
Yeah, that's what I was afraid of and what explains your use case. The default cache that ships with emscripten does not support 64-bit memory or LTO, so you need to build your own. A default distribution of emscripten does that lazily, on demand. However, this doesn't work in Bazel as the cache builder tool does not produce identical binaries (the SHA256 hash differs even if you always use the same build flags), so different Bazel workers observe different inputs to their actions, and this results in too many unnecessary rebuilds of code at best, or a broken binary at worst. Instead of "unfreezing" the cache, you should do this the way which is compatible with Bazel, as explained in the README. Basically, you need to create your own cache with 64-bit memory enabled and then use it: emscripten_cache = use_extension(
"@emsdk//:emscripten_cache.bzl",
"emscripten_cache",
)
emscripten_cache.configuration(flags = ["--wasm64"])
emscripten_cache.targets(targets = [
"crtbegin",
"libprintf_long_double-debug",
"libstubs-debug",
"libnoexit",
"libc-debug",
"libdlmalloc",
"libcompiler_rt",
"libc++-noexcept",
"libc++abi-debug-noexcept",
"libsockets"
])This will then build additional cache compatible with 64-bit, which you can use without needing to unset Note: You may need to tweak the list of targets to rebuild based on your project's needs. This is the list I needed for my projects. You can see what's missing by observing the build error from emscripten telling you that specific target is missing and cannot be lazily rebuilt because |
|
@DoDoENT Thank you, I totally missed that. In that case I don't consider this a valid pull request for my purposes. Feel free to close it. |
Tested with bazel 8.6.0 with git bash as the main shell and
build --action_env=EM_FROZEN_CACHE=0.Without this change, my build fails with the error: