xref: /aosp_15_r20/external/flashrom/bindings/rust/libflashrom-sys/build.rs (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)

main()1 fn main() {
2     pkg_config::probe_library("flashrom").unwrap();
3     let bindings = bindgen::Builder::default()
4         .header("../../../include/libflashrom.h")
5         // Tell cargo to invalidate the built crate whenever any of the
6         // included header files changed.
7         .parse_callbacks(Box::new(bindgen::CargoCallbacks))
8         // only generate the flashrom functions and used types.
9         .allowlist_function("flashrom_.*")
10         // newtype enums provide type checking without the UB potential of rust enums.
11         .default_enum_style(bindgen::EnumVariation::NewType { is_bitfield: false })
12         // We use constified enum for flashrom_log_level to allow '<' comparison.
13         .constified_enum("flashrom_log_level")
14         .prepend_enum_name(false)
15         .derive_copy(false)
16         .must_use_type("flashrom_wp_result")
17         // Avoid some va_list related functionality that is not easy to use in rust.
18         .blocklist_function("flashrom_set_log_callback")
19         .blocklist_type("flashrom_log_callback")
20         .blocklist_type("va_list")
21         .blocklist_type("__builtin_va_list")
22         .blocklist_type("__va_list_tag")
23         .size_t_is_usize(true)
24         .generate()
25         .expect("Unable to generate bindings");
26 
27     // Write the bindings to the $OUT_DIR/bindings.rs file.
28     let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
29     bindings
30         .write_to_file(out_path.join("bindings.rs"))
31         .expect("Couldn't write bindings!");
32 }
33