]> git.proxmox.com Git - cargo.git/blobdiff - vendor/openssl-sys/build/find_normal.rs
New upstream version 0.63.1
[cargo.git] / vendor / openssl-sys / build / find_normal.rs
index 786b31ae5c622a13d1daafa950ca368523cfe060..df451438ad015e41c3a0f6d42202046a51cc878e 100644 (file)
@@ -5,16 +5,27 @@ use std::process::{self, Command};
 
 use super::env;
 
-pub fn get_openssl(target: &str) -> (PathBuf, PathBuf) {
+pub fn get_openssl(target: &str) -> (Vec<PathBuf>, PathBuf) {
     let lib_dir = env("OPENSSL_LIB_DIR").map(PathBuf::from);
     let include_dir = env("OPENSSL_INCLUDE_DIR").map(PathBuf::from);
 
     match (lib_dir, include_dir) {
-        (Some(lib_dir), Some(include_dir)) => (lib_dir, include_dir),
+        (Some(lib_dir), Some(include_dir)) => (vec![lib_dir], include_dir),
         (lib_dir, include_dir) => {
             let openssl_dir = env("OPENSSL_DIR").unwrap_or_else(|| find_openssl_dir(target));
             let openssl_dir = Path::new(&openssl_dir);
-            let lib_dir = lib_dir.unwrap_or_else(|| openssl_dir.join("lib"));
+            let lib_dir = lib_dir.map(|d| vec![d]).unwrap_or_else(|| {
+                let mut lib_dirs = vec![];
+                // OpenSSL 3.0 now puts it's libraries in lib64/ by default,
+                // check for both it and lib/.
+                if openssl_dir.join("lib64").exists() {
+                    lib_dirs.push(openssl_dir.join("lib64"));
+                }
+                if openssl_dir.join("lib").exists() {
+                    lib_dirs.push(openssl_dir.join("lib"));
+                }
+                lib_dirs
+            });
             let include_dir = include_dir.unwrap_or_else(|| openssl_dir.join("include"));
             (lib_dir, include_dir)
         }
@@ -22,21 +33,27 @@ pub fn get_openssl(target: &str) -> (PathBuf, PathBuf) {
 }
 
 fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option<PathBuf> {
+    let versions = ["openssl@3", "openssl@1.1"];
+
     // 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 homebrew = Path::new(dir).join("opt/openssl@1.1");
-    if homebrew.exists() {
-        return Some(homebrew);
+    for version in &versions {
+        let homebrew = Path::new(dir).join(format!("opt/{}", version));
+        if homebrew.exists() {
+            return Some(homebrew);
+        }
     }
 
-    // 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", "openssl@1.1"]);
-    if let Some(ref output) = output {
-        let homebrew = Path::new(&output);
-        if homebrew.exists() {
-            return Some(homebrew.to_path_buf());
+    for version in &versions {
+        // 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", version]);
+        if let Some(ref output) = output {
+            let homebrew = Path::new(&output);
+            if homebrew.exists() {
+                return Some(homebrew.to_path_buf());
+            }
         }
     }
 
@@ -203,7 +220,7 @@ fn try_pkg_config() {
         }
     };
 
-    super::validate_headers(&lib.include_paths);
+    super::postprocess(&lib.include_paths);
 
     for include in lib.include_paths.iter() {
         println!("cargo:include={}", include.display());
@@ -221,17 +238,18 @@ fn try_vcpkg() {
     // vcpkg will not emit any metadata if it can not find libraries
     // appropriate for the target triple with the desired linkage.
 
-    let lib = vcpkg::Config::new()
+    let lib = match vcpkg::Config::new()
         .emit_includes(true)
-        .find_package("openssl");
-
-    if let Err(e) = lib {
-        println!("note: vcpkg did not find openssl: {}", e);
-        return;
-    }
+        .find_package("openssl")
+    {
+        Ok(lib) => lib,
+        Err(e) => {
+            println!("note: vcpkg did not find openssl: {}", e);
+            return;
+        }
+    };
 
-    let lib = lib.unwrap();
-    super::validate_headers(&lib.include_paths);
+    super::postprocess(&lib.include_paths);
 
     println!("cargo:rustc-link-lib=user32");
     println!("cargo:rustc-link-lib=gdi32");