-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.rs
48 lines (46 loc) · 1.69 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
use std::fs;
use std::path::PathBuf;
use std::process::Command;
fn main() -> Result<(), std::io::Error> {
// Homebrew/macOS gcc don't add libgfortran to the rpath,
// so we manually go prodding around for it here
if cfg!(target_os = "windows") {
#[cfg(target_os = "windows")]
let _lapack = vcpkg::Config::new()
.target_triplet("x64-windows-static-md")
.find_package("clapack")
.unwrap();
println!("cargo:rustc-link-lib=static=lapack");
}
if cfg!(target_os = "macos") {
// First, we get brew prefix, if installed. Fall back to system gcc.
let prefix = String::from_utf8(
Command::new("brew")
.arg("--prefix")
.output()
.expect("Failed to run brew --prefix")
.stdout,
)
.unwrap()
.replace('\n', "");
let mut gcc_dir = PathBuf::new();
gcc_dir.push(prefix.clone());
gcc_dir = fs::read_dir(gcc_dir.join("Cellar/gcc"))?
.map(|res| res.map(|e| e.path()))
.filter_map(Result::ok)
.last()
.expect("No gcc installed?");
gcc_dir = gcc_dir.join("lib/gcc");
let version_dir = fs::read_dir(gcc_dir)?
.map(|res| res.map(|e| e.path()))
.filter_map(Result::ok)
.last()
.expect("No directories in prefix?");
let mut openblas_dir = PathBuf::new();
openblas_dir.push(prefix);
openblas_dir.push("opt/openblas/lib");
println!("cargo:rustc-link-search={}", version_dir.to_str().unwrap());
println!("cargo:rustc-link-search={}", openblas_dir.to_str().unwrap());
}
Ok(())
}