skia2/bazel/macros.bzl
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

36 lines
1.3 KiB
Python

# select_multi works around a restriction in native select() that prevents multiple
# keys from being matched unless one is a strict subset of another. For some features,
# we allow multiple of that component to be active. For example, with codecs, we let
# the clients mix and match anywhere from 0 built in codecs to all of them.
#
# select_multi takes a given map and turns it into several distinct select statements
# that have the effect of using any values associated with any active keys.
# For example, if the following parameters are passed in:
# values_map = {
# ":alpha": ["apple", "apricot"],
# ":beta": ["banana"],
# ":gamma": ["grapefruit"],
# },
# default = []
# it will be unrolled into the following select statements
# [] + select({
# ":apple": ["apple", "apricot"],
# "//conditions:default": [],
# }) + select({
# ":beta": ["banana"],
# "//conditions:default": [],
# }) + select({
# ":gamma": ["grapefruit"],
# "//conditions:default": [],
# })
def select_multi(values_map, default):
if len(values_map) == 0:
return default
rv = []
for key, value in values_map.items():
rv += select({
key: value,
"//conditions:default": default,
})
return rv