[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>
This commit is contained in:
Kevin Lubick 2021-11-11 12:50:02 -05:00
parent 08a971126e
commit 8ed49ea6e3
14 changed files with 835 additions and 58 deletions

View File

@ -9,4 +9,5 @@ build:clang --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
# the command line easier.
build --flag_alias=fontmgr=//bazel/common_config_settings:fontmgr
build --flag_alias=gpu_backend=//bazel/common_config_settings:gpu_backend
build --flag_alias=include_codec=//bazel/common_config_settings:include_codec
build --flag_alias=with_gl_standard=//bazel/common_config_settings:with_gl_standard

1
.bazelversion Normal file
View File

@ -0,0 +1 @@
6.0.0-pre.20211025.1

View File

@ -1,7 +1,8 @@
package(default_visibility = ["//:__subpackages__"])
# 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",
@ -65,7 +66,7 @@ CORE_HDRS = [
})
# Some of these are documented in SkUserConfig.h
CORE_DEFINES = select({
CORE_DEFINES = ["SK_HAS_ANDROID_CODEC"] + select({
"//bazel/common_config_settings:debug_build": [
"SK_DEBUG",
],
@ -99,14 +100,48 @@ CORE_DEFINES = select({
"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(

View File

@ -1002,6 +1002,12 @@ optional("heif") {
enabled = skia_use_libheif
public_defines = [ "SK_HAS_HEIF_LIBRARY" ]
# This HEIF decoding functionality is a part of the Android Framework.
# https://android.googlesource.com/platform/frameworks/av/+/master/media/libheif/include/HeifDecoderAPI.h
# There isn't a way to compile that library outside of it, so we just link against
# the library. This feature is not supported on other platforms (and we haven't
# yet tried something like https://github.com/strukturag/libheif/tree/master/libheif).
# The dependency for Android is set in gn_to_bp.py.
deps = []
sources = [ "src/codec/SkHeifCodec.cpp" ]

View File

@ -1,8 +1,8 @@
load(":defs.bzl", "string_flag_with_values")
# @platforms is found at https://github.com/bazelbuild/platforms
package(default_visibility = ["//:__subpackages__"])
load(":defs.bzl", "string_flag_with_values")
config_setting(
name = "linux_x64",
constraint_values = [
@ -75,10 +75,9 @@ config_setting(
# directory. https://docs.bazel.build/versions/main/guide.html#where-are-the-bazelrc-files
#
# TODO(kjlubick) make gpu_backend a multi-string flag when available in Bazel.
# https://docs.bazel.build/versions/main/skylark/config.html#defining-multi-set-string-flags
string_flag_with_values(
flag_name = "gpu_backend",
multiple = True,
values = [
"gl_backend",
"vulkan_backend",
@ -102,3 +101,15 @@ string_flag_with_values(
"custom_directory_fontmgr_factory",
],
)
string_flag_with_values(
flag_name = "include_codec",
multiple = True,
values = [
"gif_codec",
"jpeg_codec",
"png_codec",
"raw_codec",
"webp_codec",
],
)

View File

@ -1,25 +1,61 @@
# https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
# Forked from https://github.com/bazelbuild/bazel-skylib/blob/main/rules/common_settings.bzl
BuildSettingInfo = provider(fields = ["values"])
def _multi_string_impl(ctx):
allowed_values = ctx.attr.values
values = ctx.build_setting_value
for v in values:
if v not in ctx.attr.values:
fail("Error setting " + str(ctx.label) + ": invalid value '" + v + "'. Allowed values are " + str(allowed_values))
return BuildSettingInfo(values = values)
multi_string_flag = rule(
implementation = _multi_string_impl,
build_setting = config.string(flag = True, allow_multiple = True),
attrs = {
"values": attr.string_list(
doc = "The list of allowed values for this setting. An error is raised if any other values are given.",
),
},
doc = "A string-typed build setting that can be set multiple times on the command line",
)
# string_flag_with_values is a Bazel Macro that defines a flag with the given name and a set
# of valid values for that flag. For each value, a config_setting is defined with the name
# of the value, associated with the created flag.
# This is defined to make the BUILD.bazel file easier to read w/o the boilerplate of defining
# a string_flag rule and n config_settings
# https://docs.bazel.build/versions/main/skylark/macros.html
def string_flag_with_values(flag_name, values, default = ""):
string_flag(
name = flag_name,
# We have to specify a default value, even if that value is empty string.
# https://docs.bazel.build/versions/main/skylark/config.html#instantiating-build-settings
build_setting_default = default,
# If empty string is the default, we need to make sure it is in the list
# of acceptable values. If the default is not empty string, we don't want
# to make empty string a valid value. Having duplicate values in the list
# does not cause any issues, so we can just add the default to achieve
# this affect.
values = values + [default],
)
def string_flag_with_values(flag_name, values, default = "", multiple = False):
if multiple:
multi_string_flag(
name = flag_name,
# We have to specify a default value, even if that value is empty string.
# https://docs.bazel.build/versions/main/skylark/config.html#instantiating-build-settings
build_setting_default = default,
# If empty string is the default, we need to make sure it is in the list
# of acceptable values. If the default is not empty string, we don't want
# to make empty string a valid value. Having duplicate values in the list
# does not cause any issues, so we can just add the default to achieve
# this affect.
values = values + [default],
)
else:
string_flag(
name = flag_name,
# We have to specify a default value, even if that value is empty string.
# https://docs.bazel.build/versions/main/skylark/config.html#instantiating-build-settings
build_setting_default = default,
# If empty string is the default, we need to make sure it is in the list
# of acceptable values. If the default is not empty string, we don't want
# to make empty string a valid value. Having duplicate values in the list
# does not cause any issues, so we can just add the default to achieve
# this affect.
values = values + [default],
)
# For each of the values given, we define a config_setting. This allows us to use
# select statements, on the given setting, e.g. referencing

35
bazel/macros.bzl Normal file
View File

@ -0,0 +1,35 @@
# 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

View File

@ -1,8 +1,8 @@
package(default_visibility = ["//visibility:private"])
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
package(default_visibility = ["//visibility:private"])
filegroup(
name = "core-hdrs",
srcs = [

View File

@ -1,8 +1,8 @@
package(default_visibility = ["//:__subpackages__"])
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
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

View File

@ -122,15 +122,6 @@ typecheck:
echo "Make sure you've run cd npm_build && npm ci recently"
cd npm_build && npm run dtslint
bazel_gms_sandboxed:
# Because emscripten does a lot of extra work, we need to limit the number of jobs or it
# can overwhelm even a powerful build system.
bazel build :gm-bindings-wasm --compilation_mode opt --cpu=wasm --jobs 8
- rm -rf build/
mkdir build
cp ../../bazel-bin/modules/canvaskit/gm-bindings-wasm/gm-bindings.js build/gm-bindings.js
cp ../../bazel-bin/modules/canvaskit/gm-bindings-wasm/gm-bindings.wasm build/gm-bindings.wasm
bazel_gms_release:
# We use spawn_strategy=local for "everyday" builds because emscripten assumes there
# is a cache in the home directory that it needs to fill with compiled versions of libc etc.
@ -139,8 +130,10 @@ bazel_gms_release:
# unit, by letting the cache be used (and not dropped from the sandbox), which gets expensive.
# Local testing showed using the local strategy sped up a clean build from 9.5 minutes
# to 1 minute. https://docs.bazel.build/versions/main/user-manual.html#strategy-options
bazel build :gm-bindings-wasm --compilation_mode opt --spawn_strategy=local \
--gpu_backend=gl_backend --with_gl_standard=webgl_standard
bazelisk build :gm-bindings-wasm --compilation_mode opt --spawn_strategy=local \
--gpu_backend=gl_backend --with_gl_standard=webgl_standard \
--included_codec=jpeg_codec --included_codec=png_codec --include_codec=webp_codec \
--include_codec=gif_codec
- rm -rf build/
mkdir build
cp ../../bazel-bin/modules/canvaskit/gm-bindings-wasm/gm-bindings.js build/gm-bindings.js
@ -148,8 +141,10 @@ bazel_gms_release:
bazel_gms_debug:
# See above note about spawn_strategy
bazel build :gm-bindings-wasm --compilation_mode dbg --spawn_strategy=local \
--gpu_backend=gl_backend --with_gl_standard=webgl_standard
bazelisk build :gm-bindings-wasm --compilation_mode dbg --spawn_strategy=local \
--gpu_backend=gl_backend --with_gl_standard=webgl_standard \
--include_codec=jpeg_codec --include_codec=png_codec --include_codec=webp_codec \
--include_codec=gif_codec
- rm -rf build/
mkdir build
cp ../../bazel-bin/modules/canvaskit/gm-bindings-wasm/gm-bindings.js build/gm-bindings.js

View File

@ -1,5 +1,38 @@
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:macros.bzl", "select_multi")
package(default_visibility = ["//visibility:private"])
filegroup(
name = "androidcodec-srcs",
srcs = [
"SkAndroidCodec.cpp",
"SkAndroidCodecAdapter.cpp",
"SkAndroidCodecAdapter.h",
"SkSampledCodec.cpp",
"SkSampledCodec.h",
],
)
filegroup(
name = "bmp-srcs",
srcs = [
"SkBmpBaseCodec.cpp",
"SkBmpBaseCodec.h",
"SkBmpCodec.cpp",
"SkBmpCodec.h",
"SkBmpMaskCodec.cpp",
"SkBmpMaskCodec.h",
"SkBmpRLECodec.cpp",
"SkBmpRLECodec.h",
"SkBmpStandardCodec.cpp",
"SkBmpStandardCodec.h",
"SkWbmpCodec.cpp",
"SkWbmpCodec.h",
],
)
filegroup(
name = "core-srcs",
srcs = [
@ -22,30 +55,81 @@ filegroup(
)
filegroup(
name = "bmp-srcs",
name = "gif-srcs",
srcs = [
"SkBmpBaseCodec.cpp",
"SkBmpBaseCodec.h",
"SkBmpCodec.cpp",
"SkBmpCodec.h",
"SkBmpMaskCodec.cpp",
"SkBmpMaskCodec.h",
"SkBmpRLECodec.cpp",
"SkBmpRLECodec.h",
"SkBmpStandardCodec.cpp",
"SkBmpStandardCodec.h",
"SkWbmpCodec.cpp",
"SkWbmpCodec.h",
"SkScalingCodec.h",
"SkWuffsCodec.cpp",
"SkWuffsCodec.h",
],
)
# TODO(kjlubick) add selects here to allow opting in or out of various codecs.
filegroup(
name = "jpeg-srcs",
srcs = [
"SkEncodedInfo.cpp",
"SkJpegCodec.cpp",
"SkJpegCodec.h",
"SkJpegDecoderMgr.cpp",
"SkJpegDecoderMgr.h",
"SkJpegPriv.h",
"SkJpegUtility.cpp",
"SkJpegUtility.h",
"SkParseEncodedOrigin.cpp",
"SkParseEncodedOrigin.h",
],
)
filegroup(
name = "png-srcs",
srcs = [
"SkEncodedInfo.cpp",
"SkIcoCodec.cpp",
"SkIcoCodec.h",
"SkPngCodec.cpp",
"SkPngCodec.h",
"SkPngPriv.h",
],
)
filegroup(
name = "raw-srcs",
srcs = [
"SkRawCodec.cpp",
"SkRawCodec.h",
],
)
filegroup(
name = "webp-srcs",
srcs = [
"SkEncodedInfo.cpp",
"SkParseEncodedOrigin.cpp",
"SkParseEncodedOrigin.h",
"SkScalingCodec.h",
"SkWebpCodec.cpp",
"SkWebpCodec.h",
],
)
filegroup(
name = "srcs",
srcs = [
":androidcodec-srcs",
":bmp-srcs",
":core-srcs",
],
] + select_multi(
{
"//bazel/common_config_settings:gif_codec": [":gif-srcs"],
"//bazel/common_config_settings:png_codec": [":png-srcs"],
"//bazel/common_config_settings:raw_codec": [":raw-srcs"],
"//bazel/common_config_settings:webp_codec": [":webp-srcs"],
},
default = [],
) + selects.with_or({
# The RAW codec depends on JPEG, but we cannot list jpeg twice in the above list, or
# Bazel gets sad.
("//bazel/common_config_settings:jpeg_codec", "//bazel/common_config_settings:raw_codec"): [":jpeg-srcs"],
"//conditions:default": [],
}),
visibility = ["//:__subpackages__"],
)

View File

@ -1,8 +1,8 @@
package(default_visibility = ["//visibility:private"])
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
package(default_visibility = ["//visibility:private"])
filegroup(
name = "core-srcs",
srcs = [

View File

@ -1,8 +1,8 @@
package(default_visibility = ["//visibility:private"])
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
package(default_visibility = ["//visibility:private"])
filegroup(
name = "core-srcs",
srcs = [

View File

@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
package(default_visibility = ["//:__subpackages__"])
@ -208,3 +209,575 @@ cc_library(
"musl_compat/locale.c",
],
)
JPEGTURBO_SRCS = [
"externals/libjpeg-turbo/jaricom.c",
"externals/libjpeg-turbo/jcapimin.c",
"externals/libjpeg-turbo/jcapistd.c",
"externals/libjpeg-turbo/jcarith.c",
"externals/libjpeg-turbo/jccoefct.c",
"externals/libjpeg-turbo/jccolor.c",
"externals/libjpeg-turbo/jcdctmgr.c",
"externals/libjpeg-turbo/jchuff.c",
"externals/libjpeg-turbo/jchuff.h",
"externals/libjpeg-turbo/jcinit.c",
"externals/libjpeg-turbo/jcmainct.c",
"externals/libjpeg-turbo/jcmarker.c",
"externals/libjpeg-turbo/jcmaster.c",
"externals/libjpeg-turbo/jcomapi.c",
"externals/libjpeg-turbo/jconfigint.h",
"externals/libjpeg-turbo/jcparam.c",
"externals/libjpeg-turbo/jcphuff.c",
"externals/libjpeg-turbo/jcprepct.c",
"externals/libjpeg-turbo/jcsample.c",
"externals/libjpeg-turbo/jdapimin.c",
"externals/libjpeg-turbo/jdapistd.c",
"externals/libjpeg-turbo/jdarith.c",
"externals/libjpeg-turbo/jdcoefct.c",
"externals/libjpeg-turbo/jdcoefct.h",
"externals/libjpeg-turbo/jdcolor.c",
"externals/libjpeg-turbo/jdct.h",
"externals/libjpeg-turbo/jddctmgr.c",
"externals/libjpeg-turbo/jdhuff.c",
"externals/libjpeg-turbo/jdhuff.h",
"externals/libjpeg-turbo/jdinput.c",
"externals/libjpeg-turbo/jdmainct.c",
"externals/libjpeg-turbo/jdmainct.h",
"externals/libjpeg-turbo/jdmarker.c",
"externals/libjpeg-turbo/jdmaster.c",
"externals/libjpeg-turbo/jdmaster.h",
"externals/libjpeg-turbo/jdmerge.c",
"externals/libjpeg-turbo/jdmerge.h",
"externals/libjpeg-turbo/jdphuff.c",
"externals/libjpeg-turbo/jdpostct.c",
"externals/libjpeg-turbo/jdsample.c",
"externals/libjpeg-turbo/jdsample.h",
"externals/libjpeg-turbo/jerror.c",
"externals/libjpeg-turbo/jfdctflt.c",
"externals/libjpeg-turbo/jfdctfst.c",
"externals/libjpeg-turbo/jfdctint.c",
"externals/libjpeg-turbo/jidctflt.c",
"externals/libjpeg-turbo/jidctfst.c",
"externals/libjpeg-turbo/jidctint.c",
"externals/libjpeg-turbo/jidctred.c",
"externals/libjpeg-turbo/jinclude.h",
"externals/libjpeg-turbo/jmemmgr.c",
"externals/libjpeg-turbo/jmemnobs.c",
"externals/libjpeg-turbo/jmemsys.h",
"externals/libjpeg-turbo/jpeg_nbits_table.c",
"externals/libjpeg-turbo/jpeg_nbits_table.h",
"externals/libjpeg-turbo/jpegcomp.h",
"externals/libjpeg-turbo/jpegint.h",
"externals/libjpeg-turbo/jquant1.c",
"externals/libjpeg-turbo/jquant2.c",
"externals/libjpeg-turbo/jsimd.h",
"externals/libjpeg-turbo/jsimddct.h",
"externals/libjpeg-turbo/jutils.c",
"externals/libjpeg-turbo/jversion.h",
] + selects.with_or({
("@platforms//cpu:arm", "@platforms//cpu:arm64"): [
"externals/libjpeg-turbo/simd/arm/jccolor-neon.c",
"externals/libjpeg-turbo/simd/arm/jcgray-neon.c",
"externals/libjpeg-turbo/simd/arm/jcphuff-neon.c",
"externals/libjpeg-turbo/simd/arm/jcsample-neon.c",
"externals/libjpeg-turbo/simd/arm/jdcolor-neon.c",
"externals/libjpeg-turbo/simd/arm/jdmerge-neon.c",
"externals/libjpeg-turbo/simd/arm/jdsample-neon.c",
"externals/libjpeg-turbo/simd/arm/jfdctfst-neon.c",
"externals/libjpeg-turbo/simd/arm/jfdctint-neon.c",
"externals/libjpeg-turbo/simd/arm/jidctfst-neon.c",
"externals/libjpeg-turbo/simd/arm/jidctint-neon.c",
"externals/libjpeg-turbo/simd/arm/jidctred-neon.c",
"externals/libjpeg-turbo/simd/arm/jquanti-neon.c",
],
"//conditions:default": ["externals/libjpeg-turbo/jsimd_none.c"],
}) + select({
"@platforms//cpu:arm": [
"externals/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c",
"externals/libjpeg-turbo/simd/arm/aarch32/jsimd.c",
],
"@platforms//cpu:arm64": [
"externals/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c",
"externals/libjpeg-turbo/simd/arm/aarch64/jsimd.c",
],
"//conditions:default": [],
})
JPEGTURBO_DEFINES = [
# Add support for arithmetic encoding (C_) and decoding (D_).
# This matches Android. Note that such JPEGs are likely rare, given lack of
# support by major browsers.
"C_ARITH_CODING_SUPPORTED=1",
"D_ARITH_CODING_SUPPORTED=1",
] + selects.with_or({
("@platforms//cpu:arm", "@platforms//cpu:arm64"): ["NEON_INTRINSICS"],
"//conditions:default": [],
}) + select({
"@platforms//os:windows": [],
"//conditions:default": ["USE_CLZ_INTRINSIC"], # Cuts a 64K table.
})
cc_library(
name = "libjpeg-turbo",
srcs = JPEGTURBO_SRCS,
hdrs = [
"externals/libjpeg-turbo/jconfig.h",
"externals/libjpeg-turbo/jerror.h",
"externals/libjpeg-turbo/jmorecfg.h",
"externals/libjpeg-turbo/jpeglib.h",
"externals/libjpeg-turbo/jpeglibmangler.h",
],
local_defines = JPEGTURBO_DEFINES,
strip_include_prefix = "externals/libjpeg-turbo/",
textual_hdrs = [
"externals/libjpeg-turbo/jccolext.c",
"externals/libjpeg-turbo/jdmrgext.c",
"externals/libjpeg-turbo/jdcolext.c",
"externals/libjpeg-turbo/jdcol565.c",
"externals/libjpeg-turbo/jdmrg565.c",
"externals/libjpeg-turbo/jstdhuff.c",
],
)
WEBP_SRCS = [
"externals/libwebp/src/dec/alpha_dec.c",
"externals/libwebp/src/dec/alphai_dec.h",
"externals/libwebp/src/dec/buffer_dec.c",
"externals/libwebp/src/dec/common_dec.h",
"externals/libwebp/src/dec/frame_dec.c",
"externals/libwebp/src/dec/idec_dec.c",
"externals/libwebp/src/dec/io_dec.c",
"externals/libwebp/src/dec/quant_dec.c",
"externals/libwebp/src/dec/tree_dec.c",
"externals/libwebp/src/dec/vp8_dec.c",
"externals/libwebp/src/dec/vp8_dec.h",
"externals/libwebp/src/dec/vp8i_dec.h",
"externals/libwebp/src/dec/vp8l_dec.c",
"externals/libwebp/src/dec/vp8li_dec.h",
"externals/libwebp/src/dec/webp_dec.c",
"externals/libwebp/src/dec/webpi_dec.h",
"externals/libwebp/src/demux/anim_decode.c",
"externals/libwebp/src/demux/demux.c",
"externals/libwebp/src/dsp/alpha_processing.c",
"externals/libwebp/src/dsp/alpha_processing_mips_dsp_r2.c",
"externals/libwebp/src/dsp/alpha_processing_neon.c",
"externals/libwebp/src/dsp/alpha_processing_sse2.c",
"externals/libwebp/src/dsp/common_sse2.h",
"externals/libwebp/src/dsp/common_sse41.h",
"externals/libwebp/src/dsp/cost.c",
"externals/libwebp/src/dsp/cost_mips32.c",
"externals/libwebp/src/dsp/cost_mips_dsp_r2.c",
"externals/libwebp/src/dsp/cost_neon.c",
"externals/libwebp/src/dsp/cost_sse2.c",
"externals/libwebp/src/dsp/cpu.c",
"externals/libwebp/src/dsp/dec.c",
"externals/libwebp/src/dsp/dec_clip_tables.c",
"externals/libwebp/src/dsp/dec_mips32.c",
"externals/libwebp/src/dsp/dec_mips_dsp_r2.c",
"externals/libwebp/src/dsp/dec_msa.c",
"externals/libwebp/src/dsp/dec_neon.c",
"externals/libwebp/src/dsp/dec_sse2.c",
"externals/libwebp/src/dsp/dsp.h",
"externals/libwebp/src/dsp/enc.c",
"externals/libwebp/src/dsp/enc_mips32.c",
"externals/libwebp/src/dsp/enc_mips_dsp_r2.c",
"externals/libwebp/src/dsp/enc_msa.c",
"externals/libwebp/src/dsp/enc_neon.c",
"externals/libwebp/src/dsp/enc_sse2.c",
"externals/libwebp/src/dsp/filters.c",
"externals/libwebp/src/dsp/filters_mips_dsp_r2.c",
"externals/libwebp/src/dsp/filters_msa.c",
"externals/libwebp/src/dsp/filters_neon.c",
"externals/libwebp/src/dsp/filters_sse2.c",
"externals/libwebp/src/dsp/lossless.c",
"externals/libwebp/src/dsp/lossless.h",
"externals/libwebp/src/dsp/lossless_common.h",
"externals/libwebp/src/dsp/lossless_enc.c",
"externals/libwebp/src/dsp/lossless_enc_mips32.c",
"externals/libwebp/src/dsp/lossless_enc_mips_dsp_r2.c",
"externals/libwebp/src/dsp/lossless_enc_msa.c",
"externals/libwebp/src/dsp/lossless_enc_neon.c",
"externals/libwebp/src/dsp/lossless_enc_sse2.c",
"externals/libwebp/src/dsp/lossless_mips_dsp_r2.c",
"externals/libwebp/src/dsp/lossless_msa.c",
"externals/libwebp/src/dsp/lossless_neon.c",
"externals/libwebp/src/dsp/lossless_sse2.c",
"externals/libwebp/src/dsp/mips_macro.h",
"externals/libwebp/src/dsp/msa_macro.h",
"externals/libwebp/src/dsp/neon.h",
"externals/libwebp/src/dsp/quant.h",
"externals/libwebp/src/dsp/rescaler.c",
"externals/libwebp/src/dsp/rescaler_mips32.c",
"externals/libwebp/src/dsp/rescaler_mips_dsp_r2.c",
"externals/libwebp/src/dsp/rescaler_msa.c",
"externals/libwebp/src/dsp/rescaler_neon.c",
"externals/libwebp/src/dsp/rescaler_sse2.c",
"externals/libwebp/src/dsp/ssim.c",
"externals/libwebp/src/dsp/ssim_sse2.c",
"externals/libwebp/src/dsp/upsampling.c",
"externals/libwebp/src/dsp/upsampling_mips_dsp_r2.c",
"externals/libwebp/src/dsp/upsampling_msa.c",
"externals/libwebp/src/dsp/upsampling_neon.c",
"externals/libwebp/src/dsp/upsampling_sse2.c",
"externals/libwebp/src/dsp/yuv.c",
"externals/libwebp/src/dsp/yuv.h",
"externals/libwebp/src/dsp/yuv_mips32.c",
"externals/libwebp/src/dsp/yuv_mips_dsp_r2.c",
"externals/libwebp/src/dsp/yuv_neon.c",
"externals/libwebp/src/dsp/yuv_sse2.c",
"externals/libwebp/src/enc/alpha_enc.c",
"externals/libwebp/src/enc/analysis_enc.c",
"externals/libwebp/src/enc/backward_references_cost_enc.c",
"externals/libwebp/src/enc/backward_references_enc.c",
"externals/libwebp/src/enc/backward_references_enc.h",
"externals/libwebp/src/enc/config_enc.c",
"externals/libwebp/src/enc/cost_enc.c",
"externals/libwebp/src/enc/cost_enc.h",
"externals/libwebp/src/enc/filter_enc.c",
"externals/libwebp/src/enc/frame_enc.c",
"externals/libwebp/src/enc/histogram_enc.c",
"externals/libwebp/src/enc/histogram_enc.h",
"externals/libwebp/src/enc/iterator_enc.c",
"externals/libwebp/src/enc/near_lossless_enc.c",
"externals/libwebp/src/enc/picture_csp_enc.c",
"externals/libwebp/src/enc/picture_enc.c",
"externals/libwebp/src/enc/picture_psnr_enc.c",
"externals/libwebp/src/enc/picture_rescale_enc.c",
"externals/libwebp/src/enc/picture_tools_enc.c",
"externals/libwebp/src/enc/predictor_enc.c",
"externals/libwebp/src/enc/quant_enc.c",
"externals/libwebp/src/enc/syntax_enc.c",
"externals/libwebp/src/enc/token_enc.c",
"externals/libwebp/src/enc/tree_enc.c",
"externals/libwebp/src/enc/vp8i_enc.h",
"externals/libwebp/src/enc/vp8l_enc.c",
"externals/libwebp/src/enc/vp8li_enc.h",
"externals/libwebp/src/enc/webp_enc.c",
"externals/libwebp/src/mux/anim_encode.c",
"externals/libwebp/src/mux/animi.h",
"externals/libwebp/src/mux/muxedit.c",
"externals/libwebp/src/mux/muxi.h",
"externals/libwebp/src/mux/muxinternal.c",
"externals/libwebp/src/mux/muxread.c",
"externals/libwebp/src/utils/bit_reader_inl_utils.h",
"externals/libwebp/src/utils/bit_reader_utils.c",
"externals/libwebp/src/utils/bit_reader_utils.h",
"externals/libwebp/src/utils/bit_writer_utils.c",
"externals/libwebp/src/utils/bit_writer_utils.h",
"externals/libwebp/src/utils/color_cache_utils.c",
"externals/libwebp/src/utils/color_cache_utils.h",
"externals/libwebp/src/utils/endian_inl_utils.h",
"externals/libwebp/src/utils/filters_utils.c",
"externals/libwebp/src/utils/filters_utils.h",
"externals/libwebp/src/utils/huffman_encode_utils.c",
"externals/libwebp/src/utils/huffman_encode_utils.h",
"externals/libwebp/src/utils/huffman_utils.c",
"externals/libwebp/src/utils/huffman_utils.h",
"externals/libwebp/src/utils/quant_levels_dec_utils.c",
"externals/libwebp/src/utils/quant_levels_dec_utils.h",
"externals/libwebp/src/utils/quant_levels_utils.c",
"externals/libwebp/src/utils/quant_levels_utils.h",
"externals/libwebp/src/utils/random_utils.c",
"externals/libwebp/src/utils/random_utils.h",
"externals/libwebp/src/utils/rescaler_utils.c",
"externals/libwebp/src/utils/rescaler_utils.h",
"externals/libwebp/src/utils/thread_utils.c",
"externals/libwebp/src/utils/thread_utils.h",
"externals/libwebp/src/utils/utils.c",
"externals/libwebp/src/utils/utils.h",
] + select({
"@platforms//cpu:x86_64": [
"externals/libwebp/src/dsp/alpha_processing_sse41.c",
"externals/libwebp/src/dsp/dec_sse41.c",
"externals/libwebp/src/dsp/enc_sse41.c",
"externals/libwebp/src/dsp/lossless_enc_sse41.c",
"externals/libwebp/src/dsp/lossless_sse41.c",
"externals/libwebp/src/dsp/upsampling_sse41.c",
"externals/libwebp/src/dsp/yuv_sse41.c",
],
"//bazel/common_config_settings:cpu_wasm": [], # not sure why wasm doesn't use default
"//conditions:default": [],
})
WEBP_COPTS = [
"-isystem third_party/externals/libwebp/",
] + select({
"@platforms//cpu:x86_64": ["-msse4.1"],
"//bazel/common_config_settings:cpu_wasm": [], # not sure why wasm doesn't use default
"//conditions:default": [],
})
WEBP_DEFINES = [
# TODO(scroggo): swizzle ourself in SkWebpCodec instead of requiring this non-standard libwebp.
"WEBP_SWAP_16BIT_CSP",
]
cc_library(
name = "libwebp",
srcs = WEBP_SRCS,
hdrs = [
"externals/libwebp/src/webp/decode.h",
"externals/libwebp/src/webp/demux.h",
"externals/libwebp/src/webp/encode.h",
"externals/libwebp/src/webp/format_constants.h",
"externals/libwebp/src/webp/mux.h",
"externals/libwebp/src/webp/mux_types.h",
"externals/libwebp/src/webp/types.h",
],
copts = WEBP_COPTS,
local_defines = WEBP_DEFINES,
strip_include_prefix = "externals/libwebp/src/",
)
cc_library(
name = "wuffs",
# We list this file both as a source file and a header file because it will be
# compiled for symbols *and* included as a header file.
srcs = ["externals/wuffs/release/c/wuffs-v0.3.c"],
# Thankfully, bazel doesn't mind a .c file being declared as a public "header".
hdrs = ["externals/wuffs/release/c/wuffs-v0.3.c"],
local_defines = [
# Copy/pasting from "externals/wuffs/release/c/wuffs-*.c":
#
# ----
#
# Wuffs ships as a "single file C library" or "header file library" as per
# https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
#
# To use that single file as a "foo.c"-like implementation, instead of a
# "foo.h"-like header, #define WUFFS_IMPLEMENTATION before #include'ing or
# compiling it.
#
# ----
"WUFFS_IMPLEMENTATION",
# Continuing to copy/paste:
#
# ----
#
# Defining the WUFFS_CONFIG__MODULE* macros are optional, but it lets users
# of Wuffs' .c file specify which parts of Wuffs to build. That file
# contains the entire Wuffs standard library, implementing a variety of
# codecs and file formats. Without this macro definition, an optimizing
# compiler or linker may very well discard Wuffs code for unused codecs,
# but listing the Wuffs modules we use makes that process explicit.
# Preprocessing means that such code simply isn't compiled.
#
# ----
#
# For Skia, we're only interested in particular image codes (e.g. GIF) and
# their dependencies (e.g. BASE, LZW).
"WUFFS_CONFIG__MODULES",
"WUFFS_CONFIG__MODULE__BASE",
"WUFFS_CONFIG__MODULE__GIF",
"WUFFS_CONFIG__MODULE__LZW",
],
strip_include_prefix = "externals/wuffs/release/c/",
)
cc_library(
name = "piex",
srcs = [
"externals/piex/src/binary_parse/cached_paged_byte_array.cc",
"externals/piex/src/binary_parse/cached_paged_byte_array.h",
"externals/piex/src/binary_parse/range_checked_byte_ptr.cc",
"externals/piex/src/binary_parse/range_checked_byte_ptr.h",
"externals/piex/src/image_type_recognition/image_type_recognition_lite.cc",
"externals/piex/src/image_type_recognition/image_type_recognition_lite.h",
"externals/piex/src/piex.cc",
"externals/piex/src/tiff_directory/tiff_directory.cc",
"externals/piex/src/tiff_directory/tiff_directory.h",
"externals/piex/src/tiff_parser.cc",
"externals/piex/src/tiff_parser.h",
],
hdrs = [
"externals/piex/src/piex.h",
"externals/piex/src/piex_types.h",
],
copts = [
"-isystem third_party/externals/piex/",
],
local_defines = ["BREAK_IF_DEBUGGING_AND_OUT_OF_RANGE"],
strip_include_prefix = "externals/piex/",
)
cc_library(
name = "dng_sdk",
srcs = [
"externals/dng_sdk/source/dng_1d_function.cpp",
"externals/dng_sdk/source/dng_1d_table.cpp",
"externals/dng_sdk/source/dng_abort_sniffer.cpp",
"externals/dng_sdk/source/dng_area_task.cpp",
"externals/dng_sdk/source/dng_bad_pixels.cpp",
"externals/dng_sdk/source/dng_bottlenecks.cpp",
"externals/dng_sdk/source/dng_camera_profile.cpp",
"externals/dng_sdk/source/dng_color_space.cpp",
"externals/dng_sdk/source/dng_color_spec.cpp",
"externals/dng_sdk/source/dng_date_time.cpp",
"externals/dng_sdk/source/dng_exceptions.cpp",
"externals/dng_sdk/source/dng_exif.cpp",
"externals/dng_sdk/source/dng_file_stream.cpp",
"externals/dng_sdk/source/dng_filter_task.cpp",
"externals/dng_sdk/source/dng_fingerprint.cpp",
"externals/dng_sdk/source/dng_gain_map.cpp",
"externals/dng_sdk/source/dng_globals.cpp",
"externals/dng_sdk/source/dng_host.cpp",
"externals/dng_sdk/source/dng_hue_sat_map.cpp",
"externals/dng_sdk/source/dng_ifd.cpp",
"externals/dng_sdk/source/dng_image.cpp",
"externals/dng_sdk/source/dng_image_writer.cpp",
"externals/dng_sdk/source/dng_info.cpp",
"externals/dng_sdk/source/dng_iptc.cpp",
"externals/dng_sdk/source/dng_jpeg_image.cpp",
"externals/dng_sdk/source/dng_jpeg_memory_source.cpp",
"externals/dng_sdk/source/dng_lens_correction.cpp",
"externals/dng_sdk/source/dng_linearization_info.cpp",
"externals/dng_sdk/source/dng_lossless_jpeg.cpp",
"externals/dng_sdk/source/dng_matrix.cpp",
"externals/dng_sdk/source/dng_memory.cpp",
"externals/dng_sdk/source/dng_memory_stream.cpp",
"externals/dng_sdk/source/dng_misc_opcodes.cpp",
"externals/dng_sdk/source/dng_mosaic_info.cpp",
"externals/dng_sdk/source/dng_mutex.cpp",
"externals/dng_sdk/source/dng_negative.cpp",
"externals/dng_sdk/source/dng_opcode_list.cpp",
"externals/dng_sdk/source/dng_opcodes.cpp",
"externals/dng_sdk/source/dng_orientation.cpp",
"externals/dng_sdk/source/dng_parse_utils.cpp",
"externals/dng_sdk/source/dng_pixel_buffer.cpp",
"externals/dng_sdk/source/dng_point.cpp",
"externals/dng_sdk/source/dng_preview.cpp",
"externals/dng_sdk/source/dng_pthread.cpp",
"externals/dng_sdk/source/dng_rational.cpp",
"externals/dng_sdk/source/dng_read_image.cpp",
"externals/dng_sdk/source/dng_rect.cpp",
"externals/dng_sdk/source/dng_ref_counted_block.cpp",
"externals/dng_sdk/source/dng_reference.cpp",
"externals/dng_sdk/source/dng_render.cpp",
"externals/dng_sdk/source/dng_resample.cpp",
"externals/dng_sdk/source/dng_safe_arithmetic.cpp",
"externals/dng_sdk/source/dng_shared.cpp",
"externals/dng_sdk/source/dng_simple_image.cpp",
"externals/dng_sdk/source/dng_spline.cpp",
"externals/dng_sdk/source/dng_stream.cpp",
"externals/dng_sdk/source/dng_string.cpp",
"externals/dng_sdk/source/dng_string_list.cpp",
"externals/dng_sdk/source/dng_tag_types.cpp",
"externals/dng_sdk/source/dng_temperature.cpp",
"externals/dng_sdk/source/dng_tile_iterator.cpp",
"externals/dng_sdk/source/dng_tone_curve.cpp",
"externals/dng_sdk/source/dng_utils.cpp",
"externals/dng_sdk/source/dng_xy_coord.cpp",
],
hdrs = [
"externals/dng_sdk/source/RawEnvironment.h",
"externals/dng_sdk/source/dng_1d_function.h",
"externals/dng_sdk/source/dng_1d_table.h",
"externals/dng_sdk/source/dng_abort_sniffer.h",
"externals/dng_sdk/source/dng_area_task.h",
"externals/dng_sdk/source/dng_assertions.h",
"externals/dng_sdk/source/dng_auto_ptr.h",
"externals/dng_sdk/source/dng_bad_pixels.h",
"externals/dng_sdk/source/dng_bottlenecks.h",
"externals/dng_sdk/source/dng_camera_profile.h",
"externals/dng_sdk/source/dng_classes.h",
"externals/dng_sdk/source/dng_color_space.h",
"externals/dng_sdk/source/dng_color_spec.h",
"externals/dng_sdk/source/dng_date_time.h",
"externals/dng_sdk/source/dng_errors.h",
"externals/dng_sdk/source/dng_exceptions.h",
"externals/dng_sdk/source/dng_exif.h",
"externals/dng_sdk/source/dng_fast_module.h",
"externals/dng_sdk/source/dng_file_stream.h",
"externals/dng_sdk/source/dng_filter_task.h",
"externals/dng_sdk/source/dng_fingerprint.h",
"externals/dng_sdk/source/dng_flags.h",
"externals/dng_sdk/source/dng_gain_map.h",
"externals/dng_sdk/source/dng_globals.h",
"externals/dng_sdk/source/dng_host.h",
"externals/dng_sdk/source/dng_hue_sat_map.h",
"externals/dng_sdk/source/dng_ifd.h",
"externals/dng_sdk/source/dng_image.h",
"externals/dng_sdk/source/dng_image_writer.h",
"externals/dng_sdk/source/dng_info.h",
"externals/dng_sdk/source/dng_iptc.h",
"externals/dng_sdk/source/dng_jpeg_image.h",
"externals/dng_sdk/source/dng_jpeg_memory_source.h",
"externals/dng_sdk/source/dng_jpeglib.h",
"externals/dng_sdk/source/dng_lens_correction.h",
"externals/dng_sdk/source/dng_linearization_info.h",
"externals/dng_sdk/source/dng_lossless_jpeg.h",
"externals/dng_sdk/source/dng_matrix.h",
"externals/dng_sdk/source/dng_memory.h",
"externals/dng_sdk/source/dng_memory_stream.h",
"externals/dng_sdk/source/dng_misc_opcodes.h",
"externals/dng_sdk/source/dng_mosaic_info.h",
"externals/dng_sdk/source/dng_mutex.h",
"externals/dng_sdk/source/dng_negative.h",
"externals/dng_sdk/source/dng_opcode_list.h",
"externals/dng_sdk/source/dng_opcodes.h",
"externals/dng_sdk/source/dng_orientation.h",
"externals/dng_sdk/source/dng_parse_utils.h",
"externals/dng_sdk/source/dng_pixel_buffer.h",
"externals/dng_sdk/source/dng_point.h",
"externals/dng_sdk/source/dng_preview.h",
"externals/dng_sdk/source/dng_pthread.h",
"externals/dng_sdk/source/dng_rational.h",
"externals/dng_sdk/source/dng_read_image.h",
"externals/dng_sdk/source/dng_rect.h",
"externals/dng_sdk/source/dng_ref_counted_block.h",
"externals/dng_sdk/source/dng_reference.h",
"externals/dng_sdk/source/dng_render.h",
"externals/dng_sdk/source/dng_resample.h",
"externals/dng_sdk/source/dng_safe_arithmetic.h",
"externals/dng_sdk/source/dng_sdk_limits.h",
"externals/dng_sdk/source/dng_shared.h",
"externals/dng_sdk/source/dng_simple_image.h",
"externals/dng_sdk/source/dng_spline.h",
"externals/dng_sdk/source/dng_stream.h",
"externals/dng_sdk/source/dng_string.h",
"externals/dng_sdk/source/dng_string_list.h",
"externals/dng_sdk/source/dng_tag_codes.h",
"externals/dng_sdk/source/dng_tag_types.h",
"externals/dng_sdk/source/dng_tag_values.h",
"externals/dng_sdk/source/dng_temperature.h",
"externals/dng_sdk/source/dng_tile_iterator.h",
"externals/dng_sdk/source/dng_tone_curve.h",
"externals/dng_sdk/source/dng_types.h",
"externals/dng_sdk/source/dng_uncopyable.h",
"externals/dng_sdk/source/dng_utils.h",
"externals/dng_sdk/source/dng_xy_coord.h",
],
copts = [
"-isystem third_party/externals/dng_sdk/source/",
],
defines = [
"qDNGBigEndian=0", # The GN rules had this defined publicly
] + selects.with_or({
("@platforms//cpu:x86_64", "@platforms//cpu:arm"): [
# DNG SDK uses __builtin_smulll_overflow() to detect 64x64 bit multiply overflow.
# On some platforms, the compiler implements this with __mulodi4().
# I can't quite figure out how to link that here, so instead here's a shim for
# __builtin_smulll_overflow() that multiplies normally assuming no overflow.
# Previously tracked in b/29412086.
# Currently, without this define, we see:
# Error: cannot initialize a parameter of type 'long long *' with an rvalue of type 'std::int64_t *' (aka 'long *')
"__builtin_smulll_overflow(x,y,p)=(*(p)=(x)*(y),false)",
],
"//conditions:default": [],
}),
local_defines = [
"qDNGReportErrors=0",
"qDNGThreadSafe=1",
"qDNGUseLibJPEG=1",
"qDNGUseXMP=0",
"qDNGValidate=0",
"qDNGValidateTarget=1",
"UNIX_ENV=1",
],
strip_include_prefix = "externals/dng_sdk/source/",
deps = [
"libjpeg-turbo",
"zlib",
],
)