Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose env vars pkg-config depends on #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+34 −7
Diff settings

Always

Just for now

Copy path View file
@@ -82,7 +82,7 @@ pub fn target_supported() -> bool {
// override) and then also don't use pkg-config on MSVC as it's really not
// meant to work there but when building MSVC code in a MSYS shell we may be
// able to run pkg-config anyway.
(host == target || env::var_os("PKG_CONFIG_ALLOW_CROSS").is_some()) &&
(host == target || get_var_os("PKG_CONFIG_ALLOW_CROSS").is_some()) &&
!target.contains("msvc")
}

@@ -330,7 +330,7 @@ impl Config {
/// `pkg-config` is run.
pub fn probe(&self, name: &str) -> Result<Library, Error> {
let abort_var_name = format!("{}_NO_PKG_CONFIG", envify(name));
if env::var_os(&abort_var_name).is_some() {
if get_var_os(&abort_var_name).is_some() {
return Err(Error::EnvNoPkgConfig(abort_var_name))
} else if !target_supported() {
if env::var("TARGET").unwrap_or(String::new()).contains("msvc") {
@@ -341,6 +341,22 @@ impl Config {
}
}

// pkg-config can be configured via env vars,
// and should be probed again if the configuration changes.
// Unfortunately, this list is not exhaustive,
// because arbitrary `PKG_CONFIG_$PKG_$VAR` can exist.
// NB: `get_var_os` automatically marks vars as used.
rerun_if_changed("PKG_CONFIG_PATH");
rerun_if_changed("PKG_CONFIG_SYSTEM_INCLUDE_PATH");
rerun_if_changed("CPATH");
rerun_if_changed("INCLUDE");
rerun_if_changed("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS");
rerun_if_changed("PKG_CONFIG_SYSTEM_LIBRARY_PATH");
rerun_if_changed("PKG_CONFIG_ALLOW_SYSTEM_LIBS");
rerun_if_changed("PKG_CONFIG_SYSROOT_DIR");
rerun_if_changed("PKG_CONFIG_LIBDIR");
rerun_if_changed("PKG_CONFIG_DISABLE_UNINSTALLED");

let mut library = Library::new();

let output = try!(run(self.command(name, &["--libs", "--cflags"])));
@@ -363,7 +379,7 @@ impl Config {
}

fn command(&self, name: &str, args: &[&str]) -> Command {
let exe = env::var("PKG_CONFIG").unwrap_or(String::from("pkg-config"));
let exe = get_var_os("PKG_CONFIG").unwrap_or(OsString::from("pkg-config"));
let mut cmd = Command::new(exe);
if self.is_static(name) {
cmd.arg("--static");
@@ -461,13 +477,13 @@ impl Library {

fn infer_static(name: &str) -> bool {
let name = envify(name);
if env::var_os(&format!("{}_STATIC", name)).is_some() {
if get_var_os(&format!("{}_STATIC", name)).is_some() {
true
} else if env::var_os(&format!("{}_DYNAMIC", name)).is_some() {
} else if get_var_os(&format!("{}_DYNAMIC", name)).is_some() {
false
} else if env::var_os("PKG_CONFIG_ALL_STATIC").is_some() {
} else if get_var_os("PKG_CONFIG_ALL_STATIC").is_some() {
true
} else if env::var_os("PKG_CONFIG_ALL_DYNAMIC").is_some() {
} else if get_var_os("PKG_CONFIG_ALL_DYNAMIC").is_some() {
false
} else {
false
@@ -480,6 +496,17 @@ fn envify(name: &str) -> String {
}).collect()
}

/// Mark build as dependent on the variable
fn rerun_if_changed(var_name: &str) {
println!("cargo:rerun-if-env-changed={}", var_name);
}

/// Get variable and mark the build as dependent on it
fn get_var_os(var_name: &str) -> Option<OsString> {
rerun_if_changed(var_name);
env::var_os(var_name)
}

/// System libraries should only be linked dynamically
fn is_static_available(name: &str, dirs: &[PathBuf]) -> bool {
let libname = format!("lib{}.a", name);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.