forked from vaind/objectbox-rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
37 lines (33 loc) · 1.29 KB
/
Copy pathbuild.rs
File metadata and controls
37 lines (33 loc) · 1.29 KB
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
36
37
extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
// Tell cargo to tell rustc to link the objectbox shared library.
println!("cargo:rustc-link-lib=objectbox");
// 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()
// The input header we would like to generate bindings for.
.header("src/objectbox.h")
// Some settings
.whitelist_function("obx_.*")
.whitelist_type("OBX_.*")
.whitelist_var("OBX_.*")
.prepend_enum_name(false)
.derive_copy(false)
.derive_debug(false)
.derive_default(false)
.rustfmt_bindings(true)
.generate_comments(false) // generated comments breaks rust
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the src/c_bindings.rs file.
let cargo_manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let target_path = cargo_manifest_dir.join("src/c_bindings.rs");
bindings
.write_to_file(target_path.as_path())
.expect("Couldn't write bindings!");
}