-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
59 lines (51 loc) · 1.89 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
use std::env;
use std::fs::read_to_string;
use std::process::Command;
fn main() {
const OUT_DIR: &str = "build";
const C_FILE_DIR: &str = "vips";
const C_FILES: &[&str] = &[
"flux_v_text.c",
"flux_v_vips_util.c",
"flux_v_conversion.c",
"flux_v_edgedetect.c",
];
let _ = std::fs::create_dir(&format!("./{}", OUT_DIR));
let workspace = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-search=native={}/{}", workspace, OUT_DIR);
println!("cargo:rustc-env=LD_LIBRARY_PATH={}/{}", workspace, OUT_DIR);
for file in C_FILES {
Command::new("bash")
.arg("-c")
.arg(&format!(
"gcc -fPIC -Wall -O2 -shared ./{0}/{1} -g -o ./{2}/lib{3}.so `pkg-config vips --cflags --libs`",
C_FILE_DIR,
file,
OUT_DIR,
&file[..file.len() - 2]
))
.output()
.unwrap();
println!("cargo:rerun-if-changed=natives/{}", file);
println!("cargo:rustc-link-lib={}", &file[..file.len() - 2]);
let output = match Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output() {
Ok(o) => String::from_utf8_lossy(&o.stdout).to_string(),
Err(_) => "Unknown".to_owned(),
};
println!("cargo:rustc-env=FLUX_GIT_HASH={output}");
let c;
let version = match read_to_string(format!("{workspace}/Cargo.toml")) {
Ok(s) => {
c = s.clone();
c.split("\n")
.find(|x| x.trim().starts_with("version ="))
.map(|v| v.split(" ").nth(2))
.flatten()
.map(|v| &v[1..v.len() - 1])
.unwrap_or("Unknown")
},
Err(_) => "Unknown",
};
println!("cargo:rustc-env=FLUX_VERSION={version}");
}
}