Skip to content

Commit

Permalink
feat: detect homebrew lib path
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Jan 2, 2025
1 parent a9fe994 commit d932113
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::process::Command;

fn main() {
if std::env::var("CARGO_FEATURE_STATIC").is_ok() {
if cfg!(target_os = "windows") {
Expand All @@ -18,6 +20,10 @@ fn main() {
}

if cfg!(target_os = "macos") {
if let Some(homebrew_lib_path) = homebrew_library_path() {
print_paths(&homebrew_lib_path);
}

// if we're on Mac OS X we'll kindly add DYLD_LIBRARY_PATH to rustc's
// linker search path
if let Some(dyld_paths) = option_env!("DYLD_LIBRARY_PATH") {
Expand All @@ -36,3 +42,16 @@ fn print_paths(paths: &str) {
println!("cargo:rustc-link-search=native={path}")
}
}

fn homebrew_library_path() -> Option<String> {
let output = Command::new("brew").arg("--prefix").output().ok()?;
if !output.status.success() {
return None;
}
let prefix =
String::from_utf8(output.stdout).expect("brew --prefix must yield utf8 encoded response");
// brew returns also a linebreak (`\n`), we want to get rid of that.
let prefix = prefix.trim();
let lib_path = prefix.to_owned() + "/lib";
Some(lib_path)
}

0 comments on commit d932113

Please sign in to comment.