-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
46 lines (31 loc) · 1.49 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 dunce;
use std::path::PathBuf;
use std::{fs, env, process::Command};
fn main() -> std::io::Result<()> {
// the lib directory to store librestmatr.so
let external_dir = if let Ok(target_dir) = env::var("REST_EXT_DIR") {
PathBuf::from(target_dir)
} else {PathBuf::from(".".to_string())};
if ! external_dir.is_dir() {
fs::create_dir(&external_dir)?
};
let blas_dir = if let Ok(blas_dir) = env::var("REST_BLAS_DIR") {
PathBuf::from(blas_dir)
} else {PathBuf::from(".".to_string())};
let fortran_compiler = if let Ok(fortran_compiler) = env::var("REST_FORTRAN_COMPILER") {
fortran_compiler
} else {"gfortran".to_string()};
let restmatr_file = format!("src/external_libs/restmatr.f90");
let restmatr_libr = format!("{}/librestmatr.so",&external_dir.to_str().unwrap());
let restmatr_link = format!("-L{}",&blas_dir.display());
Command::new(fortran_compiler)
.args(&["-shared", "-fpic", "-O2",&restmatr_file,"-o",&restmatr_libr,&restmatr_link, "-lopenblas"])
.status().unwrap();
println!("cargo:rustc-link-lib=restmatr");
println!("cargo:rustc-link-search=native={}",&external_dir.to_str().unwrap());
println!("cargo:rustc-link-lib=openblas");
println!("cargo:rustc-link-search=native={}",&blas_dir.display());
println!("cargo:rerun-if-changed=src/external_libs/restmatr.f90");
println!("cargo:rerun-if-changed={}/librestmatr.so", &external_dir.to_str().unwrap());
Ok(())
}