xref: /aosp_15_r20/external/skia/modules/pathkit/BUILD.bazel (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1load("@skia_user_config//:copts.bzl", "DEFAULT_COPTS")
2load("//bazel:macros.bzl", "wasm_cc_binary")
3
4package(
5    default_applicable_licenses = ["//:license"],
6)
7
8licenses(["notice"])
9
10BASE_LINKOPTS = [
11    #"-flto",  # https://github.com/emscripten-core/emsdk/issues/807
12    "--bind",  # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
13    "-fno-rtti",
14    "--no-entry",
15    "-sALLOW_MEMORY_GROWTH",
16    "-sUSE_PTHREADS=0",  # Disable pthreads
17    "-sMODULARIZE",
18    "-sDISABLE_EXCEPTION_CATCHING",  # Disable all exception catching
19    "-sNODEJS_CATCH_EXIT=0",  # We don't have a 'main' so disable exit() catching
20    "-sWASM",
21    "-sMAX_WEBGL_VERSION=2",
22    "-sUSE_WEBGL2=1",
23    "-sFORCE_FILESYSTEM=0",
24    "-sDYNAMIC_EXECUTION=0",
25    "-sERROR_ON_UNDEFINED_SYMBOLS=0",
26    "-sFILESYSTEM=0",
27    "-sEXPORTED_FUNCTIONS=['_malloc','_free']",
28]
29
30BASE_OPTS = [
31    "-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0",
32    "-DSK_TRIVIAL_ABI=[[clang::trivial_abi]]",
33]
34
35RELEASE_OPTS = BASE_OPTS + [
36    "-Oz",
37    "--closure 1",
38    "-DSK_RELEASE",
39]
40
41DEBUG_OPTS = BASE_OPTS + [
42    "-O0",
43    "--js-opts",
44    "0",
45    "-sSAFE_HEAP=1",
46    "-sASSERTIONS=1",
47    "-g3",
48    "-DPATHKIT_TESTING",
49    "-DSK_DEBUG",
50]
51
52# Note: These are defines that only impact the _bindings.cpp files in this
53# folder. Any defines that need to effect the entire Skia build should go in
54# //bazel/BUILD.bazel
55CK_DEFINES = [
56    "CK_INCLUDE_PATHOPS",
57    "EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0",  # Allows us to compile with -fno-rtti
58]
59
60CK_RELEASE_OPTS = [
61    # Run the closure compiler
62    "--closure 1",
63    # pass the externs file in
64    "--closure-args=--externs=$(location externs.js)",
65]
66
67CK_LINKOPTS = BASE_LINKOPTS + [
68    "-sEXPORT_NAME=PathKitInit",
69    "-sINITIAL_MEMORY=32MB",
70    "--pre-js",
71    "modules/pathkit/chaining.js",
72    "--pre-js",
73    "modules/pathkit/helper.js",
74] + select({
75    "//bazel/common_config_settings:debug_build": DEBUG_OPTS,
76    "//conditions:default": RELEASE_OPTS + CK_RELEASE_OPTS,
77})
78
79# All JS files that could possibly be included via --pre-js or --post-js.
80# Whether they actually will be or not will be controlled above in the
81# construction of CK_LINKOPTS.
82JS_INTERFACE_FILES = [
83    "chaining.js",
84    "helper.js",
85]
86
87CK_SRCS = [
88    "pathkit_wasm_bindings.cpp",
89]
90
91CK_COPTS = [
92    "-Wno-header-hygiene",
93]
94
95cc_binary(
96    name = "pathkit.build",
97    srcs = CK_SRCS,
98    additional_linker_inputs = JS_INTERFACE_FILES + ["externs.js"],
99    copts = DEFAULT_COPTS + CK_COPTS,
100    linkopts = CK_LINKOPTS,
101    local_defines = CK_DEFINES,
102    # This target won't build successfully on its own because of missing
103    # emscripten headers etc. Therefore, we hide it from wildcards.
104    tags = ["manual"],
105    deps = [
106        "//:core",
107        "//:pathops",
108    ],
109)
110
111wasm_cc_binary(
112    name = "pathkit",
113    # Whatever is before the dot will be the name of the output js and wasm, aka "the stem".
114    # https://github.com/emscripten-core/emsdk/blob/4a48a752e6a8bef6f222622f2b4926d5eb3bdeb3/bazel/emscripten_toolchain/wasm_cc_binary.bzl#L179
115    cc_target = ":pathkit.build",
116    visibility = [
117        "//infra/jsfiddle:__pkg__",
118    ],
119)
120