• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@rules_cc//cc:defs.bzl", "cc_binary")
2load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
3
4BASE_LINKOPTS = [
5    #"-flto",  # https://github.com/emscripten-core/emsdk/issues/807
6    "--bind",  # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
7    "-s ALLOW_MEMORY_GROWTH=1",
8    "-s USE_PTHREADS=0",  # Disable pthreads
9    "-s ASSERTIONS=0",  # Turn off assertions
10    "-s MODULARIZE=1",
11    "-s EXPORT_NAME=WebGPUKitInit",
12    "-s DISABLE_EXCEPTION_CATCHING=1",  # Disable all exception catching
13    "-s NODEJS_CATCH_EXIT=0",  # We don't have a 'main' so disable exit() catching
14    "-s WASM=1",
15    "-s USE_WEBGPU=1",
16]
17
18RELEASE_OPTS = [
19    "--closure 1",  # Run the closure compiler
20]
21
22DEBUG_OPTS = [
23    "--closure 0",  # Do not use closure
24]
25
26config_setting(
27    name = "release_opts",
28    values = {"compilation_mode": "opt"},
29)
30
31config_setting(
32    name = "debug_opts",
33    values = {"compilation_mode": "dbg"},
34)
35
36cc_binary(
37    name = "hello-world",
38    srcs = ["bindings.cpp"],
39    linkopts = select({
40        ":debug_opts": BASE_LINKOPTS + DEBUG_OPTS,
41        ":release_opts": BASE_LINKOPTS + RELEASE_OPTS,
42        "//conditions:default": BASE_LINKOPTS + RELEASE_OPTS,
43    }),
44    # This target won't build successfully on its own because of missing emscripten
45    # headers etc. Therefore, we hide it from wildcards.
46    tags = ["manual"],
47)
48
49wasm_cc_binary(
50    name = "hello-world-wasm",
51    cc_target = ":hello-world",
52)
53