diff options
| author | Steven Fackler <[email protected]> | 2018-05-18 11:22:36 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-05-18 11:22:36 -0700 |
| commit | 9ba53102f987c1667cfedba540a692c2063259c4 (patch) | |
| tree | 58aed46ced02eefbd8ddda11b950f2813a764576 /openssl-sys | |
| parent | Merge pull request #919 from sfackler/cleanup (diff) | |
| parent | Find path prefix to OpenSSL installed by Homebrew. (diff) | |
| download | rust-openssl-9ba53102f987c1667cfedba540a692c2063259c4.tar.xz rust-openssl-9ba53102f987c1667cfedba540a692c2063259c4.zip | |
Merge pull request #921 from eonil/master
Find path prefix to OpenSSL installed by Homebrew better.
Diffstat (limited to 'openssl-sys')
| -rw-r--r-- | openssl-sys/build.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs index 0b8341fa..c5630556 100644 --- a/openssl-sys/build.rs +++ b/openssl-sys/build.rs @@ -104,6 +104,8 @@ fn find_openssl_dir(target: &str) -> OsString { let host = env::var("HOST").unwrap(); if host == target && target.contains("apple-darwin") { + // Check up default Homebrew installation location first + // for quick resolution if possible. let homebrew = Path::new("/usr/local/opt/[email protected]"); if homebrew.exists() { return homebrew.to_path_buf().into(); @@ -112,6 +114,22 @@ fn find_openssl_dir(target: &str) -> OsString { if homebrew.exists() { return homebrew.to_path_buf().into(); } + // Calling `brew --prefix <package>` command usually slow and + // takes seconds, and will be used only as a last resort. + let output = execute_command_and_get_output("brew", &["--prefix", "[email protected]"]); + if let Some(ref output) = output { + let homebrew = Path::new(&output); + if homebrew.exists() { + return homebrew.to_path_buf().into(); + } + } + let output = execute_command_and_get_output("brew", &["--prefix", "openssl"]); + if let Some(ref output) = output { + let homebrew = Path::new(&output); + if homebrew.exists() { + return homebrew.to_path_buf().into(); + } + } } try_pkg_config(); @@ -548,3 +566,19 @@ fn determine_mode(libdir: &Path, libs: &[&str]) -> &'static str { // practices with security libs", let's link dynamically. "dylib" } + + + +fn execute_command_and_get_output(cmd: &str, args: &[&str]) -> Option<String> { + let out = Command::new(cmd).args(args).output(); + if let Ok(ref r1) = out { + if r1.status.success() { + let r2 = String::from_utf8(r1.stdout.clone()); + if let Ok(r3) = r2 { + return Some(r3.trim().to_string()); + } + } + } + return None; +} + |