2022-11-08 14:21:06 -08:00
|
|
|
load(":toolchain.bzl", "emscripten_cc_toolchain_config_rule")
|
2020-09-10 21:42:46 -04:00
|
|
|
|
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
|
|
|
|
|
|
filegroup(
|
2022-05-09 11:30:43 -07:00
|
|
|
name = "common_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
srcs = [
|
[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 18:23:07 +02:00
|
|
|
"@emscripten_cache//:emscripten_config",
|
2020-09-10 21:42:46 -04:00
|
|
|
"env.sh",
|
2021-12-20 11:24:56 -08:00
|
|
|
"env.bat",
|
2022-12-19 18:39:40 -08:00
|
|
|
"@nodejs//:node_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
filegroup(
|
2022-05-09 11:30:43 -07:00
|
|
|
name = "compiler_files",
|
|
|
|
|
srcs = [
|
|
|
|
|
"emcc.sh",
|
|
|
|
|
"emcc.bat",
|
|
|
|
|
"@emsdk//:compiler_files",
|
|
|
|
|
":common_files",
|
|
|
|
|
],
|
2020-09-10 21:42:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
filegroup(
|
2022-05-09 11:30:43 -07:00
|
|
|
name = "linker_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
srcs = [
|
|
|
|
|
"emcc_link.sh",
|
2021-12-20 11:24:56 -08:00
|
|
|
"emcc_link.bat",
|
2020-09-10 21:42:46 -04:00
|
|
|
"link_wrapper.py",
|
2022-05-09 11:30:43 -07:00
|
|
|
"@emsdk//:linker_files",
|
|
|
|
|
":common_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
filegroup(
|
2022-05-09 11:30:43 -07:00
|
|
|
name = "ar_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
srcs = [
|
2022-05-09 11:30:43 -07:00
|
|
|
"emar.sh",
|
|
|
|
|
"emar.bat",
|
|
|
|
|
"@emsdk//:ar_files",
|
|
|
|
|
":common_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
2023-08-29 10:21:25 -04:00
|
|
|
filegroup(
|
|
|
|
|
name = "all_files",
|
|
|
|
|
srcs = [
|
|
|
|
|
":ar_files",
|
|
|
|
|
":compiler_files",
|
|
|
|
|
":linker_files",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
2020-09-10 21:42:46 -04:00
|
|
|
filegroup(name = "empty")
|
|
|
|
|
|
2024-12-06 18:26:36 +01:00
|
|
|
# dlmalloc.bc is implicitly added by the emscripten toolchain
|
2020-09-10 21:42:46 -04:00
|
|
|
cc_library(name = "malloc")
|
|
|
|
|
|
|
|
|
|
emscripten_cc_toolchain_config_rule(
|
|
|
|
|
name = "wasm",
|
|
|
|
|
cpu = "wasm",
|
[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 18:23:07 +02:00
|
|
|
em_config = "@emscripten_cache//:emscripten_config",
|
2022-05-09 11:30:43 -07:00
|
|
|
emscripten_binaries = "@emsdk//:compiler_files",
|
2021-12-20 11:24:56 -08:00
|
|
|
script_extension = select({
|
|
|
|
|
"@bazel_tools//src/conditions:host_windows": "bat",
|
|
|
|
|
"//conditions:default": "sh",
|
|
|
|
|
}),
|
2020-09-10 21:42:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cc_toolchain(
|
|
|
|
|
name = "cc-compiler-wasm",
|
2023-08-29 10:21:25 -04:00
|
|
|
all_files = ":all_files",
|
2022-05-09 11:30:43 -07:00
|
|
|
ar_files = ":ar_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
as_files = ":empty",
|
2022-05-09 11:30:43 -07:00
|
|
|
compiler_files = ":compiler_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
dwp_files = ":empty",
|
2022-05-09 11:30:43 -07:00
|
|
|
linker_files = ":linker_files",
|
2020-09-10 21:42:46 -04:00
|
|
|
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",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2022-11-08 14:21:06 -08:00
|
|
|
toolchain(
|
|
|
|
|
name = "cc-toolchain-wasm",
|
|
|
|
|
target_compatible_with = ["@platforms//cpu:wasm32"],
|
|
|
|
|
toolchain = ":cc-compiler-wasm",
|
|
|
|
|
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
|
|
|
|
|
)
|
|
|
|
|
|
2020-09-10 21:42:46 -04:00
|
|
|
py_binary(
|
|
|
|
|
name = "wasm_binary",
|
|
|
|
|
srcs = ["wasm_binary.py"],
|
|
|
|
|
)
|