The
build.rs file’s main function is a build script that configures the Rust compiler to link against the dynamic library by telling cargo through standard output (print).- dynamic library path:
cargo:rustc-link-search=native=$PATH
- dynamic library name:
cargo:rustc-link-lib=dylib=$NAME
Bindgen
- library path
- wrapper header path
- output binding rust file
let bindings = bindgen::Builder::default() // The input header we would like to generate // bindings for. .header("wrapper.h") .clang_arg("-v") .derive_debug(true) .derive_default(true) // 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!");

Seonglae Cho