diff --git a/src/lib.rs b/src/lib.rs index e3444a67..0e474f7a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -18,6 +18,8 @@ pub struct Build { out_dir: Option, target: Option, host: Option, + // Only affects non-windows builds for now. + openssl_dir: Option, } pub struct Artifacts { @@ -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")), } } @@ -52,6 +55,11 @@ impl Build { self } + pub fn openssl_dir>(&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") @@ -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