-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.rs
36 lines (30 loc) · 864 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use glob::glob;
use std::path;
use std::process::Command;
fn compile_shader(shaderpath: path::PathBuf)
{
let glsl_name = shaderpath.into_os_string().into_string().unwrap();
let spv_name = glsl_name.replace(".", "_") + ".spv";
let output = Command::new("glslangValidator")
.args(&["-V", glsl_name.as_str(), "-o", spv_name.as_str()])
.output()
.expect("Could not execute glslangValidator, is it in PATH?");
if !output.status.success()
{
panic!("Failed to build shader: {}", String::from_utf8_lossy(&output.stdout));
}
}
fn main()
{
// Only run if shaders have changed
println!("cargo:rerun-if-changed=shaders");
// Build shaders
for vertpath in glob("shaders/*.vert").unwrap().filter_map(Result::ok)
{
compile_shader(vertpath);
}
for fragpath in glob("shaders/*.frag").unwrap().filter_map(Result::ok)
{
compile_shader(fragpath);
}
}