-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.rs
67 lines (53 loc) · 2.09 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
64
65
66
67
extern crate cpp_build;
#[cfg(feature = "download-models")]
extern crate reqwest;
#[cfg(feature = "download-models")]
extern crate bzip2;
#[cfg(feature = "download-models")]
fn download_path() -> std::path::PathBuf {
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("files")
}
#[cfg(feature = "download-models")]
fn download_and_unzip(client: &reqwest::Client, url: &str) {
use bzip2::read::*;
let url: reqwest::Url = url.parse().unwrap();
let filename = url
.path_segments().unwrap()
.last().unwrap()
.replace(".bz2", "");
let path = download_path().join(&filename);
if path.exists() {
println!("Already got '{}'", path.display());
return;
}
println!("Downloading '{}'...", url);
let response = client.get(url).send().unwrap();
let mut decoded = BzDecoder::new(response);
let mut file = std::fs::File::create(&path).unwrap();
std::io::copy(&mut decoded, &mut file).unwrap();
}
fn main() {
println!("cargo:rustc-link-lib=dlib");
println!("cargo:rustc-link-lib=lapack");
println!("cargo:rustc-link-lib=cblas");
cpp_build::build("src/lib.rs");
#[cfg(feature = "download-models")]
{
if !download_path().exists() {
std::fs::create_dir(download_path()).unwrap();
}
// Download the data files
// I'm not sure if doing this in the build script is such a good idea, seeing as it happens silently,
// but I dont think adding the files to the repo is good either
// Create a client for maintaining connections
let client = reqwest::ClientBuilder::new()
// Turn off gzip decryption
// See: https://github.com/seanmonstar/reqwest/issues/328
.gzip(false)
.build().unwrap();
download_and_unzip(&client, "http://dlib.net/files/mmod_human_face_detector.dat.bz2");
download_and_unzip(&client, "http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2");
download_and_unzip(&client, "http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2");
}
}