From 01e46671756d4e729adb0bfd88f3c98638712b5d Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 24 Jan 2017 21:31:41 +0100 Subject: [PATCH] Make sure to not add system dirs to linkage cc #447 --- openssl-sys/Cargo.toml | 5 +++-- openssl-sys/build.rs | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index fe484a79..1f1750dc 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -15,11 +15,12 @@ build = "build.rs" libc = "0.2" [build-dependencies] -metadeps = "1" +pkg-config = "0.3.9" [target.'cfg(windows)'.dependencies] user32-sys = "0.2" gdi32-sys = "0.2" +# We don't actually use metadeps for annoying reasons but this is still hear for tooling [package.metadata.pkg-config] -openssl = "1.0.0" # We actually need 1.0.1, but OpenBSD reports as 1.0.0 +openssl = "1.0.1" diff --git a/openssl-sys/build.rs b/openssl-sys/build.rs index c59a76d4..0e1cdc46 100644 --- a/openssl-sys/build.rs +++ b/openssl-sys/build.rs @@ -1,4 +1,4 @@ -extern crate metadeps; +extern crate pkg_config; use std::collections::HashSet; use std::env; @@ -172,8 +172,16 @@ fn try_pkg_config() { // cflags dirs for showing us lots of `-I`. env::set_var("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", "1"); - let lib = match metadeps::probe() { - Ok(mut libs) => libs.remove("openssl").unwrap(), + // This is more complex than normal because we need to track down opensslconf.h. + // To do that, we need the inlude paths even if they're on the default search path, but the + // linkage directories emitted from that cause all kinds of issues if other libraries happen to + // live in them. So, we run pkg-config twice, once asking for system dirs but not emitting + // metadata, and a second time emitting metadata but not asking for system dirs. Yay. + let lib = match pkg_config::Config::new() + .cargo_metadata(false) + .print_system_libs(true) + .find("openssl") { + Ok(lib) => lib, Err(_) => return, }; @@ -196,7 +204,7 @@ specific to your distribution: sudo dnf install openssl-devel See rust-openssl README for more information: - + https://github.com/sfackler/rust-openssl#linux "); } @@ -207,6 +215,11 @@ See rust-openssl README for more information: println!("cargo:include={}", include.display()); } + pkg_config::Config::new() + .print_system_libs(false) + .find("openssl") + .unwrap(); + std::process::exit(0); }