-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
71 lines (61 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::ffi::OsStr;
use std::fs::read_dir;
use std::io::Result;
use std::process::Command;
use std::path::PathBuf;
use std::env;
fn xcrun(cmd: &str) -> Command {
let mut out = Command::new("xcrun");
out.args([
"-sdk",
"macosx",
cmd
]);
out
}
fn main() -> Result<()> {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let metal_files: Vec<_> = read_dir("metal/")?
.filter_map(|f| f.ok())
.map(|de| de.path())
.filter(|f| {
if let Some(ext) = f.extension().and_then(OsStr::to_str) {
matches!(ext, "metal" | "hpp")
} else {
false
}
})
.collect();
metal_files.iter().for_each(|p| {
println!("cargo:rerun-if-changed={}", p.to_str().unwrap());
});
let c_args: Vec<_> = metal_files
.iter()
.filter(|p| {
p
.extension()
.and_then(OsStr::to_str)
.map(|ext| ext == "metal")
.unwrap_or_default()
})
.map(|p| p.to_str().unwrap())
.collect();
let mut child = xcrun("metal")
.arg("-o")
.arg(out_dir.join("metalsha.ir"))
.arg("-c")
.args(&c_args)
.spawn()?;
if !child.wait()?.success() {
todo!();
}
xcrun("metallib")
.arg("-o")
.arg(out_dir.join("metalsha.metallib"))
.arg(out_dir.join("metalsha.ir"))
.spawn()?;
if !child.wait()?.success() {
todo!();
}
Ok(())
}