Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vello_shaders] Bring back the Bazel build hack #621

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion vello_shaders/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,24 @@ fn postprocess(wgsl: &str) -> String {
// NOTE: Embedding build environment info into the code makes reproducible builds trickier.
pub fn shader_dir() -> &'static PathBuf {
static SHADER_DIR: OnceLock<PathBuf> = OnceLock::new();
SHADER_DIR.get_or_init(|| Path::new(env!("CARGO_MANIFEST_DIR")).join("shader"))
SHADER_DIR.get_or_init(|| manifest_dir().join("shader"))
}

// In a regular cargo build the manifest directory is simply given by CARGO_MANIFEST_DIR.
//
// Skia, an external consumer of this crate, uses Bazel rules to compile Rust code. Due to
// limitations in Bazel's rust support, Skia maintains its own build definitions
// (https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/bazel/external/vello/BUILD.bazel).
//
// Because of the current setup, Bazel sets CARGO_MANIFEST_DIR to the workspace root instead of the
// actual crate being built. This could be improved but until then, we work around this by allowing
// the absolute path to the vello_shader crate's manifest to be specified using the
// `BAZEL_CRATE_MANIFEST_PATH` build script environment variable. This should never be set when
// using cargo.
fn manifest_dir() -> PathBuf {
use std::env;
env::var_os("BAZEL_CRATE_MANIFEST_PATH")
DJMcNab marked this conversation as resolved.
Show resolved Hide resolved
.and_then(|p| Path::new(&p).parent().map(|p| p.to_owned()))
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")))
.to_path_buf()
}