Skip to content

Commit ce2a362

Browse files
LegNeatoclaude
andcommitted
Support SPIRV_HEADERS_PATH env var for git dependency usage
When spirv-tools-core is used as a git dependency, the SPIRV-Headers submodule isn't available. This adds support for the SPIRV_HEADERS_PATH environment variable to specify an alternative location for the headers. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 59f2f49 commit ce2a362

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

rust/spirv-tools-core/build.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,24 @@ fn bit_enum_ident(enumerant: &str) -> String {
107107

108108
fn main() {
109109
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR");
110-
let grammar_path = PathBuf::from(&manifest_dir)
111-
.join("../../external/spirv-headers/include/spirv/unified1/spirv.core.grammar.json");
112-
let grammar_contents =
113-
fs::read_to_string(&grammar_path).expect("failed to read spirv.core.grammar.json");
110+
// Allow overriding the SPIRV-Headers path via environment variable for standalone builds.
111+
// When used as a git dependency, the submodule isn't available, so users can set
112+
// SPIRV_HEADERS_PATH to point to their local SPIRV-Headers checkout.
113+
let grammar_path = if let Ok(headers_path) = env::var("SPIRV_HEADERS_PATH") {
114+
println!("cargo:rerun-if-env-changed=SPIRV_HEADERS_PATH");
115+
PathBuf::from(headers_path).join("include/spirv/unified1/spirv.core.grammar.json")
116+
} else {
117+
PathBuf::from(&manifest_dir)
118+
.join("../../external/spirv-headers/include/spirv/unified1/spirv.core.grammar.json")
119+
};
120+
let grammar_contents = fs::read_to_string(&grammar_path).unwrap_or_else(|_| {
121+
panic!(
122+
"failed to read spirv.core.grammar.json from {:?}. \
123+
If building as a git dependency, set SPIRV_HEADERS_PATH to point to a \
124+
SPIRV-Headers checkout.",
125+
grammar_path
126+
)
127+
});
114128
let grammar: CoreGrammar =
115129
serde_json::from_str(&grammar_contents).expect("failed to parse core grammar");
116130

0 commit comments

Comments
 (0)