rFactor2_vk_hud/build.rs

43 lines
1.2 KiB
Rust

use std::{fs::File, io::Write, path::Path, process::Command, str::from_utf8};
const VK_INCLUDE: &str = "/usr/include/vulkan";
const VK_HEADER: &[&str] = &[
"vulkan_core.h",
"vulkan_xcb.h",
"vulkan_xlib.h",
"vulkan_wayland.h",
];
const FN_PREFIX: &str = "PFN_";
fn main() {
let mut fns = Vec::new();
for header in VK_HEADER {
Command::new("ctags")
.arg("--help")
.output()
.expect("Failed to execute ctags. Maybe you need to install it first?");
let output = Command::new("ctags")
.arg("-x")
.arg("--c-types=t")
.arg(format!("{}/{}", VK_INCLUDE, header))
.output()
.expect(&format!("failed to open file {}/{}", VK_INCLUDE, header));
let output_splits = from_utf8(&output.stdout).unwrap().split_whitespace();
for split in output_splits {
if split.starts_with(FN_PREFIX) {
fns.push(split.trim_start_matches(FN_PREFIX).to_string())
}
}
}
let path = Path::new("vk_functions");
let mut file = File::create(path).unwrap();
for func in fns {
file.write_all(format!("{}\n", func).as_bytes()).unwrap();
}
}