Krys4lide/crates/fsv-sys/build.rs

59 lines
2.1 KiB
Rust
Raw Normal View History

use std::{env, path::PathBuf};
fn main() {
// Configure for various targets
let target_code;
// Use CARGO configuration env Variable, because !cfg(target_os) is not available in build.rs
// Source: https://kazlauskas.me/entries/writing-proper-buildrs-scripts
let target = env::var("TARGET").expect("TARGET not set");
let target_os = env::var("CARGO_CFG_TARGET_OS");
println!("Target: {:?}", target);
match target_os.as_ref().map(|x| &**x) {
Ok("linux") => {
println!("Building for Linux");
// lib_name = "ssvlux64";
target_code = "linux";
},
Ok("windows") => {
println!("Building for Windows");
// lib_name = "Ssvw64";
target_code = "win";
},
Ok("macos") => {
println!("Building for MacOS");
// lib_name = "ssvosx";
target_code = "macosx";
},
tos => panic!("Unsupported target_os {:?}", tos),
}
// Link the library
// println!("cargo:rustc-link-lib={}", lib_name);
// Build the bindings
let wrapper_path = format!("vendor/fsv/1.40.14.13/includes/wrapper.{}.h", target_code);
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header(wrapper_path)
// To generate the bindings for specific target
.clang_arg(format!("--target={}", target))
// Limit the bindings generation to the SSV_ prefix
.allowlist_item("SSV_.*")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}