Skip to content

Commit 587188a

Browse files
authored
Merge pull request #93 from blas-lapack-rs/brew-prefix
Use `brew --prefix` command to get library path
2 parents 1d4379f + 4512606 commit 587188a

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

openblas-src/build.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,23 @@ fn windows_msvc_system() {
4141
}
4242
}
4343

44-
/// homebrew says
45-
///
46-
/// > openblas is keg-only, which means it was not symlinked into /usr/local,
47-
/// > because macOS provides BLAS in Accelerate.framework.
48-
/// > For compilers to find openblas you may need to set:
49-
///
50-
/// ```text
51-
/// export LDFLAGS="-L/usr/local/opt/openblas/lib"
52-
/// export CPPFLAGS="-I/usr/local/opt/openblas/include"
53-
/// ```
44+
/// Add linker flag (`-L`) to path where brew installs OpenBLAS
5445
fn macos_system() {
55-
if cfg!(target_arch = "aarch64") {
56-
println!("cargo:rustc-link-search=/opt/homebrew/opt/openblas/lib");
57-
println!("cargo:rustc-link-search=/opt/homebrew/opt/libomp/lib");
58-
} else {
59-
println!("cargo:rustc-link-search=/usr/local/homebrew/opt/openblas/lib");
60-
println!("cargo:rustc-link-search=/usr/local/homebrew/opt/libomp/lib");
46+
fn brew_prefix(target: &str) -> PathBuf {
47+
let out = Command::new("brew")
48+
.arg("--prefix")
49+
.arg(target)
50+
.output()
51+
.expect("brew not installed");
52+
assert!(out.status.success(), "`brew --prefix` failed");
53+
let path = String::from_utf8(out.stdout).expect("Non-UTF8 path by `brew --prefix`");
54+
PathBuf::from(path.trim())
6155
}
56+
let openblas = brew_prefix("openblas");
57+
let libomp = brew_prefix("libomp");
58+
59+
println!("cargo:rustc-link-search={}/lib", openblas.display());
60+
println!("cargo:rustc-link-search={}/lib", libomp.display());
6261
}
6362

6463
fn main() {

0 commit comments

Comments
 (0)