Florian Briand
7ac8215382
- Création de la crates/fsv-sys - Ajout des headers de la FSV 1.40.14.13 dans crates/fsv-sys/vendor - Génération des bindings depuis ces headers avec bindgen - Implémentation d'une structure de loading de la librairie au runtime - Implémentation d'une macro permettant de générer facilement la couche d'accès aux fonctions de la librairie
62 lines
2.3 KiB
Rust
62 lines
2.3 KiB
Rust
use std::{env, path::PathBuf};
|
|
|
|
fn main() {
|
|
// // TODO: make the path dynamic
|
|
// println!("cargo:rustc-link-search=native=/home/florianbriand/TMP/SESAM-VITALE/FSV_1.40.1317_Linux/x86_64/Release/installeur/opt/santesocial/fsv/1.40.13/lib");
|
|
|
|
// 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!");
|
|
} |