Skip to content

Improve openssl resolution under brew #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 30 additions & 33 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,55 +77,52 @@ fn build_mgclient_macos() -> PathBuf {
} else {
println!("Macports not found.");
println!("Checking for Homebrew...");
let output = Command::new("/usr/bin/command")
.args(["-v", "brew"])
.output()
.expect("Failed to execute shell command: '/usr/bin/command -v brew'")
.stdout;
let brew_path = String::from_utf8(output).unwrap();
if brew_path.is_empty() {
println!("Homebrew not found.");
panic!(
"We did not detect either MacPorts or Homebrew on your machine. We cannot proceed."
);
} else {
println!("'brew' executable detected at {:?}", &brew_path);
println!("Proceeding with installation assuming Homebrew is your package manager");
}
let path_openssl = if cfg!(target_arch = "aarch64") {
"/opt/homebrew/Cellar/[email protected]"
} else {
"/usr/local/Cellar/[email protected]"
let openssl_root_path = {
let output = Command::new("brew").arg("--prefix").arg("openssl").output();
match output {
Ok(output) if output.status.success() => {
let path = String::from_utf8_lossy(&output.stdout);
std::path::Path::new(path.trim()).to_path_buf()
}
_ => {
let fallback_output = Command::new("which").arg("openssl").output();
match fallback_output {
Ok(fallback_output) if fallback_output.status.success() => {
let fallback_path = String::from_utf8_lossy(&fallback_output.stdout);
std::path::Path::new(fallback_path.trim()).to_path_buf()
}
_ => {
panic!("OpenSSL not found on this system under brew.");
}
}
}
}
};
let mut openssl_dirs = std::fs::read_dir(PathBuf::new().join(path_openssl))
.unwrap()
.map(|r| r.unwrap().path())
.collect::<Vec<PathBuf>>();
openssl_dirs.sort_by(|a, b| {
let a_time = a.metadata().unwrap().modified().unwrap();
let b_time = b.metadata().unwrap().modified().unwrap();
b_time.cmp(&a_time)
});
let openssl_root_path = openssl_dirs[0].clone();

println!(
"cargo:rustc-link-search=native={}",
openssl_root_path.join("lib").display()
);
let openssl_root = openssl_dirs[0].clone();
Config::new("mgclient")
.define("OPENSSL_ROOT_DIR", format!("{}", openssl_root.display()))
.define(
"OPENSSL_ROOT_DIR",
format!("{}", openssl_root_path.display()),
)
.define(
"OPENSSL_CRYPTO_LIBRARY",
format!(
"{}",
openssl_root.join("lib").join("libcrypto.dylib").display()
openssl_root_path
.join("lib")
.join("libcrypto.dylib")
.display()
),
)
.define(
"OPENSSL_SSL_LIBRARY",
format!(
"{}",
openssl_root.join("lib").join("libssl.dylib").display()
openssl_root_path.join("lib").join("libssl.dylib").display()
),
)
.build()
Expand Down
Loading