comparison third_party/emsdk/bazel/test_external/BUILD @ 179:8d17f6e6e290

[ThirdParty] Added emsdk bazel rules that can be supported by bazel 9.0.0
author MrJuneJune <me@mrjunejune.com>
date Thu, 22 Jan 2026 21:23:17 -0800
parents
children
comparison
equal deleted inserted replaced
178:94705b5986b3 179:8d17f6e6e290
1 load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
2 load("@rules_cc//cc:defs.bzl", "cc_binary")
3
4 cc_binary(
5 name = "hello-world",
6 srcs = ["hello-world.cc"],
7 )
8
9 wasm_cc_binary(
10 name = "hello-world-wasm",
11 cc_target = ":hello-world",
12 outputs = [
13 "hello-world.js",
14 "hello-world.wasm",
15 ],
16 )
17
18 BASE_LINKOPTS = [
19 "--bind", # Enable embind
20 "-sMODULARIZE",
21 "--pre-js",
22 "hello-embind-interface.js",
23 ]
24
25 RELEASE_OPTS = [
26 "--closure=1", # Run the closure compiler
27 # Tell closure about the externs file, so as not to minify our JS public API.
28 "--closure-args=--externs=$(location hello-embind-externs.js)"
29 ]
30
31 DEBUG_OPTS = [
32 "--closure=0", # Do not use closure
33 ]
34
35 config_setting(
36 name = "release_opts",
37 values = {"compilation_mode": "opt"},
38 )
39
40 config_setting(
41 name = "debug_opts",
42 values = {"compilation_mode": "dbg"},
43 )
44
45 cc_binary(
46 name = "hello-embind",
47 srcs = ["hello-embind.cc"],
48 features = ["emcc_debug_link"],
49 additional_linker_inputs = [
50 "hello-embind-externs.js",
51 "hello-embind-interface.js",
52 ],
53 linkopts = select({
54 ":debug_opts": BASE_LINKOPTS + DEBUG_OPTS,
55 ":release_opts": BASE_LINKOPTS + RELEASE_OPTS,
56 "//conditions:default": BASE_LINKOPTS + RELEASE_OPTS,
57 }),
58 # This target won't build successfully on its own because of missing emscripten
59 # headers etc. Therefore, we hide it from wildcards.
60 tags = ["manual"],
61 )
62
63 wasm_cc_binary(
64 name = "hello-embind-wasm",
65 cc_target = ":hello-embind",
66 )
67