-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.rs
68 lines (65 loc) · 1.99 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
extern crate bindgen;
extern crate cc;
use std::env::var;
use std::path::Path;
fn main() {
use bindgen::builder;
// Configure and generate bindings.
let bindings = builder()
.header("unqlite/unqlite.h")
.generate()
.expect("generate unqlite bindings");
// Write the generated bindings to an output file.
bindings
.write_to_file(Path::new(&var("OUT_DIR").expect("OUT_DIR should be exist")).join("ffi.rs"))
.expect("write to source file");
cc::Build::new()
.file("unqlite/unqlite.c")
.warnings(false)
.if_enable_threads()
.if_jx9_diable_builtin_func()
.if_jx9_enable_math_func()
.if_jx9_disable_disk_io()
.if_enable_jx9_hash_io()
.compile("libunqlite.a");
}
trait ConfigExt {
fn if_enable_threads(&mut self) -> &mut Self {
self
}
fn if_jx9_diable_builtin_func(&mut self) -> &mut Self {
self
}
fn if_jx9_enable_math_func(&mut self) -> &mut Self {
self
}
fn if_jx9_disable_disk_io(&mut self) -> &mut Self {
self
}
fn if_enable_jx9_hash_io(&mut self) -> &mut Self {
self
}
}
impl ConfigExt for cc::Build {
#[cfg(feature = "enable-threads")]
fn if_enable_threads(&mut self) -> &mut Self {
self.define("UNQLITE_ENABLE_THREADS", None)
.flag("-lpthread")
}
#[cfg(feature = "jx9-disable-builtin-func")]
fn if_jx9_diable_builtin_func(&mut self) -> &mut Self {
self.define("JX9_DISABLE_BUILTIN_FUNC", None)
}
#[cfg(feature = "jx9-enable-math-func")]
fn if_jx9_enable_math_func(&mut self) -> &mut Self {
self.define("JX9_ENABLE_MATH_FUNC", None)
}
#[cfg(feature = "jx9-disable-disk-io")]
fn if_jx9_disable_disk_io(&mut self) -> &mut Self {
self.define("JX9_DISABLE_DISK_IO", None)
}
#[cfg(feature = "enable-jx9-hash-io")]
fn if_enable_jx9_hash_io(&mut self) -> &mut Self {
self.define("UNQLITE_ENABLE_JX9_HASH_IO", None)
}
}