Skip to content

Bazel support for multiple emscripten caches #1581

@DoDoENT

Description

@DoDoENT

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, 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 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?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions