-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.rs
47 lines (43 loc) · 1.64 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
use std::env;
use std::fs;
use std::path::Path;
use std::process::{Command, Stdio};
fn main() {
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
#[cfg(target_os = "linux")]
let glslang_path = Path::new(&manifest_dir).join("tools/glslangValidator_unix");
#[cfg(target_os = "macos")]
let glslang_path = Path::new(&manifest_dir).join("tools/glslangValidator");
#[cfg(target_os = "windows")]
let glslang_path = Path::new(&manifest_dir).join("tools/glslangValidator.exe");
let shader_dir = Path::new(&manifest_dir).join("shaders");
let shaders = fs::read_dir(&shader_dir).unwrap();
let mut file_path;
let mut extension;
for shader in shaders {
if let Ok(shader) = shader {
file_path = shader.path();
extension = file_path.extension().unwrap().to_str().unwrap();
if extension == "vert" || extension == "frag" {
let mut glslang_cmd = Command::new(&glslang_path);
glslang_cmd
.arg("-V")
.arg("-o")
.arg(&format!("{}.spv", file_path.to_str().unwrap()))
.arg(&file_path);
if glslang_cmd
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.unwrap()
.code()
.unwrap()
!= 0
{
panic!("Error while compiling spirv: {:?}", file_path);
};
println!("cargo:rerun-if-changed={}", file_path.to_str().unwrap());
}
}
}
}