forked from hauleth/libucl-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
52 lines (43 loc) · 1.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
use std::process::Command;
use std::env;
use std::io::ErrorKind;
use std::path::PathBuf;
fn main() {
let mut cflags = env::var("CFLAGS").unwrap_or(String::new());
cflags.push_str(" -fPIC");
let src = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
let dst = PathBuf::from(&env::var("OUT_DIR").unwrap());
let mut cmd = Command::new("./autogen.sh");
cmd.current_dir(&src.join("libucl"));
run(&mut cmd, "autogen.sh");
let mut cmd = Command::new("./configure");
cmd.current_dir(&src.join("libucl"));
cmd.arg(&format!("--prefix={}", dst.display()));
run(cmd.arg("--enable-urls")
.arg("--enable-regex")
.arg("--disable-shared")
.arg("--with-pic"), "configure");
let mut cmd = Command::new("make");
cmd.env("CFLAGS", cflags);
cmd.current_dir(&src.join("libucl"));
run(cmd.arg("install"), "make");
println!("cargo:rustc-link-lib=static=ucl");
println!("cargo:rustc-link-search=native={}", dst.join("lib").display());
}
fn run(cmd: &mut Command, program: &str) {
println!("running: {:?}", cmd);
let status = match cmd.status() {
Ok(status) => status,
Err(ref e) if e.kind() == ErrorKind::NotFound => {
fail(&format!("failed to execute command: {}\nis `{}` not installed?",
e, program));
}
Err(e) => fail(&format!("failed to execute command: {}", e)),
};
if !status.success() {
fail(&format!("command did not execute successfully, got: {}", status));
}
}
fn fail(s: &str) -> ! {
panic!("\n{}\n\nbuild script failed, must exit now", s)
}