skia2/bazel/BUILD.bazel

133 lines
4.2 KiB
Python
Raw Normal View History

load("//bazel:macros.bzl", "cc_library", "exports_files_legacy", "select_multi")
[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 13:15:24 +00:00
licenses(["notice"])
exports_files_legacy()
GENERAL_DEFINES = [
# The following comment is load-bearing. It will be replace via regex when we build for Google3
# Do not remove it or we won't be able to properly define SK_BUILD_FOR_GOOGLE3
# REPLACE_WHEN_BUILDING_IN_GOOGLE3
"SK_HAS_ANDROID_CODEC",
"SKIA_IMPLEMENTATION=1",
] + select({
[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 13:15:24 +00:00
"//bazel/common_config_settings:debug_build": [
"SK_DEBUG",
],
"//bazel/common_config_settings:release_build": [
"SK_RELEASE",
],
"//conditions:default": [
"SK_RELEASE",
],
}) + select({
"//bazel/common_config_settings:enable_tracing_false": ["SK_DISABLE_TRACING"],
"//conditions:default": [],
}) + select({
"//bazel/common_config_settings:enable_effect_serialization_false": ["SK_DISABLE_EFFECT_DESERIALIZATION"],
"//conditions:default": [],
[bazel] Compile gms for wasm and WebGL PS 1 is re-generating existing BUILD.bazel files PS 2 is generating BUILD.bazel files for tests/gms PS 3+ makes modifications to build all of the gms and tests. It is recommended to view this CL with just a diff between PS 2 and the end, due to the large amount of generated changes in PS 1 and 2. We make a filegroup for the gms and tests because they need to be compiled as one large blob in order for the registries to work. Maybe in the future we will break these up, but at least for WASM/JS, the overhead of starting a browser for each new test would likely grind things to a halt, so we just group them all together for now. It's also the most similar to what we currently do. In gm/BUILD.bazel and tests/BUILD.bazel, we add a cc_library that encapsulates all of the deps of the tests, so we can easily include that the build. These were discovered via trial and error, not anything automatic or systematic. The is_skia_dev_build config_setting is very similar to the GN equivalent from which it was based. The list of gms and tests to skip (e.g. which are incompatible with WASM) was determined by building the wasm bundle: modules/canvaskit$ make bazel_gms_release tools/run-wasm-gm-tests$ make run_local_debug # Don't forget to click the button on the screen after the # browser loads This way of invoking the tests will be replace soon with `bazel test <something>`. As such, I didn't bother fully documenting the current way. Suggested review order: - modules/canvaskit/BUILD.bazel taking note that we always use profiling-funcs to make the stacktraces human readable. - gm/BUILD.bazel and tests/BUILD.bazel to see the lists of gms/tests. Notice the tests are roughly partitioned because we don't support things like vulkan/PDF in the wasm build and we will want a way to not build certain tests for certain configurations - tools/* noting some of the cc_libraries added to make dependencies easier to add when needed. - All other files. Change-Id: I43059cd93c28af1c4c12b93d6ebd9c46a12d381f Bug: skia:12541 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/506256 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-02-09 18:14:25 +00:00
}) + select({
"//bazel/common_config_settings:is_skia_dev_build_true": [
"GR_TEST_UTILS=1",
"SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1",
],
"//conditions:default": [],
}) + select({
"//bazel/common_config_settings:enable_skslc_true": [
"SKSL_STANDALONE",
"SK_DISABLE_TRACING",
"SK_ENABLE_SPIRV_CROSS",
"SK_ENABLE_SPIRV_VALIDATION",
"SK_ENABLE_WGSL_VALIDATION",
],
"//conditions:default": [],
}) + select({
"//bazel/common_config_settings:enable_sksl_tracing_true": [
"SKSL_ENABLE_TRACING",
],
"//conditions:default": [],
[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 13:15:24 +00:00
})
GPU_DEFINES = select({
"//bazel/common_config_settings:gl_backend": [
"SK_GL",
"SK_SUPPORT_GPU=1",
],
"//bazel/common_config_settings:vulkan_backend": [
"SK_VULKAN",
"SK_SUPPORT_GPU=1",
],
[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-21 17:06:32 +00:00
"//bazel/common_config_settings:dawn_backend": [
"SK_DAWN",
"SK_SUPPORT_GPU=1",
"VK_USE_PLATFORM_XCB_KHR", # TODO(kjlubick) support dawn's dawn_enable_vulkan etc
],
[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 13:15:24 +00:00
"//conditions:default": [
"SK_SUPPORT_GPU=0",
],
}) + select({
"//bazel/common_config_settings:gl_standard": [
"SK_ASSUME_GL=1",
],
"//bazel/common_config_settings:gles_standard": [
"SK_ASSUME_GL_ES=1",
],
"//bazel/common_config_settings:webgl_standard": [
"SK_ASSUME_WEBGL=1",
"SK_USE_WEBGL",
],
"//conditions:default": [],
}) + select({
"//bazel/common_config_settings:vulkan_with_vma": [
"SK_USE_VMA",
],
"//conditions:default": [],
[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 13:15:24 +00:00
})
CODEC_DEFINES = select_multi(
{
"//bazel/common_config_settings:gif_decode_codec": ["SK_HAS_WUFFS_LIBRARY"],
"//bazel/common_config_settings:jpeg_decode_codec": ["SK_CODEC_DECODES_JPEG"],
"//bazel/common_config_settings:jpeg_encode_codec": ["SK_ENCODE_JPEG"],
"//bazel/common_config_settings:png_decode_codec": ["SK_CODEC_DECODES_PNG"],
"//bazel/common_config_settings:png_encode_codec": ["SK_ENCODE_PNG"],
"//bazel/common_config_settings:raw_decode_codec": [
"SK_CODEC_DECODES_RAW",
"SK_CODEC_DECODES_JPEG",
],
"//bazel/common_config_settings:webp_decode_codec": ["SK_CODEC_DECODES_WEBP"],
"//bazel/common_config_settings:webp_encode_codec": ["SK_ENCODE_WEBP"],
[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 13:15:24 +00:00
},
default = [],
)
PLATFORM_DEFINES = select({
"//bazel/common_config_settings:cpu_wasm": [
# working around https://github.com/emscripten-core/emscripten/issues/10072
"SK_FORCE_8_BYTE_ALIGNMENT",
"SK_DISABLE_LEGACY_SHADERCONTEXT",
"SK_DISABLE_AAA", # This saves about 57KB of code size, uncompressed
[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 13:15:24 +00:00
],
"//conditions:default": [],
})
SHAPER_DEFINES = select_multi(
{
"//bazel/common_config_settings:coretext_shaper": ["SK_SHAPER_CORETEXT_AVAILABLE"],
"//bazel/common_config_settings:harfbuzz_shaper": ["SK_SHAPER_HARFBUZZ_AVAILABLE"],
},
default = [],
)
UNICODE_DEFINES = select({
"//bazel/common_config_settings:use_icu_true": ["SK_UNICODE_AVAILABLE"],
"//conditions:default": [],
})
[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 13:15:24 +00:00
cc_library(
name = "defines_from_flags",
defines = GENERAL_DEFINES + GPU_DEFINES + CODEC_DEFINES + PLATFORM_DEFINES +
SHAPER_DEFINES + UNICODE_DEFINES,
[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 13:15:24 +00:00
visibility = ["//:__subpackages__"],
)