2c65579aad
The primary goal of this organization structure is to keep our top level BUILD.bazel file short, with as little logic as feasible. The logic required to control which files to include, which third_party deps are needed, what system libraries should be linked again, etc, should be in the BUILD.bazel file best should be as close to the affected files as feasible. In essence, we use filegroup() rules to bubble up the files needed to build Skia (all as one big cc_library call) and cc_library rules to bubble up the other components needed to build. For example, //src/ports/SkFontHost_FreeType.cpp needs FreeType, but only if we are compiling Skia with that type of font support. With the new organization structure in this CL, //src/ports/BUILD.bazel should have the logic that determines if the cpp file should be included in the build of Skia and if it is, that the Skia build should depend on //third_party:freetype2 Another example is //src/gpu/ganesh/BUILD.bazel, which chooses which of the dawn, gl, vulkan, etc backend sources, and the associated dependencies to include in the build. It does not specify what those are, but delegates to the BUILD.bazel files in the subdirectories housing the backend-specific code. The structure guidelines for BUILD.bazel files are as follows: - Have a filegroup() called "hdrs" (for public headers) or "srcs" (for private headers and all .cpp files) that is visible to the parent directory. This should list the files from the containing directory to include in the build. See //include/core/BUILD.bazel and //src/effects/BUILD.bazel as examples. - filegroup() rules can list a child directory's "hdrs" or "srcs" in their "srcs" attributes, but should not contain select statements pertaining to child directory files. See //include/gpu/BUILD.bazel and //src/gpu/ganesh/BUILD.bazel as examples. - May have a cc_library() called "deps". This can specify dependencies, cc_opts, and linkopts, but not srcs or hdrs. [1] See //src/codec/BUILD.bazel as an example. These should be visible to the parent directory. - "hdrs", "srcs", and "deps" for the primary Skia build (currently called "skia_core") should bubble up through //include/BUILD.bazel and //src/BUILD.bazel, one directory at a time. This CL demonstrates a very basic build of Skia with many features turned off (CPU only, no fonts, no codecs). Follow-on CLs will add to these rules as more targets are supported. See bazel/Makefile for the builds that work with just this CL. Suggested Review Order: - //BUILD.bazel to see the very small skia_core rule which delegates all the logic down stack. Note that it has a dependency on //bazel:defines_from_flags which will set all the defines listed there when compiling all the .cpp and .h files in skia_core *and* anything that depends on skia_core, but *not* //src:deps. - //include/BUILD.bazel and other BUILD.bazel files in the subdirectories of that folder. Note that the filegroups in //include/private/... are called "srcs" to be similar to how Bazel wants "private headers" to be in the "srcs" of cc_library, cc_binary, etc. and only public headers are to be in "hdrs" [2]. - //src/BUILD.bazel and other BUILD.bazel files in the subdirectories of that folder. //src/gpu/ganesh/... will be filled in for dawn, vulkan, and GL in the next CL. - //PRESUBMIT.py, which adds a check that runs buildifier [3] on modified BUILD.bazel files to make sure they stay consistently formatted. - //bazel/... to see the new option I added to make sksl opt-in or opt-out, so one could build Skia with sksl, but not with a gpu backend. - Misc .h and .cpp files, whose includes were removed if unnecessary or #ifdef'd out to make the minimal build work without GPU or SkSL includes. - //bazel/Makefile to see the builds that work with this CL. [1] Setting srcs or hdrs is error-prone at best, because those files will be compiled with a different set of defines than the rest of skia_core, because they wouldn't depend on //bazel:defines_from_flags. [2] https://bazel.build/reference/be/c-cpp#cc_library.hdrs [3] https://github.com/bazelbuild/buildtools/releases Change-Id: I5e0e3ae01ad42d672506d5aad1239f2512188191 Bug: skia:12541 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/543977 Reviewed-by: Leandro Lovisolo <lovisolo@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
245 lines
6.5 KiB
Python
245 lines
6.5 KiB
Python
load("//bazel:macros.bzl", "selects")
|
|
load(":defs.bzl", "bool_flag", "string_flag_with_values")
|
|
|
|
licenses(["notice"])
|
|
|
|
# @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",
|
|
],
|
|
)
|
|
|
|
# Apple devices with intel processors released before the shift to the M1 chip
|
|
# will use this config setting. Because M1 chips use the arm cpu instruction set,
|
|
# this flag will not be used.
|
|
config_setting(
|
|
name = "mac_x64",
|
|
constraint_values = [
|
|
"@platforms//cpu:x86_64",
|
|
"@platforms//os:macos",
|
|
],
|
|
)
|
|
|
|
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 = [
|
|
":gl_backend",
|
|
":dawn_backend",
|
|
":vulkan_backend",
|
|
],
|
|
)
|
|
|
|
selects.config_setting_group(
|
|
name = "needs_sksl",
|
|
match_any = [
|
|
":has_gpu_backend",
|
|
":enable_sksl_true",
|
|
],
|
|
)
|
|
|
|
selects.config_setting_group(
|
|
name = "vulkan_with_vma",
|
|
match_all = [
|
|
":vulkan_backend",
|
|
":use_vulkan_memory_allocator_true",
|
|
],
|
|
)
|
|
|
|
# =============================================================================
|
|
# 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 = True,
|
|
flag_name = "enable_effect_serialization",
|
|
)
|
|
|
|
bool_flag(
|
|
default = False,
|
|
flag_name = "enable_sksl",
|
|
)
|
|
|
|
bool_flag(
|
|
default = False,
|
|
flag_name = "enable_skslc",
|
|
)
|
|
|
|
bool_flag(
|
|
default = False,
|
|
flag_name = "enable_sksl_tracing",
|
|
)
|
|
|
|
bool_flag(
|
|
# See SkTraceEventCommon.h for more on this type of tracing.
|
|
default = True,
|
|
flag_name = "enable_tracing",
|
|
)
|
|
|
|
bool_flag(
|
|
default = False,
|
|
flag_name = "is_skia_dev_build",
|
|
)
|
|
|
|
bool_flag(
|
|
default = False,
|
|
flag_name = "use_icu",
|
|
)
|
|
|
|
bool_flag(
|
|
default = True,
|
|
flag_name = "use_vulkan_memory_allocator",
|
|
public = False, # Users should use :vulkan_with_vma
|
|
)
|