| load("@aspect_rules_js//js:defs.bzl", "js_library") |
| load("//infra-sk:index.bzl", "bool_flag", "extract_files_from_skia_wasm_container") |
| |
| bool_flag( |
| default = True, |
| flag_name = "use_canvaskit_from_container", |
| ) |
| |
| # This target makes the canvaskit js and wasm binaries available for tests. This is not the same |
| # as ../build because we want to be able to control which binaries get used when we deploy a |
| # container, but we are less stringent when running tests on the infra CI. |
| extract_files_from_skia_wasm_container( |
| name = "fetch_canvaskit_wasm", |
| testonly = True, |
| container = "@pinned_jsfiddle", |
| container_files = { |
| "/usr/local/share/jsfiddle/dist/index.d.ts": "from_container/canvaskit.d.ts", |
| "/usr/local/share/jsfiddle/dist/canvaskit.js": "from_container/canvaskit.js", |
| "/usr/local/share/jsfiddle/dist/canvaskit.wasm": "from_container/canvaskit.wasm", |
| }, |
| enabled_flag = ":use_canvaskit_from_container", |
| visibility = ["//shaders:__subpackages__"], |
| ) |
| |
| # This js_library rule makes the source a viable dependency of ts_library rules (and thus visible |
| # during compilation). |
| js_library( |
| name = "canvaskit_types", |
| srcs = [ |
| "types/canvaskit.d.ts", |
| ], |
| visibility = ["//shaders:__subpackages__"], |
| deps = [ |
| # Because we copy the index.d.ts out of canvaskit, we lose the transitive dependency on the |
| # webgpu types that canvaskit itself has. |
| "//:node_modules/@webgpu/types", |
| ], |
| ) |
| |
| # This copy rule makes it so we can import from '../../wasm_libs/types/canvaskit' and not |
| # '../../wasm_libs/from_container/canvaskit', which does not make the source easily toggleable. |
| genrule( |
| name = "copy_canvaskit_types", |
| srcs = ["canvaskit.d.ts"], |
| outs = ["types/canvaskit.d.ts"], |
| # Copy the one input file to the one output location |
| cmd = "cp $< $@", |
| ) |
| |
| filegroup( |
| name = "canvaskit.d.ts", |
| srcs = select({ |
| ":use_canvaskit_from_container_true": ["from_container/canvaskit.d.ts"], |
| ":use_canvaskit_from_container_false": ["local_build/canvaskit.d.ts"], |
| }), |
| visibility = ["//shaders:__subpackages__"], |
| ) |
| |
| filegroup( |
| name = "canvaskit.js", |
| srcs = select({ |
| ":use_canvaskit_from_container_true": ["from_container/canvaskit.js"], |
| ":use_canvaskit_from_container_false": ["local_build/canvaskit.js"], |
| }), |
| visibility = ["//shaders:__subpackages__"], |
| ) |
| |
| filegroup( |
| name = "canvaskit.wasm", |
| srcs = select({ |
| ":use_canvaskit_from_container_true": ["from_container/canvaskit.wasm"], |
| ":use_canvaskit_from_container_false": ["local_build/canvaskit.wasm"], |
| }), |
| visibility = ["//shaders:__subpackages__"], |
| ) |
| |
| genrule( |
| name = "make version file", |
| outs = ["version.js"], |
| # We use LATEST here to make Puppeteer tests more deterministic. |
| cmd = """echo "const SKIA_VERSION = 'LATEST';" > $@""", |
| visibility = ["//shaders:__subpackages__"], |
| ) |