diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-07-06 20:49:05 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-07-06 20:49:05 -0700 |
| commit | 26ffddd7597a5bae094e00fc1b511f3df9411059 (patch) | |
| tree | 6dc467917962dc4581ce2d89ee619be68449dff3 | |
| parent | 5b4b3d5f61c6939b14c3d7d38662f00fc9530f73 (diff) | |
add a build.rs that calls glslang
Force-Push: yes Change-Id: I5a565f3ad343a36ffe17436b337f524805d072f7
| -rw-r--r-- | build.rs | 43 | ||||
| -rw-r--r-- | src/main.rs | 7 |
2 files changed, 47 insertions, 3 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..593ef3f --- /dev/null +++ b/build.rs @@ -0,0 +1,43 @@ +use std::env; +use std::fs; +use std::path::Path; +use std::process::Command; + +fn main() { + match process_all() { + Err(error) => println!("cargo-error={}", error), + _ => { }, + } +} + +fn process_all () -> std::io::Result<()> { + let out_dir = env::var_os("OUT_DIR").unwrap(); + + for input in fs::read_dir("shaders")? { + let input_path = input?.path(); + if !input_path.is_file() { + continue; + } + + let output_path + = Path::new(&out_dir) + .join(format!("{}.spv", + input_path.file_name().unwrap().to_str().unwrap())); + + if !Command::new("glslang") + .arg("-V") + .arg(&input_path) + .arg("-o") + .arg(output_path) + .status()?.success() + { + println!("cargo::error=Failed to compile shader {}", + input_path.display()); + } + + println!("cargo::rerun-if-changed={}", input_path.display()); + } + + Ok(()) +} + diff --git a/src/main.rs b/src/main.rs index 3fe3f66..6c06a26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -773,9 +773,10 @@ impl Surreality { let extent = self.extent.get().unwrap().clone(); let render_pass = self.render_pass.get().unwrap().clone(); - // TODO integrate with Cargo - let vertex_binary = include_bytes!("../vert.spv"); - let fragment_binary = include_bytes!("../frag.spv"); + let vertex_binary = include_bytes!( + concat!(env!("OUT_DIR"), "/shader.vert.spv")); + let fragment_binary = include_bytes!( + concat!(env!("OUT_DIR"), "/shader.frag.spv")); let vertex_module = self.load_spirv_shader_module(vertex_binary)?; let fragment_module = self.load_spirv_shader_module(fragment_binary)?; |