2022-12-06 09:30:48 +11:00
|
|
|
use std::{env, fs};
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{BufWriter, Write};
|
2023-01-14 08:05:13 +11:00
|
|
|
use std::path::PathBuf;
|
2022-12-06 09:30:48 +11:00
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
// Do not update files on docsrs
|
|
|
|
if env::var("DOCS_RS").is_ok() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create headers.
|
|
|
|
let crate_dir = env::var("CRATE_MANIFEST_DIR").unwrap();
|
|
|
|
let mut buf = BufWriter::new(Vec::new());
|
|
|
|
cbindgen::generate(crate_dir)
|
|
|
|
.expect("Unable to generate bindings")
|
|
|
|
.write(&mut buf);
|
|
|
|
|
|
|
|
let bytes = buf.into_inner().expect("Unable to extract bytes");
|
|
|
|
let string = String::from_utf8(bytes).expect("Unable to create string");
|
|
|
|
File::create(PathBuf::from(env::var("CRATE_OUT_DIR").unwrap()).join("librashader.h"))
|
|
|
|
.expect("Unable to open file")
|
|
|
|
.write_all(string.as_bytes())
|
|
|
|
.expect("Unable to write bindings.");
|
|
|
|
|
|
|
|
|
|
|
|
if cfg!(target_os = "linux") {
|
2023-01-14 16:32:05 +11:00
|
|
|
let artifacts = &["liblibrashader_capi.so", "liblibrashader_capi.a"];
|
2022-12-06 09:30:48 +11:00
|
|
|
for artifact in artifacts {
|
|
|
|
let ext = artifact.strip_prefix("lib").unwrap();
|
2023-01-15 09:43:58 +11:00
|
|
|
let ext = ext.replace("_capi", "");
|
2022-12-06 09:30:48 +11:00
|
|
|
fs::rename(PathBuf::from(env::var("CRATE_OUT_DIR").unwrap()).join(artifact), PathBuf::from(env::var("CRATE_OUT_DIR").unwrap()).join(ext)).unwrap();
|
|
|
|
}
|
|
|
|
}
|
2023-01-14 16:32:05 +11:00
|
|
|
|
|
|
|
if cfg!(target_os = "windows") {
|
|
|
|
let artifacts = &["librashader_capi.dll", "librashader_capi.lib", "librashader_capi.d", "librashader_capi.dll.exp", "librashader_capi.dll.lib", "librashader_capi.pdb"];
|
|
|
|
for artifact in artifacts {
|
|
|
|
let ext = artifact.replace("_capi", "");
|
|
|
|
fs::rename(PathBuf::from(env::var("CRATE_OUT_DIR").unwrap()).join(artifact), PathBuf::from(env::var("CRATE_OUT_DIR").unwrap()).join(ext)).unwrap();
|
|
|
|
}
|
|
|
|
}
|
2022-12-06 09:30:48 +11:00
|
|
|
}
|