Skip to content

Commit

Permalink
Allow openssldir to be configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSidhion committed Dec 4, 2023
1 parent 86ad505 commit 715c2fe
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate cc;

use std::env;
use std::ffi::OsStr;
use std::ffi::{OsStr, OsString};
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand All @@ -18,6 +18,8 @@ pub struct Build {
out_dir: Option<PathBuf>,
target: Option<String>,
host: Option<String>,
// Only affects non-windows builds for now.
openssl_dir: Option<PathBuf>,
}

pub struct Artifacts {
Expand All @@ -34,6 +36,7 @@ impl Build {
out_dir: env::var_os("OUT_DIR").map(|s| PathBuf::from(s).join("openssl-build")),
target: env::var("TARGET").ok(),
host: env::var("HOST").ok(),
openssl_dir: Some(PathBuf::from("/usr/local/ssl")),
}
}

Expand All @@ -52,6 +55,11 @@ impl Build {
self
}

pub fn openssl_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Build {
self.openssl_dir = Some(path.as_ref().to_path_buf());
self
}

fn cmd_make(&self) -> Command {
let host = &self.host.as_ref().expect("HOST dir not set")[..];
if host.contains("dragonfly")
Expand Down Expand Up @@ -154,11 +162,18 @@ impl Build {

// Specify that openssl directory where things are loaded at runtime is
// not inside our build directory. Instead this should be located in the
// default locations of the OpenSSL build scripts.
// default locations of the OpenSSL build scripts, or as specified by whatever
// configured this builder.
if target.contains("windows") {
configure.arg("--openssldir=SYS$MANAGER:[OPENSSL]");
} else {
configure.arg("--openssldir=/usr/local/ssl");
let openssl_dir = self
.openssl_dir
.as_ref()
.expect("path to the openssl directory must be set");
let mut dir_arg: OsString = "--openssldir=".into();
dir_arg.push(openssl_dir);
configure.arg(dir_arg);
}

configure
Expand Down

0 comments on commit 715c2fe

Please sign in to comment.