skia2/modules/canvaskit/BUILD.bazel
Kevin Lubick ef3d6af042 [infra] Add POC Bazel rules for CanvasKit
Many things are not enabled currently (e.g. Skottie, Paragraph),
but we can render many APIs using WebGL.

To turn on Paragraph, etc, we'll need to tackle fonts, which
is a separate effort.

This also changes where the build artifacts go. ./build/ is
easier to deal with than the old way of sticking them in
./npm_build/bin

Change-Id: Ia377360af580a887d03630670438fea2e3157e90
Bug: skia:12541
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/470682
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2021-11-12 21:38:46 +00:00

165 lines
4.3 KiB
Python

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
package(default_visibility = ["//:__subpackages__"])
BASE_LINKOPTS = [
#"-flto", # https://github.com/emscripten-core/emsdk/issues/807
"--bind", # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript
"--no-entry",
"-sALLOW_MEMORY_GROWTH",
"-sUSE_PTHREADS=0", # Disable pthreads
"-sMODULARIZE",
"-sDISABLE_EXCEPTION_CATCHING", # Disable all exception catching
"-sNODEJS_CATCH_EXIT=0", # We don't have a 'main' so disable exit() catching
"-sWASM",
"-sMAX_WEBGL_VERSION=2",
"-sFORCE_FILESYSTEM=0",
"-sFILESYSTEM=0",
]
RELEASE_OPTS = [
# We disable closure for now, because we need a way to pass in the externs file,
# which does not appear to be exposed on the emscripten toolchain.
# "--closure 1", # Run the closure compiler
"-sASSERTIONS=0", # Turn off assertions
]
DEBUG_OPTS = [
"--closure 0", # Do not use closure
"-sASSERTIONS", # Turn on assertions
"-sGL_ASSERTIONS",
]
GM_OPTS = [
"-sEXPORT_NAME=InitWasmGMTests",
"--pre-js",
"modules/canvaskit/gm.js",
]
filegroup(
name = "hdrs",
srcs = [
"WasmCommon.h",
],
)
cc_binary(
name = "gm-bindings",
testonly = True,
srcs = [
"gm_bindings.cpp",
":hdrs",
"//gm:gms", # Required for the registry to work
"//src/ports:default_global_init",
"//src/ports:fontmgr",
"//src/ports:malloc",
"//src/ports:skdebug",
"//src/ports:skia_image_generator",
],
additional_linker_inputs = ["gm.js"],
linkopts = select({
"//bazel/common_config_settings:debug_build": BASE_LINKOPTS + GM_OPTS + DEBUG_OPTS,
"//bazel/common_config_settings:release_build": BASE_LINKOPTS + GM_OPTS + RELEASE_OPTS,
"//conditions:default": BASE_LINKOPTS + GM_OPTS + RELEASE_OPTS,
}),
local_defines = [
"SK_GL",
"SK_USE_WEBGL",
],
# This target won't build successfully on its own because of missing emscripten
# headers etc. Therefore, we hide it from wildcards.
tags = ["manual"],
deps = [
"//:gms",
"//:hash_and_encode",
"//:tests",
],
)
wasm_cc_binary(
name = "gm-bindings-wasm",
testonly = True,
cc_target = ":gm-bindings",
)
CK_DEFINES = [
"SK_NO_FONTS", #TODO(kjlubick)
"SK_DISABLE_LEGACY_SHADERCONTEXT",
] + select({
"//bazel/common_config_settings:gl_backend": [
"SK_GL",
"SK_SUPPORT_GPU=1",
],
"//conditions:default": [
"SK_SUPPORT_GPU=0",
],
})
CK_OPTS = BASE_LINKOPTS + [
"-sEXPORT_NAME=CanvasKitInit",
# The order of these --pre-js flags matters! The preamble is a partially open scope and the
# postamble closes it.
"--pre-js",
"modules/canvaskit/preamble.js",
"--pre-js",
"modules/canvaskit/color.js",
"--pre-js",
"modules/canvaskit/memory.js",
"--pre-js",
"modules/canvaskit/util.js",
"--pre-js",
"modules/canvaskit/interface.js",
"--pre-js",
"modules/canvaskit/postamble.js",
"-sINITIAL_MEMORY=128MB",
] + select({
"//bazel/common_config_settings:gl_backend": [
"--pre-js",
"modules/canvaskit/cpu.js",
"--pre-js",
"modules/canvaskit/gpu.js",
],
"//conditions:default": [
"--pre-js",
"modules/canvaskit/cpu.js",
],
}) + select({
"//bazel/common_config_settings:debug_build": DEBUG_OPTS,
"//conditions:default": RELEASE_OPTS,
})
cc_binary(
name = "canvaskit",
srcs = [
"canvaskit_bindings.cpp",
":hdrs",
"//src/ports:default_global_init",
"//src/ports:fontmgr",
"//src/ports:malloc",
"//src/ports:skdebug",
"//src/ports:skia_image_generator",
],
additional_linker_inputs = [
"color.js",
"interface.js",
"memory.js",
"postamble.js",
"preamble.js",
"util.js",
],
linkopts = CK_OPTS,
local_defines = CK_DEFINES,
# This target won't build successfully on its own because of missing emscripten
# headers etc. Therefore, we hide it from wildcards.
tags = ["manual"],
deps = [
"//:skia-core",
],
)
wasm_cc_binary(
name = "canvaskit-wasm",
cc_target = ":canvaskit",
)