[Bazel] Support generating a secondary cache (#1405)
This is a working solution for generating a separate Emscripten cache.
Note that this requires an additional entry in the workspace as follows:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache()
```
When used like this, the default Emscripten cache will be used. However,
if the entry is as follows:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache(flags = ["--lto"])
```
Then embuilder will be called to build all system libraries and ports
(i.e., the `ALL` option to embuilder) with the LTO option enabled. This
can take awhile, so I have also made possible to specify which libraries
you want to build explicitly:
```starlark
load("@emsdk//:emscripten_cache.bzl", emsdk_emscripten_cache = "emscripten_cache")
emsdk_emscripten_cache(
flags = ["--lto"],
libraries = [
"crtbegin",
"libprintf_long_double-debug",
"libstubs-debug",
"libnoexit",
"libc-debug",
"libdlmalloc",
"libcompiler_rt",
"libc++-noexcept",
"libc++abi-debug-noexcept",
"libsockets"
]
)
```
Resolves #807, resolves #971, resolves #1099, resolves #1362, resolves
#1401
This commit is contained in:
committed by
GitHub
parent
7fbd555dbe
commit
82d41a76d3
1
bazel/test_secondary_lto_cache/.bazelrc
Normal file
1
bazel/test_secondary_lto_cache/.bazelrc
Normal file
@@ -0,0 +1 @@
|
||||
build --incompatible_enable_cc_toolchain_resolution
|
||||
4
bazel/test_secondary_lto_cache/.gitignore
vendored
Normal file
4
bazel/test_secondary_lto_cache/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
bazel-bin
|
||||
bazel-out
|
||||
bazel-test_secondary_lto_cache
|
||||
bazel-testlogs
|
||||
19
bazel/test_secondary_lto_cache/BUILD
Normal file
19
bazel/test_secondary_lto_cache/BUILD
Normal file
@@ -0,0 +1,19 @@
|
||||
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
|
||||
|
||||
cc_binary(
|
||||
name = "hello-world",
|
||||
srcs = ["hello-world.cc"],
|
||||
linkopts = [
|
||||
"-sAUTO_NATIVE_LIBRARIES=0",
|
||||
"-flto",
|
||||
],
|
||||
)
|
||||
|
||||
wasm_cc_binary(
|
||||
name = "hello-world-wasm",
|
||||
cc_target = ":hello-world",
|
||||
outputs = [
|
||||
"hello-world.js",
|
||||
"hello-world.wasm",
|
||||
],
|
||||
)
|
||||
1
bazel/test_secondary_lto_cache/MODULE.bazel
Normal file
1
bazel/test_secondary_lto_cache/MODULE.bazel
Normal file
@@ -0,0 +1 @@
|
||||
bazel_dep(name = "platforms", version = "0.0.9")
|
||||
30
bazel/test_secondary_lto_cache/WORKSPACE
Normal file
30
bazel/test_secondary_lto_cache/WORKSPACE
Normal file
@@ -0,0 +1,30 @@
|
||||
local_repository(
|
||||
name = "emsdk",
|
||||
path = "..",
|
||||
)
|
||||
|
||||
load("@emsdk//:deps.bzl", "deps")
|
||||
|
||||
deps()
|
||||
|
||||
load("@emsdk//:emscripten_deps.bzl", "emscripten_deps")
|
||||
|
||||
emscripten_deps()
|
||||
|
||||
load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains")
|
||||
|
||||
register_emscripten_toolchains(cache = {
|
||||
"configuration": ["--lto"],
|
||||
"targets": [
|
||||
"crtbegin",
|
||||
"libprintf_long_double-debug",
|
||||
"libstubs-debug",
|
||||
"libnoexit",
|
||||
"libc-debug",
|
||||
"libdlmalloc",
|
||||
"libcompiler_rt",
|
||||
"libc++-noexcept",
|
||||
"libc++abi-debug-noexcept",
|
||||
"libsockets"
|
||||
]
|
||||
})
|
||||
6
bazel/test_secondary_lto_cache/hello-world.cc
Normal file
6
bazel/test_secondary_lto_cache/hello-world.cc
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::cout << "hello world!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user