在内核中引入cbindgen,生成rust-C的FFI (#81)

* 解决codeql失败问题

* new: 为内核引入cbindgen
This commit is contained in:
login
2022-11-11 22:21:44 +08:00
committed by GitHub
parent 2813126e31
commit 2aaf7808ef
6 changed files with 651 additions and 78 deletions

View File

@ -1,12 +1,19 @@
extern crate bindgen;
extern crate cbindgen;
use ::std::env;
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");
let binding_file_path = "src/include/bindings/bindings.rs";
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let out_path = PathBuf::from(String::from("src/include/bindings/"));
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
@ -30,11 +37,12 @@ fn main() {
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(String::from("."));
bindings
.write_to_file(out_path.join(binding_file_path))
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
cbindgen::generate(crate_dir)
.unwrap()
.write_to_file(out_path.join("bindings.h"));
}