From 20b3002e8debf8a4cabba74611db0d87c6af5040 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Tue, 9 Feb 2021 11:44:45 +0000 Subject: Add support for MacPorts + fix scanning other directories on arm64 --- openssl-sys/build/find_normal.rs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/openssl-sys/build/find_normal.rs b/openssl-sys/build/find_normal.rs index 3e314e15..873dc671 100644 --- a/openssl-sys/build/find_normal.rs +++ b/openssl-sys/build/find_normal.rs @@ -56,31 +56,33 @@ fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option { None } -fn resolve_with_wellknown_pkgsrc_location() -> Option { - let pkgsrc = Path::new("/opt/pkg"); - let pkgsrc_include_openssl = pkgsrc.join("include/openssl"); - if pkgsrc_include_openssl.exists() { - return Some(pkgsrc.to_path_buf()); +fn resolve_with_wellknown_location(dir: &str) -> Option { + let root_dir = Path::new(dir); + let include_openssl = root_dir.join("include/openssl"); + if include_openssl.exists() { + Some(root_dir.to_path_buf()) + } else { + None } - - 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(); - } - } else if target.contains("apple-darwin") { - if let Some(dir) = resolve_with_wellknown_homebrew_location("/usr/local/opt/openssl") { - return dir.into(); - } else if let Some(dir) = resolve_with_wellknown_pkgsrc_location() { - return dir.into(); - } + if host == target && target.ends_with("-apple-darwin") { + let homebrew_dir = match target { + "aarch64-apple-darwin" => "/opt/homebrew/opt/openssl", + _ => "/usr/local/opt/openssl", + }; + + if let Some(dir) = resolve_with_wellknown_homebrew_location(homebrew_dir) { + return dir.into(); + } else if let Some(dir) = resolve_with_wellknown_location("/opt/pkg") { + // pkgsrc + return dir.into(); + } else if let Some(dir) = resolve_with_wellknown_location("/opt/local") { + // MacPorts + return dir.into(); } } -- cgit v1.2.3 From cce48ac7d25d83e1a320370a674a7794721d1596 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Tue, 9 Feb 2021 12:22:55 +0000 Subject: add docs for installing openssl with macports/pkgsrc --- openssl/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index f908f3ab..b08bad6b 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -28,9 +28,15 @@ //! Additionally, it will use `pkg-config` on Unix-like systems to find the system installation. //! //! ```not_rust -//! # macOS +//! # macOS (Homebrew) //! $ brew install openssl@1.1 //! +//! # macOS (MacPorts) +//! $ sudo port install openssl +//! +//! # macOS (pkgsrc) +//! $ sudo pkgin install openssl +//! //! # Arch Linux //! $ sudo pacman -S pkg-config openssl //! -- cgit v1.2.3 From 32e6746e4a9e4926e00ca1c112e48d45864292c9 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 10 Feb 2021 10:36:58 +0000 Subject: remove unnecessary homebrew path checks --- openssl-sys/build/find_normal.rs | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/openssl-sys/build/find_normal.rs b/openssl-sys/build/find_normal.rs index 873dc671..b598aab6 100644 --- a/openssl-sys/build/find_normal.rs +++ b/openssl-sys/build/find_normal.rs @@ -25,16 +25,11 @@ fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option { // 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); + let homebrew = Path::new(dir).join("opt/openssl@1.1"); if homebrew.exists() { return Some(homebrew.to_path_buf()); } + // Calling `brew --prefix ` command usually slow and // takes seconds, and will be used only as a last resort. let output = execute_command_and_get_output("brew", &["--prefix", "openssl@1.1"]); @@ -45,14 +40,6 @@ fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option { } } - 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 Some(homebrew.to_path_buf()); - } - } - None } @@ -71,8 +58,8 @@ fn find_openssl_dir(target: &str) -> OsString { if host == target && target.ends_with("-apple-darwin") { let homebrew_dir = match target { - "aarch64-apple-darwin" => "/opt/homebrew/opt/openssl", - _ => "/usr/local/opt/openssl", + "aarch64-apple-darwin" => "/opt/homebrew", + _ => "/usr/local", }; if let Some(dir) = resolve_with_wellknown_homebrew_location(homebrew_dir) { -- cgit v1.2.3 From d7bd9becb73744c4e696395cbd904ee0711228aa Mon Sep 17 00:00:00 2001 From: David Bailey Date: Wed, 10 Feb 2021 12:00:28 +0000 Subject: remove redundant clone --- openssl-sys/build/find_normal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openssl-sys/build/find_normal.rs b/openssl-sys/build/find_normal.rs index b598aab6..5e3726c4 100644 --- a/openssl-sys/build/find_normal.rs +++ b/openssl-sys/build/find_normal.rs @@ -27,7 +27,7 @@ fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option { // `pkg-config` on brew doesn't necessarily contain settings for openssl apparently. let homebrew = Path::new(dir).join("opt/openssl@1.1"); if homebrew.exists() { - return Some(homebrew.to_path_buf()); + return Some(homebrew); } // Calling `brew --prefix ` command usually slow and -- cgit v1.2.3