-
Notifications
You must be signed in to change notification settings - Fork 742
[Bazel] Dynamically generate the Emscripten cache #1402
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
Conversation
@walkingeyerobot let me know if you think this is going in a reasonable direction or if you would do something differently |
export EM_BINARYEN_ROOT=$$(realpath $$(dirname $$(dirname $(location :emscripten/embuilder.py)))) | ||
export EM_LLVM_ROOT=$$EM_BINARYEN_ROOT/bin | ||
export EM_EMSCRIPTEN_ROOT=$$EM_BINARYEN_ROOT/emscripten | ||
export EM_CACHE=$(RULEDIR)/emscripten/cache |
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.
These values normally part of the config file. See https://github.com/emscripten-core/emsdk/blob/main/bazel/emscripten_toolchain/emscripten_config
I think the only one you want to override here is EM_CACHE. The others should all come from that config file.
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.
The problem there (I think/I will test this) is that emscripten_config
is part of the @emsdk//
while this code is inside @emscripten_bin_XXX//
so this might create a circular dependency.
I think the only one you want to override here is EM_CACHE. The others should all come from that config file.
Also the values of EMSCRIPTEN_ROOT
, BINARYEN_ROOT
, LLVM_ROOT
in emscripten_config are based on environment variables which are set in env.sh/env.bat, which in turn, depends on environment variables set in toolchain.bzl.
Is there some shared, writable location that we can use is the one true location for the emscripten cache? Somewhere that is both readable and writable when the build rules run? |
You can always set the following in .bazelrc
This seems to work, well, sort of... The cache is built fine but it is breaking my builds for the moment. When using:
I thought the latter issue with |
I thought I had a really nice alternative solution to what I have done so far. The idea would have been to move cache generation from inside For example, you set up a secondary cache in your WORKSPACE with something like: emsdk_emscripten_cache(
name = "pic_cache"
mode = ["--pic"],
libraries = ["crtbegin", "libprintf_long_double-debug"]
) and then for each target that needs to use this cache, you could set In addition to setting |
Closed in favour of #1405 |
This is a draft PR for sharing my progress on this feature. The idea is to use embuilder to generate the Emscripten cache dynamically by specifying what you want upfront and in which configuration (i.e., wasm64, lto, pic etc).
For now I would really appreciate any input on these remaining problems:
Output names
Some libraries generate
.a
and some.o
, I suspect that it is just the c runtime libraries that emit the.o
files, so I could tell Bazel that if the name of the library begins with crt then its output is.o
?Overlaying the cache
I added my output to
link_files
but this seems to be ignored by the Emscripten linker. When I compile a program, Emscripten considers the cache to be:external/emscripten_bin_linux/emscripten/cache/
while, the cache assets from my genrule are actually stored at:execroot/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/emscripten_bin_linux/emscripten/cache/
. I am not sure what the best approach for moving forward here is.Portability
I haven't found away to get rid of the
dirname
andrealpath
for the moment. It seems almost impossible to provide a rule in Bazel with a path which means it is very difficult to set the values ofBINARYEN_ROOT
etc forembuilder
. The best solution I can think of for the moment is to leave the Bash-isms in place and just usecmd_bash
andcmd_bat
(provided by genrule) to set the environment variables.Related issues: