-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
90 lines (85 loc) · 3 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
extern crate bindgen;
extern crate fs_extra;
use fs_extra::dir::{copy, CopyOptions};
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let mut options = CopyOptions::new();
options.skip_exist = true;
options.content_only = true;
copy("TileDB", &out_dir, &options).unwrap();
let current_dir = env::current_dir().unwrap();
Command::new("mkdir")
.arg("-p")
.arg(format!("{}/build", &out_dir))
.arg(".")
.status()
.expect("failed to run bootstrap");
assert!(env::set_current_dir(Path::new(&format!("{}/build", &out_dir))).is_ok());
Command::new("../bootstrap")
.arg("--enable-s3")
.status()
.expect("failed to run bootstrap");
Command::new("make")
.arg("-j")
.arg("12")
.status()
.expect("failed to run make");
Command::new("make")
.arg("install-tiledb")
.status()
.expect("failed to run make");
assert!(env::set_current_dir(current_dir).is_ok());
// Tell cargo to tell rustc to link the tiledb library.
println!("cargo:rustc-link-lib=dylib=tiledb");
// search for the library in a custom location
println!(
"cargo:rustc-link-search=native={}",
format!("{}/dist/lib", &out_dir),
);
// Tell cargo to invalidate the built crate whenever the wrapper changes
//println!("cargo:rerun-if-changed=wrapper.hpp");
// 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("wrapper.hpp")
.rustified_enum(".*")
.generate_inline_functions(true)
.clang_args(vec![
format!("-I{}/dist/include", &out_dir),
"-std=c++11".to_string(),
])
.enable_cxx_namespaces()
.opaque_type("std::.*")
.blocklist_type("int_type")
.blocklist_type("off_type")
.allowlist_type("tiledb.*")
.module_raw_lines(
"root",
[
"pub type int_type = ::std::os::raw::c_int;",
"pub type off_type = root::std::streamoff;",
]
.iter()
.map(|s| *s),
)
.derive_copy(false)
.allowlist_function("tiledb.*")
// 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");
// 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!");
}