forked from sfackler/rust-openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sfackler#1388 from Byron/master
Find brew openssl in correct place on Apple Silicon/aarch64
- Loading branch information
Showing
1 changed file
with
42 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,34 +21,53 @@ pub fn get_openssl(target: &str) -> (PathBuf, PathBuf) { | |
} | ||
} | ||
|
||
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]"); | ||
fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option<PathBuf> { | ||
// Check up default aarch 64 Homebrew installation location first | ||
// for quick resolution if possible. | ||
// `pkg-config` on brew doesn't necessarily contain settings for openssl apparently. | ||
let mut version_dir = dir.to_owned(); | ||
version_dir.push_str("@1.1"); | ||
let homebrew = Path::new(&version_dir); | ||
if homebrew.exists() { | ||
return Some(homebrew.to_path_buf()); | ||
} | ||
let homebrew = Path::new(dir); | ||
if homebrew.exists() { | ||
return Some(homebrew.to_path_buf()); | ||
} | ||
// 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(); | ||
return Some(homebrew.to_path_buf()); | ||
} | ||
let homebrew = Path::new("/usr/local/opt/openssl"); | ||
} | ||
|
||
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(); | ||
return Some(homebrew.to_path_buf()); | ||
} | ||
// 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(); | ||
} | ||
|
||
None | ||
} | ||
|
||
fn find_openssl_dir(target: &str) -> OsString { | ||
let host = env::var("HOST").unwrap(); | ||
|
||
if host == target { | ||
if target == "aarch64-apple-darwin" { | ||
if let Some(dir) = resolve_with_wellknown_homebrew_location("/opt/homebrew/opt/openssl") | ||
{ | ||
return dir.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(); | ||
} else if target.contains("apple-darwin") { | ||
if let Some(dir) = resolve_with_wellknown_homebrew_location("/usr/local/opt/openssl") { | ||
return dir.into(); | ||
} | ||
} | ||
} | ||
|