extern crate bindgen; use std::env; use std::path::PathBuf; fn main() { // Add libelektra's lib directory to rustc's search path println!("cargo:rustc-link-search=@CMAKE_BINARY_DIR@/lib"); // Tell cargo to tell rustc to link the dynamic elektra library. println!("cargo:rustc-link-lib=dylib=elektra-core"); println!("cargo:rustc-link-lib=dylib=elektra-meta"); println!("cargo:rustc-link-lib=dylib=elektra-kdb"); // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. let bindings = bindgen::Builder::default() // The input header we would like to generate // bindings for. .header("wrapper.h") // Include only the necessary functions and enums .allowlist_function("(key|ks|kdb).*") .allowlist_var("(KEY|KDB).*") // bindgen uses clang for anything C-related. // Here we set the necessary include directories // such that any includes in the wrapper can be found. .clang_arg("-I@CMAKE_SOURCE_DIR@/src/include") .clang_arg("-I@CMAKE_BINARY_DIR@/src/include") // 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!"); }