Files
ci-emsdk/bazel/emscripten_toolchain/BUILD.bazel
Michael Allwright 82d41a76d3 [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
2024-07-01 09:23:07 -07:00

104 lines
2.1 KiB
Python

load(":toolchain.bzl", "emscripten_cc_toolchain_config_rule")
package(default_visibility = ["//visibility:public"])
filegroup(
name = "common_files",
srcs = [
"@emscripten_cache//:emscripten_config",
"env.sh",
"env.bat",
"@nodejs//:node_files",
],
)
filegroup(
name = "compiler_files",
srcs = [
"emcc.sh",
"emcc.bat",
"@emsdk//:compiler_files",
":common_files",
],
)
filegroup(
name = "linker_files",
srcs = [
"emcc_link.sh",
"emcc_link.bat",
"link_wrapper.py",
"@emsdk//:linker_files",
":common_files",
],
)
filegroup(
name = "ar_files",
srcs = [
"emar.sh",
"emar.bat",
"@emsdk//:ar_files",
":common_files",
],
)
filegroup(
name = "all_files",
srcs = [
":ar_files",
":compiler_files",
":linker_files",
],
)
filegroup(name = "empty")
# dlmalloc.bc is implictly added by the emscripten toolchain
cc_library(name = "malloc")
emscripten_cc_toolchain_config_rule(
name = "wasm",
cpu = "wasm",
em_config = "@emscripten_cache//:emscripten_config",
emscripten_binaries = "@emsdk//:compiler_files",
script_extension = select({
"@bazel_tools//src/conditions:host_windows": "bat",
"//conditions:default": "sh",
}),
)
cc_toolchain(
name = "cc-compiler-wasm",
all_files = ":all_files",
ar_files = ":ar_files",
as_files = ":empty",
compiler_files = ":compiler_files",
dwp_files = ":empty",
linker_files = ":linker_files",
objcopy_files = ":empty",
strip_files = ":empty",
toolchain_config = "wasm",
toolchain_identifier = "emscripten-wasm",
)
cc_toolchain_suite(
name = "everything",
toolchains = {
"wasm": ":cc-compiler-wasm",
"wasm|emscripten": ":cc-compiler-wasm",
},
)
toolchain(
name = "cc-toolchain-wasm",
target_compatible_with = ["@platforms//cpu:wasm32"],
toolchain = ":cc-compiler-wasm",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
py_binary(
name = "wasm_binary",
srcs = ["wasm_binary.py"],
)