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