Skip to content

Commit

Permalink
[bazel] Support optional building of Ganesh Metal backend.
Browse files Browse the repository at this point in the history
Change-Id: Ia321c3d67898cf15a14ad5ce8f56227ef990bac0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/673919
Reviewed-by: Kevin Lubick <[email protected]>
  • Loading branch information
bpsalomon authored and kjlubick committed Apr 20, 2023
1 parent 660953b commit d43b92d
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 31 deletions.
30 changes: 27 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
load("//:defines.bzl", "DEFAULT_DEFINES", "DEFAULT_LOCAL_DEFINES")
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library")
load("@skia_user_config//:copts.bzl", "DEFAULT_OBJC_COPTS")
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library", "skia_objc_library")

licenses(["notice"])

exports_files_legacy()

# All the mm files from the Skia library are rolled up to this objc library since cc_library
# ignores mm files. This private library is then deps'ed into the public and internal versions
# of the SKia library below. The Skia library Objective-C code requires ARC, while non-library code
# does not.
skia_objc_library(
name = "skia_objc",
srcs = [
"//src:objc_srcs",
],
copts = DEFAULT_OBJC_COPTS + ["-fobjc-arc"],
defines = DEFAULT_DEFINES,
deps = [
"//src:deps",
"@skia_user_config//:user_config",
],
)

# This target exposes the Skia public API. It is what external clients should use.
skia_cc_library(
name = "skia_public",
Expand All @@ -21,7 +39,10 @@ skia_cc_library(
deps = [
"//src:deps",
"@skia_user_config//:user_config",
],
] + select({
"//src/gpu:metal_backend": ["//:skia_objc"],
"//conditions:default": [],
}),
)

# This target exposes headers beyond the public, supported API. It is intended to be
Expand All @@ -48,7 +69,10 @@ skia_cc_library(
deps = [
"//src:deps",
"@skia_user_config//:user_config",
],
] + select({
"//src/gpu:metal_backend": ["//:skia_objc"],
"//conditions:default": [],
}),
)

####################################################################
Expand Down
3 changes: 3 additions & 0 deletions bazel/buildrc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ build:vulkan_ganesh --enable_gpu_test_utils --gpu_backend=vulkan_backend \
build:dawn_ganesh --enable_gpu_test_utils --gpu_backend=dawn_backend \
--cc_output_directory_tag=dawn_ganesh

build:metal_ganesh --enable_gpu_test_utils --gpu_backend=metal_backend \
--cc_output_directory_tag=metal_ganesh

# Short-hand aliases
build:cpu --config=cpu_only
build:gl --config=gl_ganesh
Expand Down
6 changes: 4 additions & 2 deletions bazel/exporter_tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ var gniExportDescs = []exporter.GNIExportDesc{
}},
{Var: "skia_gpu_metal_private",
Rules: []string{
"//src/gpu/ganesh/surface:mtl_srcs",
"//include/private/gpu/ganesh:mtl_private_hdrs",
"//src/gpu/ganesh/surface:mtl_objc_srcs",
"//src/gpu/ganesh/mtl:mtl_hdrs",
"//src/gpu/ganesh/mtl:mtl_srcs",
}},
Expand Down Expand Up @@ -403,7 +404,8 @@ var gniExportDescs = []exporter.GNIExportDesc{
{Var: "skia_shared_mtl_sources",
Rules: []string{
"//include/gpu/mtl:shared_public_hdrs",
"//src/gpu/mtl:shared_srcs",
"//src/gpu/mtl:mtl_hdrs",
"//src/gpu/mtl:mtl_srcs",
}},
{Var: "skia_piet_gpu_sources",
Rules: []string{
Expand Down
2 changes: 1 addition & 1 deletion bazel/skia_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def skia_filegroup(**kwargs):
native.filegroup(**kwargs)

def skia_objc_library(name, copts = DEFAULT_OBJC_COPTS, **kwargs):
"""A wrapper around cc_library for Skia Objective C libraries.
"""A wrapper around objc_library for Skia Objective C libraries.
This lets us provide compiler flags (copts) consistently to the Skia build (e.g. //:skia_public)
and builds which depend on those targets (e.g. things in //tools or //modules).
Expand Down
4 changes: 4 additions & 0 deletions defines.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ GPU_DEFINES = select_multi({
"SK_GANESH",
"VK_USE_PLATFORM_XCB_KHR", # TODO(kjlubick) support dawn's dawn_enable_vulkan etc
],
"//src/gpu:metal_backend": [
"SK_METAL",
"SK_GANESH",
],
}) + select({
"//src/gpu:gl_standard": [
"SK_ASSUME_GL=1",
Expand Down
26 changes: 26 additions & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ cc_binary_with_flags(
],
)

cc_binary_with_flags(
name = "hello_world_metal",
testonly = True,
srcs = [
"HelloWorld.cpp",
"HelloWorld.h",
],
# These flags are defined in //bazel/common_config_settings/BUILD.bazel
set_flags = {
"gpu_backend": [
"metal_backend",
],
# Load fonts from the standard system directory (e.g. "/usr/share/fonts/")
# as defined in //src/ports/SkFontMgr_custom_directory_factory.cpp
"fontmgr_factory": [
"custom_directory_fontmgr_factory",
],
},
deps = [
"//:skia_public",
] + select({
"@platforms//os:macos": ["//tools/sk_app:sk_app_objc"],
"//conditions:default": [],
}),
)

cc_binary_with_flags(
name = "vulkan_basic",
testonly = True,
Expand Down
7 changes: 5 additions & 2 deletions gn/gpu.gni
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,12 @@ skia_gpu_metal_public = [
]

# List generated by Bazel rules:
# //src/gpu/ganesh/surface:mtl_srcs
# //include/private/gpu/ganesh:mtl_private_hdrs
# //src/gpu/ganesh/surface:mtl_objc_srcs
# //src/gpu/ganesh/mtl:mtl_hdrs
# //src/gpu/ganesh/mtl:mtl_srcs
skia_gpu_metal_private = [
"$_include/private/gpu/ganesh/GrMtlTypesPriv.h",
"$_src/gpu/ganesh/mtl/GrMtlAttachment.h",
"$_src/gpu/ganesh/mtl/GrMtlAttachment.mm",
"$_src/gpu/ganesh/mtl/GrMtlBuffer.h",
Expand Down Expand Up @@ -1096,7 +1098,8 @@ skia_shared_vk_sources = [

# List generated by Bazel rules:
# //include/gpu/mtl:shared_public_hdrs
# //src/gpu/mtl:shared_srcs
# //src/gpu/mtl:mtl_hdrs
# //src/gpu/mtl:mtl_srcs
skia_shared_mtl_sources = [
"$_include/gpu/mtl/MtlMemoryAllocator.h",
"$_src/gpu/mtl/MtlMemoryAllocatorImpl.h",
Expand Down
3 changes: 2 additions & 1 deletion include/gpu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ skia_filegroup(
{
"//src/gpu:dawn_backend": ["//include/gpu/dawn:public_hdrs"],
"//src/gpu:vulkan_backend": ["//include/gpu/vk:public_hdrs"],
# TODO(kjlubick) mtl and d3d backend
"//src/gpu:metal_backend": ["//include/gpu/mtl:public_hdrs"],
# TODO(kjlubick) d3d backend
},
),
visibility = ["//include:__pkg__"],
Expand Down
6 changes: 3 additions & 3 deletions include/gpu/mtl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ licenses(["notice"])

exports_files_legacy()

# Not referenced by Bazel target.
# for exporting to //gn/gpu.gni:skia_shared_mtl_sources.
skia_filegroup(
name = "shared_public_hdrs",
Expand All @@ -13,12 +12,13 @@ skia_filegroup(
],
)

# Not referenced by Bazel target.
# for exporting to //gn/gpu.gni:skia_metal_sources.
# Group is exported to //gn/gpu.gni:skia_gpu_metal_public.
skia_filegroup(
name = "public_hdrs",
srcs = [
"GrMtlBackendContext.h",
"GrMtlTypes.h",
":shared_public_hdrs",
],
visibility = ["//include/gpu:__pkg__"],
)
9 changes: 8 additions & 1 deletion include/private/gpu/ganesh/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ skia_filegroup(
srcs = ["GrD3DTypesMinimal.h"],
)

# In own group for mapping to //gn/gpu.gni:skia_gpu_metal_private.
skia_filegroup(
name = "mtl_private_hdrs",
srcs = ["GrMtlTypesPriv.h"],
)

skia_filegroup(
name = "private_hdrs",
srcs = [
Expand All @@ -35,7 +41,8 @@ skia_filegroup(
"//src/gpu:dawn_backend": [":dawn_private_hdrs"],
"//src/gpu:gl_backend": ["GrGLTypesPriv.h"],
"//src/gpu:vulkan_backend": [":vk_private_hdrs"],
# TODO(kjlubick) Direct3D and Metal Backends
"//src/gpu:metal_backend": [":mtl_private_hdrs"],
# TODO(kjlubick) Direct3D Backend
},
),
visibility = ["//include/private/gpu:__pkg__"],
Expand Down
9 changes: 9 additions & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ skia_filegroup(
visibility = ["//:__pkg__"],
)

skia_filegroup(
name = "objc_srcs",
srcs = select({
"//src/gpu:has_gpu_backend": ["//src/gpu:objc_srcs"],
"//conditions:default": [],
}),
visibility = ["//:__pkg__"],
)

skia_filegroup(
name = "private_hdrs",
srcs = [
Expand Down
12 changes: 12 additions & 0 deletions src/gpu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ string_flag_with_values(
"gl_backend",
"vulkan_backend",
"dawn_backend",
"metal_backend",
],
)

Expand All @@ -73,6 +74,7 @@ selects.config_setting_group(
":gl_backend",
":dawn_backend",
":vulkan_backend",
":metal_backend",
],
visibility = ["//:__subpackages__"],
)
Expand Down Expand Up @@ -113,6 +115,15 @@ skia_filegroup(
visibility = ["//src:__pkg__"],
)

skia_filegroup(
name = "objc_srcs",
srcs = [
"//src/gpu/ganesh:objc_srcs",
"//src/gpu/mtl:shared_objc_srcs",
],
visibility = ["//src:__pkg__"],
)

skia_filegroup(
name = "private_hdrs",
srcs = [
Expand All @@ -124,6 +135,7 @@ skia_filegroup(
{
"//src/gpu:dawn_backend": ["//src/gpu/dawn:private_hdrs"],
"//src/gpu:vulkan_backend": ["//src/gpu/vk:private_hdrs"],
"//src/gpu:metal_backend": ["//src/gpu/mtl:private_hdrs"],
},
),
visibility = ["//src:__pkg__"],
Expand Down
18 changes: 16 additions & 2 deletions src/gpu/ganesh/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,20 @@ skia_filegroup(
"//src/gpu:dawn_backend": ["//src/gpu/ganesh/dawn:srcs"],
"//src/gpu:gl_backend": ["//src/gpu/ganesh/gl:srcs"],
"//src/gpu:vulkan_backend": ["//src/gpu/ganesh/vk:srcs"],
# TODO(kjlubick) mtl and d3d backend
# TODO(kjlubick) d3d backend
},
),
visibility = ["//src/gpu:__pkg__"],
)

skia_filegroup(
name = "objc_srcs",
srcs = select_multi(
{
"//src/gpu:metal_backend": [
"//src/gpu/ganesh/mtl:objc_srcs",
"//src/gpu/ganesh/surface:mtl_objc_srcs",
],
},
),
visibility = ["//src/gpu:__pkg__"],
Expand All @@ -304,7 +317,8 @@ skia_filegroup(
"//src/gpu:dawn_backend": ["//src/gpu/ganesh/dawn:private_hdrs"],
"//src/gpu:gl_backend": ["//src/gpu/ganesh/gl:private_hdrs"],
"//src/gpu:vulkan_backend": ["//src/gpu/ganesh/vk:private_hdrs"],
# TODO(kjlubick) mtl and d3d backend
"//src/gpu:metal_backend": ["//src/gpu/ganesh/mtl:private_hdrs"],
# TODO(kjlubick) d3d backend
},
),
visibility = ["//src/gpu:__pkg__"],
Expand Down
19 changes: 17 additions & 2 deletions src/gpu/ganesh/mtl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ skia_filegroup(
],
)

# Not currently in a Bazel target.
# This list is exported to to gpu.gni:skia_metal_sources.
MTL_FILES = [
"GrMtlAttachment.h",
"GrMtlAttachment.mm",
Expand Down Expand Up @@ -68,3 +66,20 @@ split_srcs_and_hdrs(
name = "mtl",
files = MTL_FILES,
)

skia_filegroup(
name = "objc_srcs",
srcs = [
":mtl_srcs",
],
visibility = ["//src/gpu/ganesh:__pkg__"],
)

skia_filegroup(
name = "private_hdrs",
srcs = [
":mtl_cpp_hdrs",
":mtl_hdrs",
],
visibility = ["//src/gpu/ganesh:__pkg__"],
)
4 changes: 2 additions & 2 deletions src/gpu/ganesh/surface/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ split_srcs_and_hdrs(
files = SURFACE_FILES,
)

# Not referenced by Bazel target.
# File group use to export to //gn/gpu.gni:skia_metal_sources.
skia_filegroup(
name = "mtl_srcs",
name = "mtl_objc_srcs",
srcs = ["SkSurface_GaneshMtl.mm"],
visibility = ["//src/gpu/ganesh:__pkg__"],
)

skia_filegroup(
Expand Down
32 changes: 22 additions & 10 deletions src/gpu/mtl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup")
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup", "split_srcs_and_hdrs")

licenses(["notice"])

exports_files_legacy()

# Not referenced by Bazel target.
# for exporting to //gn/gpu.gni:skia_shared_mtl_sources.
MTL_FILES = [
"MtlMemoryAllocatorImpl.h",
"MtlMemoryAllocatorImpl.mm",
"MtlUtils.mm",
"MtlUtilsPriv.h",
]

split_srcs_and_hdrs(
name = "mtl",
files = MTL_FILES,
)

skia_filegroup(
name = "shared_objc_srcs",
srcs = [":mtl_srcs"],
visibility = ["//src/gpu:__pkg__"],
)

skia_filegroup(
name = "shared_srcs",
srcs = [
"MtlMemoryAllocatorImpl.h",
"MtlMemoryAllocatorImpl.mm",
"MtlUtils.mm",
"MtlUtilsPriv.h",
],
name = "private_hdrs",
srcs = [":mtl_hdrs"],
visibility = ["//src/gpu:__pkg__"],
)
Loading

0 comments on commit d43b92d

Please sign in to comment.