• 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
4package(default_visibility = ["//:__subpackages__"])
5
6BASE_LINKOPTS = [
7    #"-flto",  # https://github.com/emscripten-core/emsdk/issues/807
8    "--bind",  # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
9    "--no-entry",
10    "-sALLOW_MEMORY_GROWTH",
11    "-sUSE_PTHREADS=0",  # Disable pthreads
12    "-sMODULARIZE",
13    "-sDISABLE_EXCEPTION_CATCHING",  # Disable all exception catching
14    "-sNODEJS_CATCH_EXIT=0",  # We don't have a 'main' so disable exit() catching
15    "-sWASM",
16    "-sMAX_WEBGL_VERSION=2",
17    "-sFORCE_FILESYSTEM=0",
18    "-sFILESYSTEM=0",
19]
20
21RELEASE_OPTS = [
22    # We disable closure for now, because we need a way to pass in the externs file,
23    # which does not appear to be exposed on the emscripten toolchain.
24    # "--closure 1",  # Run the closure compiler
25    "-sASSERTIONS=0",  # Turn off assertions
26]
27
28DEBUG_OPTS = [
29    "--closure 0",  # Do not use closure
30    "-sASSERTIONS",  # Turn on assertions
31    "-sGL_ASSERTIONS",
32]
33
34GM_OPTS = [
35    "-sEXPORT_NAME=InitWasmGMTests",
36    "--pre-js",
37    "modules/canvaskit/gm.js",
38]
39
40filegroup(
41    name = "hdrs",
42    srcs = [
43        "WasmCommon.h",
44    ],
45)
46
47cc_binary(
48    name = "gm-bindings",
49    testonly = True,
50    srcs = [
51        "gm_bindings.cpp",
52        ":hdrs",
53        "//gm:gms",  # Required for the registry to work
54        "//src/ports:default_global_init",
55        "//src/ports:fontmgr",
56        "//src/ports:malloc",
57        "//src/ports:skdebug",
58        "//src/ports:skia_image_generator",
59    ],
60    additional_linker_inputs = ["gm.js"],
61    linkopts = select({
62        "//bazel/common_config_settings:debug_build": BASE_LINKOPTS + GM_OPTS + DEBUG_OPTS,
63        "//bazel/common_config_settings:release_build": BASE_LINKOPTS + GM_OPTS + RELEASE_OPTS,
64        "//conditions:default": BASE_LINKOPTS + GM_OPTS + RELEASE_OPTS,
65    }),
66    local_defines = [
67        "SK_GL",
68        "SK_USE_WEBGL",
69    ],
70    # This target won't build successfully on its own because of missing emscripten
71    # headers etc. Therefore, we hide it from wildcards.
72    tags = ["manual"],
73    deps = [
74        "//:gms",
75        "//:hash_and_encode",
76        "//:tests",
77    ],
78)
79
80wasm_cc_binary(
81    name = "gm-bindings-wasm",
82    testonly = True,
83    cc_target = ":gm-bindings",
84)
85
86CK_DEFINES = [
87    "SK_NO_FONTS",  #TODO(kjlubick)
88    "SK_DISABLE_LEGACY_SHADERCONTEXT",
89] + select({
90    "//bazel/common_config_settings:gl_backend": [
91        "SK_GL",
92        "SK_SUPPORT_GPU=1",
93    ],
94    "//conditions:default": [
95        "SK_SUPPORT_GPU=0",
96    ],
97})
98
99CK_OPTS = BASE_LINKOPTS + [
100    "-sEXPORT_NAME=CanvasKitInit",
101    # The order of these --pre-js flags matters! The preamble is a partially open scope and the
102    # postamble closes it.
103    "--pre-js",
104    "modules/canvaskit/preamble.js",
105    "--pre-js",
106    "modules/canvaskit/color.js",
107    "--pre-js",
108    "modules/canvaskit/memory.js",
109    "--pre-js",
110    "modules/canvaskit/util.js",
111    "--pre-js",
112    "modules/canvaskit/interface.js",
113    "--pre-js",
114    "modules/canvaskit/postamble.js",
115    "-sINITIAL_MEMORY=128MB",
116] + select({
117    "//bazel/common_config_settings:gl_backend": [
118        "--pre-js",
119        "modules/canvaskit/cpu.js",
120        "--pre-js",
121        "modules/canvaskit/gpu.js",
122    ],
123    "//conditions:default": [
124        "--pre-js",
125        "modules/canvaskit/cpu.js",
126    ],
127}) + select({
128    "//bazel/common_config_settings:debug_build": DEBUG_OPTS,
129    "//conditions:default": RELEASE_OPTS,
130})
131
132cc_binary(
133    name = "canvaskit",
134    srcs = [
135        "canvaskit_bindings.cpp",
136        ":hdrs",
137        "//src/ports:default_global_init",
138        "//src/ports:fontmgr",
139        "//src/ports:malloc",
140        "//src/ports:skdebug",
141        "//src/ports:skia_image_generator",
142    ],
143    additional_linker_inputs = [
144        "color.js",
145        "interface.js",
146        "memory.js",
147        "postamble.js",
148        "preamble.js",
149        "util.js",
150    ],
151    linkopts = CK_OPTS,
152    local_defines = CK_DEFINES,
153    # This target won't build successfully on its own because of missing emscripten
154    # headers etc. Therefore, we hide it from wildcards.
155    tags = ["manual"],
156    deps = [
157        "//:skia-core",
158    ],
159)
160
161wasm_cc_binary(
162    name = "canvaskit-wasm",
163    cc_target = ":canvaskit",
164)
165