Skip to content

Commit 2a397fe

Browse files
Allow openssldir to be configured. (#220)
1 parent 86ad505 commit 2a397fe

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate cc;
22

33
use std::env;
4-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
55
use std::fs;
66
use std::path::{Path, PathBuf};
77
use std::process::Command;
@@ -18,6 +18,8 @@ pub struct Build {
1818
out_dir: Option<PathBuf>,
1919
target: Option<String>,
2020
host: Option<String>,
21+
// Only affects non-windows builds for now.
22+
openssl_dir: Option<PathBuf>,
2123
}
2224

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

@@ -52,6 +55,11 @@ impl Build {
5255
self
5356
}
5457

58+
pub fn openssl_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Build {
59+
self.openssl_dir = Some(path.as_ref().to_path_buf());
60+
self
61+
}
62+
5563
fn cmd_make(&self) -> Command {
5664
let host = &self.host.as_ref().expect("HOST dir not set")[..];
5765
if host.contains("dragonfly")
@@ -154,11 +162,18 @@ impl Build {
154162

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

164179
configure

0 commit comments

Comments
 (0)