Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use brew --prefix command to get library path #93

Merged
merged 1 commit into from
Dec 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions openblas-src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,23 @@ fn windows_msvc_system() {
}
}

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

println!("cargo:rustc-link-search={}/lib", openblas.display());
println!("cargo:rustc-link-search={}/lib", libomp.display());
}

fn main() {
Expand Down