build.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extern crate bindgen;
  2. // use ::std::env;
  3. use std::path::PathBuf;
  4. fn main() {
  5. // Tell cargo to look for shared libraries in the specified directory
  6. println!("cargo:rustc-link-search=src");
  7. println!("cargo:rerun-if-changed=src/include/internal/bindings/wrapper.h");
  8. // let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
  9. let out_path = PathBuf::from(String::from("src/include/internal/bindings/"));
  10. // The bindgen::Builder is the main entry point
  11. // to bindgen, and lets you build up options for
  12. // the resulting bindings.
  13. {
  14. let bindings = bindgen::Builder::default()
  15. .clang_arg("-I./src/include")
  16. .clang_arg("-I./src/include/export") // todo: 当引入多种架构之后,需要修改这里,对于不同的架构编译时,include不同的路径
  17. // The input header we would like to generate
  18. // bindings for.
  19. .header("src/include/internal/bindings/wrapper.h")
  20. .clang_arg("--target=x86_64-none-none")
  21. .clang_arg("-v")
  22. // 使用core,并将c语言的类型改为core::ffi,而不是使用std库。
  23. .use_core()
  24. .ctypes_prefix("::core::ffi")
  25. .generate_inline_functions(true)
  26. .raw_line("#![allow(dead_code)]")
  27. .raw_line("#![allow(non_upper_case_globals)]")
  28. .raw_line("#![allow(non_camel_case_types)]")
  29. // Tell cargo to invalidate the built crate whenever any of the
  30. // included header files changed.
  31. .parse_callbacks(Box::new(bindgen::CargoCallbacks))
  32. // Finish the builder and generate the bindings.
  33. .generate()
  34. // Unwrap the Result and panic on failure.
  35. .expect("Unable to generate bindings");
  36. bindings
  37. .write_to_file(out_path.join("bindings.rs"))
  38. .expect("Couldn't write bindings!");
  39. }
  40. }