build.rs

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2024 May 19 15:49
Editor
Edited
Edited
2024 May 19 16:0
Refs
Refs
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

build.rs
binding in lib.rs

  • lib.rs file can include the generated bindings and allows the Rust code to interact with the C functions.
  • The #![allow(...)] attributes are used to suppress warnings about naming conventions.
  • include!(concat!(env!("OUT_DIR"), "/bindings.rs"));: This line includes the generated bindings file, which is created by bindgen during the build process.

Source code usage

  • The extern "C" block declares the image_classifier function from the Darknet library, making it available for use in Rust.
  • This function can be called from the Rust code as if it were a normal Rust function.
 
 
 
 
 
 
 

Recommendations