-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrom_source.rs
65 lines (57 loc) · 2.07 KB
/
from_source.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
#[cfg(feature = "from-source")]
use crate::download::download_and_extract_zip;
#[cfg(feature = "from-source")]
use std::env;
use std::path::PathBuf;
#[cfg(feature = "from-source")]
pub fn is_from_source_feature_enabled() -> bool {
true
}
#[cfg(not(feature = "from-source"))]
pub fn is_from_source_feature_enabled() -> bool {
false
}
#[cfg(not(feature = "from-source"))]
pub fn download_scip_source() -> PathBuf {
unimplemented!("Cannot download SCIP source code without the `from-source` feature")
}
#[cfg(feature = "from-source")]
pub fn download_scip_source() -> PathBuf {
let scip_version = "9.1.1";
let url = format!("https://github.com/scipopt/scip-sys/releases/download/v0.1.9/scipoptsuite-{scip_version}.zip");
let target = env::var("OUT_DIR").unwrap();
let target = std::path::Path::new(&target);
if target.join(format!("scipoptsuite-{scip_version}")).exists() {
println!("cargo:warning=SCIP was previously downloaded, skipping download");
} else {
download_and_extract_zip(&url, &*target).expect("Failed to download SCIP");
}
target.join(format!("scipoptsuite-{scip_version}"))
}
#[cfg(feature = "from-source")]
pub fn compile_scip(source_path: PathBuf) -> PathBuf {
let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = std::path::Path::new(&out_dir);
let lib_path = out_dir.join("lib");
if lib_path.exists() {
println!("cargo:warning=SCIP was previously compiled, skipping compilation");
return out_dir.to_path_buf();
}
use cmake::Config;
let mut dst = Config::new(source_path);
dst.define("IPOPT", "OFF")
.define("ZIMPL", "OFF")
.define("GMP", "OFF")
.define("READLINE", "OFF")
.define("BOOST", "OFF")
.define("AUTOBUILD", "OFF")
.define("PAPILO", "OFF")
.define("SYM", "snauty")
.define("ZLIB", "OFF")
.define("SHARED", "OFF")
.build()
}
#[cfg(not(feature = "from-source"))]
pub fn compile_scip(_source_path: PathBuf) -> PathBuf {
unimplemented!("Cannot compile SCIP without the `from-source` feature")
}