Add zerocopy instance to raw bindings struct
This will come in handy later, when we integrate harmonia. It is a very stable thing to do.
This commit is contained in:
parent
538f29a390
commit
0eb73977ef
3 changed files with 39 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ path = "src/lib.rs"
|
|||
|
||||
[dependencies]
|
||||
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
|
||||
zerocopy = { version = "0.8", features = ["derive"] }
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.69"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,22 @@ impl bindgen::callbacks::ParseCallbacks for StripNixPrefix {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct AddZerocopyDerives {}
|
||||
impl bindgen::callbacks::ParseCallbacks for AddZerocopyDerives {
|
||||
fn add_derives(&self, info: &bindgen::callbacks::DeriveInfo<'_>) -> Vec<String> {
|
||||
if info.name == "store_path_hash_part" {
|
||||
vec![
|
||||
"zerocopy::FromBytes".to_string(),
|
||||
"zerocopy::IntoBytes".to_string(),
|
||||
"zerocopy::Immutable".to_string(),
|
||||
]
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=include/nix-c-store.h");
|
||||
println!("cargo:rustc-link-lib=nixstorec");
|
||||
|
|
@ -29,6 +45,7 @@ fn main() {
|
|||
.clang_args(args)
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
.parse_callbacks(Box::new(StripNixPrefix))
|
||||
.parse_callbacks(Box::new(AddZerocopyDerives {}))
|
||||
// Blocklist symbols from nix-bindings-util-sys
|
||||
.blocklist_file(".*nix_api_util\\.h")
|
||||
.generate()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue