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