From 14f78e37344286ee6696b1dce08000393fe70365 Mon Sep 17 00:00:00 2001 From: Nathan Fiedler Date: Mon, 10 Jul 2017 21:32:59 -0700 Subject: [PATCH] Fix pkg-config invocation in build.rs It seems that pkg-config ignores the --max-version option when combined with certain other options. As such, that check was not really working. Since the pkg-config Rust crate always passes those certain other options, it is necessary to invoke the pkg-config command directly from build.rs instead. cargo test passes --- build.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index f20fd31..c0efb2b 100644 --- a/build.rs +++ b/build.rs @@ -20,6 +20,7 @@ use std::env; use std::fs::File; use std::io::prelude::*; use std::path::{Path, PathBuf}; +use std::process::Command; const MIN_VERSION: &'static str = "6.9"; const MAX_VERSION: &'static str = "6.10"; @@ -31,9 +32,18 @@ fn main() { // since we are very dependent on the particulars of MagickWand. pkg_config::Config::new() .atleast_version(MIN_VERSION) - .arg(format!("--max-version={}", MAX_VERSION)) .probe("MagickWand") .unwrap(); + // Check the maximum version separately as pkg-config will ignore that + // option when combined with (certain) other options. And since the + // pkg-config crate always adds those other flags, we must run the + // command directly. + if !Command::new("pkg-config") + .arg(format!("--max-version={}", MAX_VERSION)) + .arg("MagickWand") + .status().unwrap().success() { + panic!("MagickWand version must be no higher than 6.9"); + } // We have to split the version check and the cflags/libs check because // you can't do both at the same time on RHEL (apparently). let library = pkg_config::Config::new().probe("MagickWand").unwrap();