Pass include directories to gcc

This commit is contained in:
Steven Fackler 2015-02-12 18:41:51 -08:00
parent 370dba4a2c
commit d4c5bafa19
2 changed files with 16 additions and 14 deletions

View File

@ -19,7 +19,7 @@ aes_xts = []
[build-dependencies] [build-dependencies]
pkg-config = "0.2.1" pkg-config = "0.2.1"
gcc = "0.1" gcc = "0.2"
[target.le32-unknown-nacl.dependencies] [target.le32-unknown-nacl.dependencies]
libressl-pnacl-sys = "2.1.0" libressl-pnacl-sys = "2.1.0"

View File

@ -1,10 +1,9 @@
#![feature(env)] #![feature(env, path)]
extern crate "pkg-config" as pkg_config; extern crate "pkg-config" as pkg_config;
extern crate gcc; extern crate gcc;
use std::env; use std::env;
use std::default::Default;
fn main() { fn main() {
let target = env::var("TARGET").unwrap(); let target = env::var("TARGET").unwrap();
@ -21,18 +20,18 @@ fn main() {
if target.contains("win32") || target.contains("win64") || target.contains("windows") { if target.contains("win32") || target.contains("win64") || target.contains("windows") {
println!("cargo:rustc-flags=-l crypto -l ssl -l gdi32 -l wsock32"); println!("cargo:rustc-flags=-l crypto -l ssl -l gdi32 -l wsock32");
// going to assume the user has a new version of openssl // going to assume the user has a new version of openssl
build_old_openssl_shim(false); build_old_openssl_shim(false, vec![]);
return; return;
} }
if pkg_config::Config::new().atleast_version("1.0.0").find("openssl").is_ok() { if pkg_config::Config::new().atleast_version("1.0.0").find("openssl").is_ok() {
build_old_openssl_shim(false); build_old_openssl_shim(false, vec![]);
return; return;
} }
let err = match pkg_config::find_library("openssl") { let err = match pkg_config::find_library("openssl") {
Ok(..) => { Ok(info) => {
build_old_openssl_shim(true); build_old_openssl_shim(true, info.include_paths);
return; return;
} }
Err(err) => err, Err(err) => err,
@ -42,22 +41,25 @@ fn main() {
if target.contains("bsd") { if target.contains("bsd") {
println!("cargo:rustc-flags=-l crypto -l ssl"); println!("cargo:rustc-flags=-l crypto -l ssl");
// going to assume the base system includes a new version of openssl // going to assume the base system includes a new version of openssl
build_old_openssl_shim(false); build_old_openssl_shim(false, vec![]);
return; return;
} }
panic!("unable to find openssl: {}", err); panic!("unable to find openssl: {}", err);
} }
fn build_old_openssl_shim(is_old: bool) { fn build_old_openssl_shim(is_old: bool, include_paths: Vec<Path>) {
let mut config: gcc::Config = Default::default(); let mut config = gcc::Config::new();
for path in include_paths {
config.include(path);
}
if is_old { if is_old {
config.definitions.push(("OLD_OPENSSL".to_string(), None)); config.define("OLD_OPENSSL", None);
} }
gcc::compile_library("libold_openssl_shim.a", config.file("src/old_openssl_shim.c")
&config, .compile("libold_openssl_shim.a");
&["src/old_openssl_shim.c"]);
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
println!("cargo:rustc-flags=-L native={} -l old_openssl_shim:static", out_dir); println!("cargo:rustc-flags=-L native={} -l old_openssl_shim:static", out_dir);