-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
96 lines (83 loc) · 3.45 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
91
92
93
94
95
96
// jkcoxson
extern crate bindgen;
use std::{env, fs::canonicalize, path::PathBuf};
fn main() {
// Tell cargo to invalidate the built crate whenever build files change
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rerun-if-changed=build.rs");
////////////////////////////
// BINDGEN GENERATION //
////////////////////////////
if cfg!(feature = "pls-generate") {
// Get gnutls path per OS
let gnutls_path = match env::consts::OS {
"linux" => "/usr/include",
"macos" => "/opt/homebrew/include",
"windows" => {
panic!("Generating bindings on Windows is broken, pls remove the pls-generate feature.");
}
_ => panic!("Unsupported OS"),
};
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
// Include in clang build
.clang_arg(format!("-I{}", gnutls_path))
// 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!");
}
if cfg!(feature = "vendored") {
// Change current directory to OUT_DIR
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
env::set_current_dir(out_path).unwrap();
// Clone the vendored libraries
repo_setup("https://github.com/libimobiledevice/libplist.git");
// Build those bad bois
let dst = autotools::Config::new("libplist")
.without("cython", None)
.build();
println!(
"cargo:rustc-link-search=native={}",
dst.join("lib").display()
);
println!("cargo:rustc-link-lib=static=plist-2.0");
} else {
// Check if folder ./override exists
let override_path = PathBuf::from("./override").join(env::var("TARGET").unwrap());
if override_path.exists() {
println!(
"cargo:rustc-link-search={}",
canonicalize(&override_path).unwrap().display()
);
}
println!("cargo:rustc-link-search=/usr/local/lib");
println!("cargo:rustc-link-search=/usr/lib");
println!("cargo:rustc-link-search=/opt/homebrew/lib");
println!("cargo:rustc-link-search=/usr/local/opt/libimobiledevice/lib");
println!("cargo:rustc-link-search=/usr/local/opt/libusbmuxd/lib");
println!("cargo:rustc-link-search=/usr/local/opt/libimobiledevice-glue/lib");
}
}
fn repo_setup(url: &str) {
let mut cmd = std::process::Command::new("git");
cmd.arg("clone");
cmd.arg(url);
cmd.output().unwrap();
env::set_current_dir(url.split('/').last().unwrap().replace(".git", "")).unwrap();
env::set_var("NOCONFIGURE", "1");
let mut cmd = std::process::Command::new("./autogen.sh");
let _ = cmd.output();
env::remove_var("NOCONFIGURE");
env::set_current_dir("..").unwrap();
}