-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
63 lines (54 loc) · 1.79 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 flate2::read::GzDecoder;
use std::error::Error;
use std::fs::{self, remove_file, File};
use std::io;
use std::path::Path;
use tar::Archive;
const URL: &str = "https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz";
const EIGEN_PATH: &str = "./eigen-3.4.0/";
const EIGEN_TAR_NAME: &str = "eigen-3.4.0.tar.gz";
type GenericError = Box<dyn Error>;
fn get_file_from_url<P>(url: &str, path: &P) -> Result<(), GenericError>
where
P: AsRef<Path>,
{
use curl::easy::Easy;
use std::io::Write;
let f = fs::File::create(path)?;
let mut writer = io::BufWriter::new(f);
let mut easy = Easy::new();
easy.url(url)?;
easy.write_function(move |data| Ok(writer.write(data).unwrap()))?;
easy.perform()?;
let response_code = easy.response_code()?;
if response_code == 200 {
Ok(())
} else {
Err(format!("Unexpected response code {} for {}", response_code, url).into())
}
// Ok(())
}
fn main() -> Result<(), GenericError> {
if !std::env::var("DOCS_RS").is_ok() {
// ... your code here ...
let out_dir = std::env::var("OUT_DIR")?;
let out_path = Path::new(&out_dir);
let eingen_tar_path = out_path.join(EIGEN_TAR_NAME);
let eigen_dir = out_path.join(EIGEN_PATH);
if !eigen_dir.is_dir() {
get_file_from_url(URL, &eingen_tar_path)?;
let tar_gz = File::open(&eingen_tar_path)?;
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack(out_path)?;
remove_file(eingen_tar_path)?;
}
cc::Build::new()
.cpp(true)
.include(eigen_dir)
.file("src/solver.cpp")
.flag_if_supported("-std=c++1y")
.compile("solver_cpp");
}
Ok(())
}