skia2/BUILD.bazel
Kevin Lubick 6ba9f702ba [bazel] Try adding cc_binary rules that use generated rules
To make the atomic rules a bit easier to work with, in many
of the folders, this adds in cc_library rules to group
together the sources from that folder (and subfolders
where prudent). We only needs sources because those atoms
should have their headers as deps.

One issue that was pointed out is that there is currently
no way to restrict the inclusion of certain packages,
a la, `gn check`. For example, there is no mechanism from
stopping a dev from adding
#include "modules/canvaskit/WasmCommon.h"
to something in //src/core (except circular dependencies).
We can probably address that using Bazel's visibility
rules as needed:
https://docs.bazel.build/versions/main/visibility.html
https://docs.bazel.build/versions/main/be/functions.html#package_group

It is recommended to look at this CL patchset by patchset.
PS1: Update gazelle command to generate rules in more folders.
PS2: A few changes to make generation work better.
PS3: The result of running make generate in //bazel
PS4: Adding the rules to build sksllex, the simplest binary I
     could find in the Skia repo.
PS5: Adding the rules to build skdiff, a more complex binary.
     I tried a few approaches, but ended up gravitating back
     towards the layout where we have each folder/package
     group up the sources. I imagine at some point, we'll have
     skdiff depend on skia_core or something, which will
     have things like //src/core, //src/codecs, //src/pathops
     all bundled together.
PS7: Added in the groupings of sources, similar to what we had
     earlier. I liked these for readability. These helped fix
     up the //:skia_core build, and by extension, the CanvasKit
     build.

Change-Id: I3faa7c4e821c876b243617aacf0246efa524cbde
Bug: skia:12541
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/476219
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
2021-11-30 18:18:53 +00:00

152 lines
3.6 KiB
Python

# https://github.com/bazelbuild/bazel-skylib
load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:macros.bzl", "select_multi")
load("@bazel_gazelle//:def.bzl", "gazelle")
package(default_visibility = ["//:__subpackages__"])
cc_test(
name = "bazel_test",
size = "small",
srcs = [
"//experimental/bazel_test:srcs",
"//include/config:hdrs",
"//include/core:hdrs",
"//src/ports:skdebug",
],
deps = [
"//third_party:libpng",
"//third_party:musl_compat",
],
)
selects.config_setting_group(
name = "needs_jpeg",
match_any = [
"//bazel/common_config_settings:raw_decode_codec",
"//bazel/common_config_settings:jpeg_decode_codec",
"//bazel/common_config_settings:jpeg_encode_codec",
],
)
selects.config_setting_group(
name = "needs_png",
match_any = [
"//bazel/common_config_settings:png_decode_codec",
"//bazel/common_config_settings:png_encode_codec",
],
)
selects.config_setting_group(
name = "needs_webp",
match_any = [
"//bazel/common_config_settings:webp_decode_codec",
"//bazel/common_config_settings:webp_encode_codec",
],
)
selects.config_setting_group(
name = "any_freetype_fontmgr",
match_any = [
"//bazel/common_config_settings:custom_directory_fontmgr",
"//bazel/common_config_settings:custom_embedded_fontmgr",
"//bazel/common_config_settings:custom_empty_fontmgr",
],
)
CORE_DEPS = [
"//src/android:srcs",
"//src/codec:srcs",
"//src/core:srcs",
"//src/image:srcs",
"//src/images:srcs",
"//src/effects:srcs",
"//src/opts:srcs",
"//src/pathops:srcs",
"//src/ports:srcs",
"//src/sfnt:srcs",
"//src/shaders:srcs",
"//src/utils:srcs",
"//third_party:skcms",
] + selects.with_or({
# https://github.com/bazelbuild/bazel-skylib/blob/main/docs/selects_doc.md#selectswith_or
("//bazel/common_config_settings:gl_backend", "//bazel/common_config_settings:vulkan_backend"): [
"//src/gpu:srcs",
"//src/sksl:srcs",
# TODO(kjlubick) should mock be test only?
"//src/gpu:mock_srcs",
],
"//conditions:default": [],
}) + select_multi(
{
"//bazel/common_config_settings:gif_decode_codec": ["//third_party:wuffs"],
":needs_png": ["//third_party:libpng"],
"//bazel/common_config_settings:raw_decode_codec": [
"//third_party:piex",
"//third_party:dng_sdk",
],
":needs_webp": ["//third_party:libwebp"],
":needs_jpeg": ["//third_party:libjpeg-turbo"],
},
default = [],
) + select({
":any_freetype_fontmgr": [
"//third_party:freetype2",
],
"//conditions:default": [],
})
cc_library(
name = "skia_core",
textual_hdrs = ["//src/sksl:txts"],
deps = CORE_DEPS,
)
cc_library(
name = "hash_and_encode",
testonly = True,
srcs = [
"//tools:cmdline",
"//tools:hash_and_encode",
],
deps = [
":skia-core",
"//third_party:libpng",
],
)
cc_library(
name = "gms",
testonly = True,
srcs = [
"//gm:gms",
"//gm:srcs",
"//tools:srcs",
],
hdrs = [
"//gm:hdrs",
],
textual_hdrs = ["//tools:txts"],
deps = [":skia-core"],
)
cc_library(
name = "tests",
testonly = True,
srcs = [
"//tests:srcs",
"//tools:srcs",
],
hdrs = [
"//tests:hdrs",
],
local_defines = [
"GR_TEST_UTILS",
],
textual_hdrs = ["//tools:txts"],
deps = [":skia-core"],
)
# gazelle:prefix go.skia.org/skia
gazelle(name = "gazelle")