emscripten-core / emscripten-core/emsdk

Bazel support for multiple emscripten caches

Open
#1,581 1 comment 0 reactions 1 assignee Claimed by @walkingeyerobot View on GitHub
Dominant language
Python
Stars
3.7k
Forks
821
Avg merge
2d 6h
Merged PRs (30d)
4

Description

I'm experimenting with Bazel with the goal of replacing my CMake+Conan setup with Bazel. I'm using LTO in release builds and in debug and fastbuild I'm not using LTO. However, when using Bazel, this doesn't work.

Namely, the default configuration does not ship with LTO-enabled cache, so when I enable LTO, I get the error `Exception: FROZEN_CACHE is set, but cache file is missing: "sysroot/lib/wasm32-emscripten/thinlto/crtbegin.o"`.

Then, after reading [the instructions for enabling LTO](https://github.com/emscripten-core/emsdk/blob/main/bazel/README.md), I added the declaration for cache as given in the instructions and my LTO build still didn't work.

After a couple of hours of trial and error, I discovered that the documentation does not list all minimum targets that need to be built in cache - for [my project](https://github.com/dodoent/bazel-playground) to work, I had to add at least these targets:

```
emscripten_cache.configuration(flags = ["--lto=thin"])
emscripten_cache.targets(targets = [
"crtbegin",
"libal",
"libc-mt",
"libc-mt-debug",
"libc",
"libc++-mt-noexcept",
"libc++-noexcept",
"libc++-debug-mt-noexcept",
"libc++abi-mt-noexcept",
"libc++abi-debug-mt-noexcept",
"libc++abi-debug-noexcept",
"libcompiler_rt-mt",
"libcompiler_rt",
"libembind-rtti",
"libemmalloc-mt",
"libemmalloc-mt-debug",
"libemmalloc",
"libfetch-mt",
"libfetch",
"libGL-getprocaddr",
"libGL-mt-getprocaddr",
"libhtml5",
"libnoexit",
"libsockets-mt",
"libsockets",
"libprintf_long_double-mt",
"libprintf_long_double-mt-debug",
"libprintf_long_double-debug",
"libstubs",
"libstubs-debug",
"libc-debug",
"libdlmalloc",
"libc++abi-debug-noexcept",
])
```

Now the LTO build started working, but `dbg` and `fastbuild` builds stopped working, throwing the very same exception:

`Exception: FROZEN_CACHE is set, but cache file is missing: "sysroot/lib/wasm32-emscripten/crtbegin.o"` because now the LTO-enabled cache is used, but `dbg` and `fastbuild` don't have LTO enabled.

My current workaround is to simply also enable LTO in `dbg` and `fastbuild` modes, but I don't see this as ideal, considering that I didn't have this requirement with my cmake-based setup.

I'm wondering whether it's possible to configure multiple emscripten caches, so that different build configurations could use different caches? Or maybe, treat the cache as "build artefact" instead of a "repository artefact" so it would be built as part of a regular Bazel build and cached on caching servers?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.