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>
80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
"""
|
|
This file contains general helper macros that make our BUILD.bazel files easier to read.
|
|
"""
|
|
|
|
# https://github.com/bazelbuild/bazel-skylib
|
|
load("@bazel_skylib//lib:selects.bzl", _selects = "selects")
|
|
load("@rules_python//python:defs.bzl", _py_binary = "py_binary")
|
|
load("@py_deps//:requirements.bzl", _requirement = "requirement")
|
|
load("@bazel_gazelle//:def.bzl", _gazelle = "gazelle")
|
|
|
|
# re-export symbols that are commonly used or that are not supported in G3
|
|
# (and thus we need to stub out)
|
|
selects = _selects
|
|
py_binary = _py_binary
|
|
requirement = _requirement
|
|
gazelle = _gazelle
|
|
|
|
def select_multi(values_map, default):
|
|
"""select() but allowing multiple matches of the keys.
|
|
|
|
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": [],
|
|
})
|
|
|
|
Args:
|
|
values_map: dictionary of labels to a list of labels, just like select()
|
|
default: list of labels, the value that should be used if any of the options do not match.
|
|
This is typically an empty list
|
|
|
|
Returns:
|
|
A list of values that is filled in by the generated select statements.
|
|
"""
|
|
if len(values_map) == 0:
|
|
return default
|
|
rv = []
|
|
for key, value in values_map.items():
|
|
rv += select({
|
|
key: value,
|
|
"//conditions:default": default,
|
|
})
|
|
return rv
|
|
|
|
# buildifier: disable=unnamed-macro
|
|
# buildifier: disable=native-package
|
|
def enforce_iwyu_on_package():
|
|
"""A self-annotating macro to set force_iwyu = True on all rules in this package."""
|
|
native.package(features = ["skia_opt_file_into_iwyu"])
|
|
|
|
# buildifier: disable=unnamed-macro
|
|
def cc_library(**kwargs):
|
|
"""A shim around cc_library that lets us tweak settings for G3 if necessary."""
|
|
native.cc_library(**kwargs)
|
|
|
|
# buildifier: disable=unnamed-macro
|
|
def exports_files_legacy():
|
|
"""A self-annotating macro to export all files in this package for legacy G3 rules."""
|
|
pass
|