forked from windy1/avahi-sys
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
46 lines (36 loc) · 1.32 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
extern crate bindgen;
use std::env;
use std::path::Path;
fn main() {
if !std::env::var("TARGET").unwrap().contains("-linux") {
return;
}
println!("cargo:rustc-link-lib=avahi-client");
println!("cargo:rustc-link-lib=avahi-common");
generate_bindings(env::var("OUT_DIR").expect("Out Dir variable not set"));
}
#[cfg(not(feature = "buildtime_bindgen"))]
fn generate_bindings(out_path: impl AsRef<Path>) {
let in_path = env::var("AVAHI_SYS_BINDINGS_FILE").expect(
"AVAHI_SYS_BINDINGS_FILE should be populated if buildtime_bindgen feature is not enabled",
);
std::fs::copy(in_path, out_path.as_ref().join("bindings.rs"))
.expect("Failed to copy bindings to desintation");
}
#[cfg(feature = "buildtime_bindgen")]
fn generate_bindings(out_path: impl AsRef<Path>) {
println!("cargo:rerun-if-changed=wrapper.h");
let mut builder = bindgen::Builder::default();
if cfg!(feature = "verbose_build") {
builder = builder.clang_arg("-v");
}
builder
.header("wrapper.h")
.ctypes_prefix("::libc")
.size_t_is_usize(true)
.bitfield_enum("AvahiClientFlags")
.generate()
.expect("failed to generate bindings")
.write_to_file(out_path.as_ref().join("bindings.rs"))
.expect("failed to write bindings to file");
}