-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
46 lines (39 loc) · 1.36 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 cmake;
use cmake::Config;
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let source = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("source");
let source_copy = out_dir.join("source");
if source_copy.exists() {
fs::remove_dir_all(&source_copy).unwrap();
}
fs::create_dir_all(&source_copy).unwrap();
copy_dir_all(&source, &source_copy).unwrap();
let dst = Config::new(&source_copy)
.define("CMAKE_BUILD_TYPE", "Release")
.cflag("-O3 -DNDEBUG -DPRNTlevel=0 -fPIC -w")
.build();
let lib_path = dst.join("lib");
if !lib_path.join("libsuperlu.a").exists() {
panic!("Could not find native static library `superlu`");
}
println!("cargo:rustc-link-lib=static=superlu");
println!("cargo:rustc-link-search=native={}", lib_path.display());
}
fn copy_dir_all(src: &PathBuf, dst: &PathBuf) -> std::io::Result<()> {
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
let new_dst = dst.join(entry.file_name());
fs::create_dir_all(&new_dst)?;
copy_dir_all(&entry.path(), &new_dst)?;
} else {
fs::copy(entry.path(), dst.join(entry.file_name()))?;
}
}
Ok(())
}