-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
63 lines (53 loc) · 2.53 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
use fs_extra::dir::{copy, CopyOptions};
use std::path::Path;
use std::process::Command;
use std::{env, fs};
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let num_jobs = env::var("NUM_JOBS").unwrap();
let isl_dir_path = Path::new("isl/");
let pwd_at_build_start_path = env::current_dir().unwrap();
let mut copy_options = CopyOptions::new();
copy_options.skip_exist = true;
if !isl_dir_path.is_dir() {
panic!(concat!("`isl/` directory not found. Most likely",
" `git submdoule update --init --recursive` was not invoked."));
}
if !Path::new("isl/imath").is_dir() {
panic!(concat!("`isl/imath/` directory not found. Most likely",
" `git submdoule update --init --recursive` was not invoked."));
}
// Copy to out_dir and change isl path
copy(isl_dir_path, out_dir.to_string().as_str(), ©_options).unwrap();
let isl_dir_path = Path::new(&out_dir).join("isl/");
if Path::new("isl/").join(".git").is_file() {
let mut copy_options = CopyOptions::new();
copy_options.overwrite = true;
fs::remove_file(isl_dir_path.join(".git")).unwrap();
copy(".git/modules/isl/", &isl_dir_path, ©_options).unwrap();
}
// Goto isl/ before building anything
// (Not ideal but better than `make` emitting intermediary files into tree)
env::set_current_dir(&isl_dir_path).expect("Could not cd into isl/");
Command::new("./autogen.sh").status()
.expect("failed to autoreconf!");
Command::new("./configure").args(["--prefix",
out_dir.as_str(),
"--with-pic=isl",
"--with-int=imath",
"--enable-shared=no",
"--enable-static=yes"])
.status()
.expect("failed to configure!");
Command::new("make").args(&["-j", num_jobs.as_str()])
.status()
.expect("failed to make!");
Command::new("make").args(&["install"])
.status()
.expect("failed to make install!");
// Go back to old_pwd
env::set_current_dir(pwd_at_build_start_path).expect("Could not cd back into OUT_DIR");
println!("cargo:rustc-link-search=native={}/lib/", out_dir);
println!("cargo:rustc-link-lib=static=isl");
println!("cargo:rerun-if-changed=isl/");
}