-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
86 lines (79 loc) · 2.61 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
use std::env;
use std::path::PathBuf;
fn main() {
// enabling requested features
let journald_enabled = if cfg!(feature = "journald") {
"ON"
} else {
"OFF"
};
let network_enabled = if cfg!(feature = "network") {
"ON"
} else {
"OFF"
};
let socket_enabled = if cfg!(feature = "socket") {
"ON"
} else {
"OFF"
};
let sqlite_enabled = if cfg!(feature = "sqlite") {
"ON"
} else {
"OFF"
};
let wel_enabled = if cfg!(feature = "wel") { "ON" } else { "OFF" };
let stumpless_out = cmake::Config::new("stumpless")
.define("BUILD_SHARED_LIBS", "OFF")
.define("ENABLE_JOURNALD_TARGETS", journald_enabled)
.define("ENABLE_NETWORK_TARGETS", network_enabled)
.define("ENABLE_SOCKET_TARGETS", socket_enabled)
.define("ENABLE_SQLITE3_TARGETS", sqlite_enabled)
.define("ENABLE_WINDOWS_EVENT_LOG_TARGETS", wel_enabled)
.build();
println!(
"cargo:rustc-link-search=native={}/lib",
stumpless_out.display()
);
println!("cargo:rustc-link-lib=stumpless");
if cfg!(feature = "journald") {
println!("cargo:rustc-link-lib=systemd");
}
if cfg!(feature = "sqlite") {
println!("cargo:rustc-link-lib=sqlite3");
}
if cfg!(feature = "wel") {
println!("cargo:rustc-link-lib=ktmw32");
}
let bindings_builder = bindgen::Builder::default()
.header(format!("{}/include/stumpless.h", stumpless_out.display()))
.clang_arg(format!("-I{}/include/", stumpless_out.display()))
.allowlist_function("stump.*")
.allowlist_type("stump.*")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
let bindings = bindings_builder
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
if cfg!(feature = "wel") {
println!(
"cargo:rustc-env=STUMPLESS_DEFAULT_EVENTS_RC_PATH={}",
stumpless_out
.join("build")
.join("default_events.rc")
.to_str()
.expect("couldn't create default_events.rc path")
);
println!(
"cargo:rustc-env=STUMPLESS_DEFAULT_EVENTS_BIN_PATH={}",
stumpless_out
.join("build")
.join("default_events_MSG00409.bin")
.to_str()
.expect("couldn't create default_events_MSG00409.bin path")
);
}
}