skia2/BUILD.bazel
Kevin Lubick 8ed49ea6e3 [infra] Add Bazel rules for codecs.
This ports the third_party BUILD.gn files related to codecs
(with a best-effort on arm/SIMD stuff). This includes:
 - libpng
 - libjpeg-turbo
 - libwebp
 - wuffs (gif)
 - libgifcodec
 - dng_sdk and piex (raw codec)

This expands the string_flag_with_values macro to allow
multiple values to be set at once. This was added in Bazel 5.0.0,
however the latest pre-release version of that has a bug [1]
which slows down compilation dramatically. This was fixed at
ToT, but not released. As a result, I started using the Bazel
6 pre-release (via bazelisk).

The macro select_multi makes writing select() where multiple
elements could be on possible/easier.

One can try compiling certain codecs by running:
bazel build :skia-core --config clang --include_codec=raw_codec --include_codec=png_codec

Suggested Review Order:
 - bazel/macros.bzl
 - bazel/common_config_settings/defs.bzl and its BUILD.bazel
   to see how the codec options are defined.
 - BUILD.bazel to see how the codec settings are used.
 - src/codec/BUILD.bazel to see the inclusion of Skia files to
   deal with specific codecs.
 - third_party/BUILD.bazel (while referencing the corresponding
   BUILD.gn files, such as third_party/libwebp/BUILD.gn)
 - Everything else.

Change-Id: I797375a35fa345d9835e7b2a2ab23371c45953c3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/469456
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
2021-11-11 20:10:01 +00:00

191 lines
5.0 KiB
Python

# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:macros.bzl", "select_multi")
package(default_visibility = ["//:__subpackages__"])
cc_test(
name = "bazel_test",
size = "small",
srcs = [
"//experimental/bazel_test:srcs",
"//include/config:hdrs",
"//include/core:hdrs",
"//src/ports:skdebug",
],
deps = [
"//third_party:libpng",
"//third_party:musl_compat",
],
)
CORE_SRCS = [
"//include/private:hdrs",
"//include/third_party:skcms-hdrs",
"//src/codec:srcs",
"//src/core:srcs",
"//src/image:srcs",
"//src/images:srcs",
"//src/effects:srcs",
"//src/opts:srcs",
"//src/pathops:srcs",
"//src/sfnt:srcs",
"//src/shaders:srcs",
"//src/utils:srcs",
"//third_party:skcms",
] + selects.with_or({
# https://github.com/bazelbuild/bazel-skylib/blob/main/docs/selects_doc.md#selectswith_or
("//bazel/common_config_settings:gl_backend", "//bazel/common_config_settings:vulkan_backend"): [
"//src/gpu:srcs",
"//src/sksl:srcs",
# TODO(kjlubick) should mock be test only?
"//include/private:mock-hdrs",
"//src/gpu:mock-srcs",
],
"//conditions:default": [],
})
CORE_HDRS = [
"//include/codec:hdrs",
"//include/config:hdrs",
"//include/core:hdrs",
"//include/effects:hdrs",
"//include/encode:hdrs",
"//include/pathops:hdrs",
"//include/ports:hdrs",
"//include/utils:base-hdrs",
] + selects.with_or({
# https://github.com/bazelbuild/bazel-skylib/blob/main/docs/selects_doc.md#selectswith_or
("//bazel/common_config_settings:gl_backend", "//bazel/common_config_settings:vulkan_backend"): [
"//include/sksl:hdrs",
"//include/gpu:hdrs",
# TODO(kjlubick) should mock be test only?
"//include/gpu:mock-hdrs",
],
"//conditions:default": [],
})
# Some of these are documented in SkUserConfig.h
CORE_DEFINES = ["SK_HAS_ANDROID_CODEC"] + select({
"//bazel/common_config_settings:debug_build": [
"SK_DEBUG",
],
"//bazel/common_config_settings:release_build": [
"SK_RELEASE",
],
"//conditions:default": [
"SK_RELEASE",
],
}) + select({
"//bazel/common_config_settings:gl_backend": [
"SK_GL",
"SK_SUPPORT_GPU=1",
],
"//bazel/common_config_settings:vulkan_backend": [
"SK_VULKAN",
"SK_SUPPORT_GPU=1",
],
"//conditions:default": [
"SK_SUPPORT_GPU=0",
],
}) + select({
"//bazel/common_config_settings:gl_standard": [
"SK_ASSUME_GL=1",
],
"//bazel/common_config_settings:gles_standard": [
"SK_ASSUME_GL_ES=1",
],
"//bazel/common_config_settings:webgl_standard": [
"SK_ASSUME_WEBGL=1",
"SK_USE_WEBGL",
],
"//conditions:default": [],
}) + select_multi(
{
"//bazel/common_config_settings:gif_codec": ["SK_HAS_WUFFS_LIBRARY"],
"//bazel/common_config_settings:jpeg_codec": ["SK_CODEC_DECODES_JPEG"],
"//bazel/common_config_settings:png_codec": ["SK_CODEC_DECODES_PNG"],
"//bazel/common_config_settings:raw_codec": [
"SK_CODEC_DECODES_RAW",
"SK_CODEC_DECODES_JPEG",
],
"//bazel/common_config_settings:webp_codec": ["SK_CODEC_DECODES_WEBP"],
},
default = [],
)
CORE_DEPS = [] + select_multi(
{
"//bazel/common_config_settings:gif_codec": ["//third_party:wuffs"],
"//bazel/common_config_settings:png_codec": ["//third_party:libpng"],
"//bazel/common_config_settings:raw_codec": [
"//third_party:piex",
"//third_party:dng_sdk",
],
"//bazel/common_config_settings:webp_codec": ["//third_party:libwebp"],
},
default = [],
) + selects.with_or({
# The RAW codec require JPEG, but we cannot list libjpeg-turbo twice in the above list, or
# Bazel gets sad.
("//bazel/common_config_settings:jpeg_codec", "//bazel/common_config_settings:raw_codec"): ["//third_party:libjpeg-turbo"],
"//conditions:default": [],
})
CORE_COPTS = []
cc_library(
name = "skia-core",
srcs = CORE_SRCS,
hdrs = CORE_HDRS,
copts = CORE_COPTS,
local_defines = CORE_DEFINES,
textual_hdrs = ["//src/sksl:txts"],
deps = CORE_DEPS,
)
cc_library(
name = "hash_and_encode",
testonly = True,
srcs = [
"//tools:cmdline",
"//tools:hash_and_encode",
],
deps = [
":skia-core",
"//third_party:libpng",
],
)
cc_library(
name = "gms",
testonly = True,
srcs = [
"//gm:gms",
"//gm:srcs",
"//tools:srcs",
],
hdrs = [
"//gm:hdrs",
],
textual_hdrs = ["//tools:txts"],
deps = [":skia-core"],
)
cc_library(
name = "tests",
testonly = True,
srcs = [
"//tests:srcs",
"//tools:srcs",
],
hdrs = [
"//tests:hdrs",
],
local_defines = [
"GR_TEST_UTILS",
],
textual_hdrs = ["//tools:txts"],
deps = [":skia-core"],
)