skia2/bazel/common_config_settings/BUILD.bazel
Kevin Lubick 14abec45f0 [bazel] Add support for Dawn (via Vulkan)
sk_app has existing support for Dawn on top of Vulkan, and
this adds support to build //example:hello_world_dawn and
get this to run on Linux.

Dawn depends on Tint and abseil-cpp. Tint further depends on
spirv_tools and spirv_headers (for writing to the SPIR-V format).
Dawn and Tint only have GN and CMake support, so we need to make
our Bazel rules for them (see //third_party/BUILD.bazel).

abseil-cpp and the SPIR-V libraries have Bazel support, so we
can just include them (see //WORKSPACE.bazel). It is important
that @spirv_headers be called that exactly because @spirv_tools
depends on it by that name.

The hand-crafted cc_library rules for Dawn and Tint were produced
by reading the appropriate GN files and using the parts necessary
for a supporting Vulkan+Linux. If we use Dawn for other backends
(e.g. WebGPU), we will need to expand the Bazel rules. One day,
we might contribute the Bazel rules to Dawn and Tint so they
can support them and avoid breaking us if new files are added.

Suggested Review Order
 - bazel/common_config_settings/BUILD.bazel to see introduction
   of new select-able option "has_gpu_backend" which cleans up
   some of our code that is enabled for any GPU backend.
 - src/*/BUILD.bazel to see has_gpu_backend rolled out.
 - WORKSPACE.bazel to see DEPS declared there (using the files
   in third_party/externals, which are brought in via
   tools/git-sync-deps).
 - third_party/BUILD.bazel which adds Dawn and Tint rules.
   It may be helpful to look in third_party/externals for
   the Dawn [1] and Tint [2] GN files. Especially interesting
   are the Python scripts [3] Dawn uses to generate some
   header and source files.
 - All other files.

[1] https://dawn.googlesource.com/dawn/+/d9f22ce0346b222759d5510be3d1cd93caa5ab86/src/dawn/native/BUILD.gn#183
[2] https://dawn.googlesource.com/tint/+/453d5ae84ec30ab51ac592c13d472412ae8b5fc9/src/tint/BUILD.gn#174
[3] https://dawn.googlesource.com/dawn/+/d9f22ce0346b222759d5510be3d1cd93caa5ab86/generator/dawn_json_generator.py#774
Change-Id: Ied5b162045d8e841b9666457f0158457e2b078d4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/516996
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-03-22 13:05:52 +00:00

196 lines
5.6 KiB
Python

load(":defs.bzl", "bool_flag", "string_flag_with_values")
# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
# @platforms is found at https://github.com/bazelbuild/platforms
package(default_visibility = ["//:__subpackages__"])
config_setting(
name = "linux_x64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)
config_setting(
name = "windows_x64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
)
config_setting(
name = "linux_arm64",
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:linux",
],
)
config_setting(
name = "debug_build",
values = {"compilation_mode": "dbg"},
)
config_setting(
name = "release_build",
values = {"compilation_mode": "opt"},
)
constraint_value(
name = "fuchsia",
constraint_setting = "@platforms//os:os",
)
config_setting(
name = "fuchsia_arm64",
constraint_values = [
"@platforms//cpu:arm64",
":fuchsia",
],
)
# We define this here because the emscripten toolchain calls the cpu wasm, whereas the
# bazelbuild/platforms call it wasm32. https://github.com/emscripten-core/emsdk/issues/919
config_setting(
name = "cpu_wasm",
values = {
"cpu": "wasm",
},
)
selects.config_setting_group(
name = "has_gpu_backend",
match_any = [
"//bazel/common_config_settings:gl_backend",
"//bazel/common_config_settings:dawn_backend",
"//bazel/common_config_settings:vulkan_backend",
],
)
# =============================================================================
# Configurable Skia Features
# =============================================================================
# These are flags that we can specify when invoking bazel build to turn on and
# off certain features, such as GPU backend, or codec support.
# https://docs.bazel.build/versions/4.2.1/skylark/config.html#using-build-settings-on-the-command-line
# For example, to use the GL backend with the WebGL flavor, one would run
# bazel build //:skia-core --//bazel/common_config_settings:gpu_backend=gl_backend \
# --//bazel/common_config_settings:with_gl_standard=webgl_standard
# This is a bit wordy, so we define aliases in the //.bazelrc file that condense this to
# bazel build //:skia-core --gpu_backend=gl_backend --with_gl_standard=webgl_standard
#
# Developers can specify their own short-hands by making a .bazelrc file in their home
# directory. https://docs.bazel.build/versions/main/guide.html#where-are-the-bazelrc-files
#
string_flag_with_values(
flag_name = "gpu_backend",
multiple = True,
values = [
"gl_backend",
"vulkan_backend",
"dawn_backend",
],
)
string_flag_with_values(
flag_name = "with_gl_standard",
values = [
"gles_standard",
"gl_standard",
"webgl_standard",
],
)
string_flag_with_values(
default = "empty_fontmgr_factory",
flag_name = "fontmgr_factory",
values = [
# Makes the default SkFontMgr load fonts from a hard-coded directory on disk.
"custom_directory_fontmgr_factory",
# Makes the default SkFontMgr load fonts from an SkEmbeddedResource that has been compiled
# into the binary, e.g. with //tools/embed_resources.py
"custom_embedded_fontmgr_factory",
# Makes the default SkFontMgr return empty fonts (e.g. SkTypeface_Empty). This is typically
# used when someone wants to make their own custom SkFontMgr objects, but does not want the
# default SkFontMgr to do anything (e.g. force usage of the custom one).
"custom_empty_fontmgr_factory",
# Makes the default SkFontMgr return null. Typically used when font support is not desired.
"empty_fontmgr_factory",
],
)
# These flags need only be set if additional functionality beyond the fontmgr_factory flag is
# required. For example, the setting fontmgr_factory to custom_embedded_fontmgr_factory does not
# require setting include_fontmgr to custom_embedded_fontmgr, because those sources and settings
# will already be compiled in due to the _factory flag.
string_flag_with_values(
flag_name = "include_fontmgr",
multiple = True,
values = [
# Allows the construction of an SkFontMgr that loads files from a programmatically
# defined directory on disk.
"custom_directory_fontmgr",
# Allows the construction of an SkFontMgr which can load fonts from an SkEmbeddedResource
# or from another source of raw bytes.
"custom_embedded_fontmgr",
# Allows the construction of an SkFontMgr which returns empty fonts.
"custom_empty_fontmgr",
],
)
string_flag_with_values(
flag_name = "include_decoder",
multiple = True,
values = [
"gif_decode_codec",
"jpeg_decode_codec",
"png_decode_codec",
"raw_decode_codec",
"webp_decode_codec",
],
)
string_flag_with_values(
flag_name = "include_encoder",
multiple = True,
values = [
"jpeg_encode_codec",
"png_encode_codec",
"webp_encode_codec",
],
)
string_flag_with_values(
flag_name = "shaper_backend",
multiple = True,
values = [
"harfbuzz_shaper",
"coretext_shaper",
],
)
bool_flag(
default = False,
flag_name = "use_icu",
)
bool_flag(
default = False,
flag_name = "disable_tracing",
)
bool_flag(
default = False,
flag_name = "disable_effect_serialization",
)
bool_flag(
default = False,
flag_name = "is_skia_dev_build",
)