From 385a91101a36645e3c1e5c271ab4c10dbffc54fd Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Tue, 28 Feb 2023 16:26:29 +0100 Subject: [PATCH] Add a fallback to pkgconf --- src/lib.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c690fa..89bb37a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -477,12 +477,23 @@ impl Config { } fn run(&self, name: &str, args: &[&str]) -> Result, Error> { - let exe = self - .targetted_env_var("PKG_CONFIG") - .unwrap_or_else(|| OsString::from("pkg-config")); + let pkg_config_exe = self.targetted_env_var("PKG_CONFIG"); + let fallback_exe = if pkg_config_exe.is_none() { + Some(OsString::from("pkgconf")) + } else { + None + }; + let exe = pkg_config_exe.unwrap_or_else(|| OsString::from("pkg-config")); let mut cmd = self.command(exe, name, args); - match cmd.output() { + + match cmd.output().or_else(|e| { + if let Some(exe) = fallback_exe { + self.command(exe, name, args).output() + } else { + Err(e) + } + }) { Ok(output) => { if output.status.success() { Ok(output.stdout)