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