xref: /aosp_15_r20/external/skia/third_party/vello/BUILD.gn (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1# Copyright 2023 Google LLC
2#
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import("../../gn/skia.gni")
7import("../third_party.gni")
8
9# The following shells out to bazelisk to compile static library dependencies that bridge the
10# vello_cpp crate Rust code and its C++ FFI symbols. This produces a single static library target
11# that is reachable via the ":vello" target.
12#
13# Pre-compiled shader dependencies:
14#
15#   The vello_shaders crate bundles compute shaders that are pre-compiled into a target format based
16#   on the GPU backend. This is driven by build arguments defined in //gn/skia.gni.
17
18if (skia_enable_vello_shaders) {
19  bazel_args = []
20  if (is_mac) {
21    if (host_cpu == "arm64") {
22      bazel_args += [ "--host_platform=//bazel/platform:mac_arm64_hermetic" ]
23    }
24    if (target_cpu == "arm64") {
25      bazel_args += [
26        "--platforms=//bazel/platform:mac_arm64_hermetic",
27        "--cc_output_directory_tag=mac_arm64",
28      ]
29    }
30  }
31  if (!is_debug) {
32    bazel_args += [ "--compilation_mode=opt" ]
33  }
34  if (skia_use_metal) {
35    bazel_args += [ "--define=VELLO_MSL_SHADERS=true" ]
36  }
37  if (skia_use_dawn) {
38    bazel_args += [ "--define=VELLO_WGSL_SHADERS=true" ]
39  }
40  action("compile_vello_ffi") {
41    script = "../../gn/bazel_build.py"
42    sources = [
43      "BUILD.bazel",
44      "src/lib.rs",
45    ]
46    outputs = [
47      "$root_out_dir/libvello_ffi.a",
48      "$root_out_dir/third_party/vello/src/lib.rs.h",
49    ]
50    args = [
51             "//third_party/vello:vello_ffi",
52             rebase_path("//bazel-bin/third_party/vello/libvello_ffi.a",
53                         root_build_dir),
54
55             # we want the header to not simply be copied into the output directory,
56             # but in the same path as the Bazel build uses.
57             rebase_path("//bazel-bin/third_party/vello/src/lib.rs.h",
58                         root_build_dir) + "=third_party/vello/src/lib.rs.h",
59           ] + bazel_args
60  }
61
62  action("compile_vello_rust") {
63    script = "../../gn/bazel_build.py"
64    sources = [
65      "BUILD.bazel",
66      "src/encoding.rs",
67      "src/lib.rs",
68      "src/shaders.rs",
69    ]
70    outputs = [ "$root_out_dir/libvello_rust.a" ]
71    args = [
72             "//third_party/vello:vello_rust",
73             rebase_path("//bazel-bin/third_party/vello/libvello_rust.a",
74                         root_build_dir),
75           ] + bazel_args
76  }
77}
78
79third_party("vello") {
80  # this is where third_party/vello/src/lib.rs.h was generated and exists.
81  public_include_dirs = [ "$root_out_dir" ]
82  libs = [
83    "$root_out_dir/libvello_ffi.a",
84    "$root_out_dir/libvello_rust.a",
85  ]
86  deps = [
87    ":compile_vello_ffi",
88    ":compile_vello_rust",
89  ]
90  public_defines = []
91  if (skia_use_metal) {
92    public_defines += [ "VELLO_MSL_SHADERS=true" ]
93  }
94  if (skia_use_dawn) {
95    public_defines += [ "VELLO_WGSL_SHADERS=true" ]
96  }
97}
98