/
build.rs
35 lines (30 loc) · 1.25 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2022 Sebastian Ramacher
// SPDX-License-Identifier: LGPL-3.0-or-later
use std::env;
use std::path::PathBuf;
fn main() {
system_deps::Config::new().probe().unwrap();
// Invalidate the built crate whenever the wrapper and the build script changes.
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rerun-if-changed=build.rs");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
// Invalidate the built crate whenever any of the included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.use_core()
.blocklist_function("dpkg_set_report_buffer")
.blocklist_type("(_IO_)?FILE")
.blocklist_type("_IO_.*")
.allowlist_function("dpkg_.*")
.rustified_enum("dpkg_relation")
.rustified_enum("dpkg_arch_type")
.rustified_enum("dpkg_msg_type")
// Finish the builder and generate the bindings.
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}