build.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. extern crate bindgen;
  2. extern crate cbindgen;
  3. use ::std::env;
  4. use std::path::PathBuf;
  5. fn main() {
  6. // Tell cargo to look for shared libraries in the specified directory
  7. println!("cargo:rustc-link-search=src");
  8. println!("cargo:rerun-if-changed=src/include/bindings/wrapper.h");
  9. // let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
  10. let out_path = PathBuf::from(String::from("src/include/bindings/"));
  11. // The bindgen::Builder is the main entry point
  12. // to bindgen, and lets you build up options for
  13. // the resulting bindings.
  14. {
  15. let bindings = bindgen::Builder::default()
  16. .clang_arg("-I./src")
  17. .clang_arg("-I./src/include")
  18. .clang_arg("-I./src/arch/x86_64/include") // todo: 当引入多种架构之后,需要修改这里,对于不同的架构编译时,include不同的路径
  19. // The input header we would like to generate
  20. // bindings for.
  21. .header("src/include/bindings/wrapper.h")
  22. .blocklist_file("src/include/bindings/bindings.h")
  23. .clang_arg("--target=x86_64-none-none")
  24. .clang_arg("-v")
  25. // 使用core,并将c语言的类型改为core::ffi,而不是使用std库。
  26. .use_core()
  27. .ctypes_prefix("::core::ffi")
  28. .generate_inline_functions(true)
  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. }