1# This file will be copied into //third_party/externals/vello via the new_local_repository 2# rule in WORKSPACE.bazel, so all files should be relative to that path. 3load("@rules_rust//cargo:defs.bzl", "cargo_build_script") 4load("@rules_rust//rust:defs.bzl", "rust_library") 5 6# The vello repository is organized as a workspace where the vello_shaders and vello_encoding crates 7# live in //vello/vello_shaders and //vello/vello_encoding, respectively. The WGSL shader source 8# files live under //vello/vello_shaders/shader. 9# 10# Normally we would simply list the following dependencies in our Cargo.toml file and Bazel's 11# `crates_repository` rule would automatically create targets for both crates that could be compiled 12# out-of-the-box: 13# 14# vello_shaders = { git = "https://skia.googlesource.com/external/github.com/linebender/vello", rev = "123456" } 15# vello_encoding = { git = "https://skia.googlesource.com/external/github.com/linebender/vello", rev = "123456" } 16# 17# However, using that setup I (armansito@) haven't found a good way to both: 18# 19# (a) Conditionally toggle the "wgsl" and "msl" cargo features for these libraries. Bazel wants 20# config settings and cargo features to be declared by the relevant library rules and not 21# consumers of that library; 22# (b) Support local iteration using a cargo "path" dependency. 23# 24# Until we find a way around these limitations, we maintain our own build rules for the vello crates 25# here. 26 27rust_library( 28 name = "vello_encoding", 29 srcs = glob( 30 include = ["vello_encoding/src/**/*.rs"], 31 allow_empty = False, 32 ), 33 crate_features = ["bump_estimate"], 34 visibility = ["//visibility:public"], 35 deps = [ 36 "@vello_deps//:bytemuck", 37 "@vello_deps//:peniko", 38 ], 39) 40 41# The following setting is used to enable the WGSL -> MSL translation feature. Pass 42# `--define VELLO_MSL_SHADERS=true` to Bazel to bundle vello shaders in the Metal Shading Language. 43config_setting( 44 name = "msl_shaders", 45 values = { 46 "define": "VELLO_MSL_SHADERS=true", 47 }, 48) 49 50# Pass `--define VELLO_WGSL_SHADERS=true` to Bazel to bundle the vello shaders in their native 51# WebGPU Shading Language. 52config_setting( 53 name = "wgsl_shaders", 54 values = { 55 "define": "VELLO_WGSL_SHADERS=true", 56 }, 57) 58 59rust_library( 60 name = "vello_shaders", 61 srcs = glob( 62 include = ["vello_shaders/src/**/*.rs"], 63 allow_empty = False, 64 ), 65 crate_features = select({ 66 ":msl_shaders": ["msl"], 67 "//conditions:default": [], 68 }) + select({ 69 ":wgsl_shaders": ["wgsl"], 70 "//conditions:default": [], 71 }), 72 visibility = ["//visibility:public"], 73 deps = [":vello_shaders_build_script"], 74) 75 76cargo_build_script( 77 name = "vello_shaders_build_script", 78 srcs = [ 79 "vello_shaders/build.rs", 80 "vello_shaders/src/compile/mod.rs", 81 "vello_shaders/src/compile/msl.rs", 82 "vello_shaders/src/compile/permutations.rs", 83 "vello_shaders/src/compile/preprocess.rs", 84 "vello_shaders/src/types.rs", 85 ], 86 build_script_env = { 87 "UNSTABLE_BAZEL_VELLO_SHADERS_CRATE_MANIFEST_PATH": "$(execpath vello_shaders/Cargo.toml)", 88 }, 89 crate_features = select({ 90 ":msl_shaders": ["msl"], 91 "//conditions:default": [], 92 }) + select({ 93 ":wgsl_shaders": ["wgsl"], 94 "//conditions:default": [], 95 }), 96 crate_root = "vello_shaders/build.rs", 97 data = [ 98 # This is needed to define BAZEL_CRATE_MANIFEST_PATH above. 99 "vello_shaders/Cargo.toml", 100 "vello_shaders/shader/permutations", 101 ] + glob( 102 include = [ 103 "vello_shaders/shader/**/*.wgsl", 104 ], 105 allow_empty = False, 106 ), 107 deps = [ 108 "@vello_deps//:naga", 109 "@vello_deps//:regex", 110 "@vello_deps//:thiserror", 111 ], 112) 113