1 //! A build dependency for Cargo libraries to find system artifacts through the
2 //! `pkg-config` utility.
3 //!
4 //! This library will shell out to `pkg-config` as part of build scripts and
5 //! probe the system to determine how to link to a specified library. The
6 //! `Config` structure serves as a method of configuring how `pkg-config` is
7 //! invoked in a builder style.
8 //!
9 //! A number of environment variables are available to globally configure how
10 //! this crate will invoke `pkg-config`:
11 //!
12 //! * `PKG_CONFIG_ALLOW_CROSS` - if this variable is not set, then `pkg-config`
13 //!   will automatically be disabled for all cross compiles.
14 //! * `FOO_NO_PKG_CONFIG` - if set, this will disable running `pkg-config` when
15 //!   probing for the library named `foo`.
16 //!
17 //! There are also a number of environment variables which can configure how a
18 //! library is linked to (dynamically vs statically). These variables control
19 //! whether the `--static` flag is passed. Note that this behavior can be
20 //! overridden by configuring explicitly on `Config`. The variables are checked
21 //! in the following order:
22 //!
23 //! * `FOO_STATIC` - pass `--static` for the library `foo`
24 //! * `FOO_DYNAMIC` - do not pass `--static` for the library `foo`
25 //! * `PKG_CONFIG_ALL_STATIC` - pass `--static` for all libraries
26 //! * `PKG_CONFIG_ALL_DYNAMIC` - do not pass `--static` for all libraries
27 //!
28 //! After running `pkg-config` all appropriate Cargo metadata will be printed on
29 //! stdout if the search was successful.
30 //!
31 //! # Example
32 //!
33 //! Find the system library named `foo`, with minimum version 1.2.3:
34 //!
35 //! ```no_run
36 //! extern crate pkg_config;
37 //!
38 //! fn main() {
39 //!     pkg_config::Config::new().atleast_version("1.2.3").probe("foo").unwrap();
40 //! }
41 //! ```
42 //!
43 //! Find the system library named `foo`, with no version requirement (not
44 //! recommended):
45 //!
46 //! ```no_run
47 //! extern crate pkg_config;
48 //!
49 //! fn main() {
50 //!     pkg_config::probe_library("foo").unwrap();
51 //! }
52 //! ```
53 //!
54 //! Configure how library `foo` is linked to.
55 //!
56 //! ```no_run
57 //! extern crate pkg_config;
58 //!
59 //! fn main() {
60 //!     pkg_config::Config::new().atleast_version("1.2.3").statik(true).probe("foo").unwrap();
61 //! }
62 //! ```
63 
64 #![doc(html_root_url = "https://docs.rs/pkg-config/0.3")]
65 
66 use std::collections::HashMap;
67 use std::env;
68 use std::error;
69 use std::ffi::{OsStr, OsString};
70 use std::fmt;
71 use std::io;
72 use std::ops::{Bound, RangeBounds};
73 use std::path::{Path, PathBuf};
74 use std::process::{Command, Output};
75 use std::str;
76 
77 #[derive(Clone, Debug)]
78 pub struct Config {
79     statik: Option<bool>,
80     min_version: Bound<String>,
81     max_version: Bound<String>,
82     extra_args: Vec<OsString>,
83     cargo_metadata: bool,
84     env_metadata: bool,
85     print_system_libs: bool,
86     print_system_cflags: bool,
87 }
88 
89 #[derive(Clone, Debug)]
90 pub struct Library {
91     pub libs: Vec<String>,
92     pub link_paths: Vec<PathBuf>,
93     pub frameworks: Vec<String>,
94     pub framework_paths: Vec<PathBuf>,
95     pub include_paths: Vec<PathBuf>,
96     pub defines: HashMap<String, Option<String>>,
97     pub version: String,
98     _priv: (),
99 }
100 
101 /// Represents all reasons `pkg-config` might not succeed or be run at all.
102 #[derive(Debug)]
103 pub enum Error {
104     /// Aborted because of `*_NO_PKG_CONFIG` environment variable.
105     ///
106     /// Contains the name of the responsible environment variable.
107     EnvNoPkgConfig(String),
108 
109     /// Cross compilation detected.
110     ///
111     /// Override with `PKG_CONFIG_ALLOW_CROSS=1`.
112     CrossCompilation,
113 
114     /// Failed to run `pkg-config`.
115     ///
116     /// Contains the command and the cause.
117     Command { command: String, cause: io::Error },
118 
119     /// `pkg-config` did not exit sucessfully.
120     ///
121     /// Contains the command and output.
122     Failure { command: String, output: Output },
123 
124     #[doc(hidden)]
125     // please don't match on this, we're likely to add more variants over time
126     __Nonexhaustive,
127 }
128 
129 impl error::Error for Error {
description(&self) -> &str130     fn description(&self) -> &str {
131         match *self {
132             Error::EnvNoPkgConfig(_) => "pkg-config requested to be aborted",
133             Error::CrossCompilation => {
134                 "pkg-config doesn't handle cross compilation. \
135                  Use PKG_CONFIG_ALLOW_CROSS=1 to override"
136             }
137             Error::Command { .. } => "failed to run pkg-config",
138             Error::Failure { .. } => "pkg-config did not exit sucessfully",
139             Error::__Nonexhaustive => panic!(),
140         }
141     }
142 
cause(&self) -> Option<&dyn error::Error>143     fn cause(&self) -> Option<&dyn error::Error> {
144         match *self {
145             Error::Command { ref cause, .. } => Some(cause),
146             _ => None,
147         }
148     }
149 }
150 
151 impl fmt::Display for Error {
fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>152     fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
153         match *self {
154             Error::EnvNoPkgConfig(ref name) => write!(f, "Aborted because {} is set", name),
155             Error::CrossCompilation => write!(
156                 f,
157                 "Cross compilation detected. \
158                  Use PKG_CONFIG_ALLOW_CROSS=1 to override"
159             ),
160             Error::Command {
161                 ref command,
162                 ref cause,
163             } => write!(f, "Failed to run `{}`: {}", command, cause),
164             Error::Failure {
165                 ref command,
166                 ref output,
167             } => {
168                 let stdout = str::from_utf8(&output.stdout).unwrap();
169                 let stderr = str::from_utf8(&output.stderr).unwrap();
170                 write!(
171                     f,
172                     "`{}` did not exit successfully: {}",
173                     command, output.status
174                 )?;
175                 if !stdout.is_empty() {
176                     write!(f, "\n--- stdout\n{}", stdout)?;
177                 }
178                 if !stderr.is_empty() {
179                     write!(f, "\n--- stderr\n{}", stderr)?;
180                 }
181                 Ok(())
182             }
183             Error::__Nonexhaustive => panic!(),
184         }
185     }
186 }
187 
188 /// Deprecated in favor of the probe_library function
189 #[doc(hidden)]
find_library(name: &str) -> Result<Library, String>190 pub fn find_library(name: &str) -> Result<Library, String> {
191     probe_library(name).map_err(|e| e.to_string())
192 }
193 
194 /// Simple shortcut for using all default options for finding a library.
probe_library(name: &str) -> Result<Library, Error>195 pub fn probe_library(name: &str) -> Result<Library, Error> {
196     Config::new().probe(name)
197 }
198 
199 /// Run `pkg-config` to get the value of a variable from a package using
200 /// --variable.
get_variable(package: &str, variable: &str) -> Result<String, Error>201 pub fn get_variable(package: &str, variable: &str) -> Result<String, Error> {
202     let arg = format!("--variable={}", variable);
203     let cfg = Config::new();
204     let out = run(cfg.command(package, &[&arg]))?;
205     Ok(str::from_utf8(&out).unwrap().trim_end().to_owned())
206 }
207 
208 impl Config {
209     /// Creates a new set of configuration options which are all initially set
210     /// to "blank".
new() -> Config211     pub fn new() -> Config {
212         Config {
213             statik: None,
214             min_version: Bound::Unbounded,
215             max_version: Bound::Unbounded,
216             extra_args: vec![],
217             print_system_cflags: true,
218             print_system_libs: true,
219             cargo_metadata: true,
220             env_metadata: false,
221         }
222     }
223 
224     /// Indicate whether the `--static` flag should be passed.
225     ///
226     /// This will override the inference from environment variables described in
227     /// the crate documentation.
statik(&mut self, statik: bool) -> &mut Config228     pub fn statik(&mut self, statik: bool) -> &mut Config {
229         self.statik = Some(statik);
230         self
231     }
232 
233     /// Indicate that the library must be at least version `vers`.
atleast_version(&mut self, vers: &str) -> &mut Config234     pub fn atleast_version(&mut self, vers: &str) -> &mut Config {
235         self.min_version = Bound::Included(vers.to_string());
236         self.max_version = Bound::Unbounded;
237         self
238     }
239 
240     /// Indicate that the library must be equal to version `vers`.
exactly_version(&mut self, vers: &str) -> &mut Config241     pub fn exactly_version(&mut self, vers: &str) -> &mut Config {
242         self.min_version = Bound::Included(vers.to_string());
243         self.max_version = Bound::Included(vers.to_string());
244         self
245     }
246 
247     /// Indicate that the library's version must be in `range`.
range_version<'a, R>(&mut self, range: R) -> &mut Config where R: RangeBounds<&'a str>,248     pub fn range_version<'a, R>(&mut self, range: R) -> &mut Config
249     where
250         R: RangeBounds<&'a str>,
251     {
252         self.min_version = match range.start_bound() {
253             Bound::Included(vers) => Bound::Included(vers.to_string()),
254             Bound::Excluded(vers) => Bound::Excluded(vers.to_string()),
255             Bound::Unbounded => Bound::Unbounded,
256         };
257         self.max_version = match range.end_bound() {
258             Bound::Included(vers) => Bound::Included(vers.to_string()),
259             Bound::Excluded(vers) => Bound::Excluded(vers.to_string()),
260             Bound::Unbounded => Bound::Unbounded,
261         };
262         self
263     }
264 
265     /// Add an argument to pass to pkg-config.
266     ///
267     /// It's placed after all of the arguments generated by this library.
arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Config268     pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Config {
269         self.extra_args.push(arg.as_ref().to_os_string());
270         self
271     }
272 
273     /// Define whether metadata should be emitted for cargo allowing it to
274     /// automatically link the binary. Defaults to `true`.
cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Config275     pub fn cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Config {
276         self.cargo_metadata = cargo_metadata;
277         self
278     }
279 
280     /// Define whether metadata should be emitted for cargo allowing to
281     /// automatically rebuild when environment variables change. Defaults to
282     /// `false`.
env_metadata(&mut self, env_metadata: bool) -> &mut Config283     pub fn env_metadata(&mut self, env_metadata: bool) -> &mut Config {
284         self.env_metadata = env_metadata;
285         self
286     }
287 
288     /// Enable or disable the `PKG_CONFIG_ALLOW_SYSTEM_LIBS` environment
289     /// variable.
290     ///
291     /// This env var is enabled by default.
print_system_libs(&mut self, print: bool) -> &mut Config292     pub fn print_system_libs(&mut self, print: bool) -> &mut Config {
293         self.print_system_libs = print;
294         self
295     }
296 
297     /// Enable or disable the `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS` environment
298     /// variable.
299     ///
300     /// This env var is enabled by default.
print_system_cflags(&mut self, print: bool) -> &mut Config301     pub fn print_system_cflags(&mut self, print: bool) -> &mut Config {
302         self.print_system_cflags = print;
303         self
304     }
305 
306     /// Deprecated in favor fo the `probe` function
307     #[doc(hidden)]
find(&self, name: &str) -> Result<Library, String>308     pub fn find(&self, name: &str) -> Result<Library, String> {
309         self.probe(name).map_err(|e| e.to_string())
310     }
311 
312     /// Run `pkg-config` to find the library `name`.
313     ///
314     /// This will use all configuration previously set to specify how
315     /// `pkg-config` is run.
probe(&self, name: &str) -> Result<Library, Error>316     pub fn probe(&self, name: &str) -> Result<Library, Error> {
317         let abort_var_name = format!("{}_NO_PKG_CONFIG", envify(name));
318         if self.env_var_os(&abort_var_name).is_some() {
319             return Err(Error::EnvNoPkgConfig(abort_var_name));
320         } else if !self.target_supported() {
321             return Err(Error::CrossCompilation);
322         }
323 
324         let mut library = Library::new();
325 
326         let output = run(self.command(name, &["--libs", "--cflags"]))?;
327         library.parse_libs_cflags(name, &output, self);
328 
329         let output = run(self.command(name, &["--modversion"]))?;
330         library.parse_modversion(str::from_utf8(&output).unwrap());
331 
332         Ok(library)
333     }
334 
target_supported(&self) -> bool335     pub fn target_supported(&self) -> bool {
336         let target = env::var("TARGET").unwrap_or_default();
337         let host = env::var("HOST").unwrap_or_default();
338 
339         // Only use pkg-config in host == target situations by default (allowing an
340         // override).
341         if host == target {
342             return true;
343         }
344 
345         // pkg-config may not be aware of cross-compilation, and require
346         // a wrapper script that sets up platform-specific prefixes.
347         match self.targetted_env_var("PKG_CONFIG_ALLOW_CROSS") {
348             // don't use pkg-config if explicitly disabled
349             Ok(ref val) if val == "0" => false,
350             Ok(_) => true,
351             Err(_) => {
352                 // if not disabled, and pkg-config is customized,
353                 // then assume it's prepared for cross-compilation
354                 self.targetted_env_var("PKG_CONFIG").is_ok()
355                     || self.targetted_env_var("PKG_CONFIG_SYSROOT_DIR").is_ok()
356             }
357         }
358     }
359 
360     /// Deprecated in favor of the top level `get_variable` function
361     #[doc(hidden)]
get_variable(package: &str, variable: &str) -> Result<String, String>362     pub fn get_variable(package: &str, variable: &str) -> Result<String, String> {
363         get_variable(package, variable).map_err(|e| e.to_string())
364     }
365 
targetted_env_var(&self, var_base: &str) -> Result<String, env::VarError>366     fn targetted_env_var(&self, var_base: &str) -> Result<String, env::VarError> {
367         if let Ok(target) = env::var("TARGET") {
368             let host = env::var("HOST")?;
369             let kind = if host == target { "HOST" } else { "TARGET" };
370             let target_u = target.replace("-", "_");
371 
372             self.env_var(&format!("{}_{}", var_base, target))
373                 .or_else(|_| self.env_var(&format!("{}_{}", var_base, target_u)))
374                 .or_else(|_| self.env_var(&format!("{}_{}", kind, var_base)))
375                 .or_else(|_| self.env_var(var_base))
376         } else {
377             self.env_var(var_base)
378         }
379     }
380 
env_var(&self, name: &str) -> Result<String, env::VarError>381     fn env_var(&self, name: &str) -> Result<String, env::VarError> {
382         if self.env_metadata {
383             println!("cargo:rerun-if-env-changed={}", name);
384         }
385         env::var(name)
386     }
387 
env_var_os(&self, name: &str) -> Option<OsString>388     fn env_var_os(&self, name: &str) -> Option<OsString> {
389         if self.env_metadata {
390             println!("cargo:rerun-if-env-changed={}", name);
391         }
392         env::var_os(name)
393     }
394 
is_static(&self, name: &str) -> bool395     fn is_static(&self, name: &str) -> bool {
396         self.statik.unwrap_or_else(|| self.infer_static(name))
397     }
398 
command(&self, name: &str, args: &[&str]) -> Command399     fn command(&self, name: &str, args: &[&str]) -> Command {
400         let exe = self
401             .env_var("PKG_CONFIG")
402             .unwrap_or_else(|_| String::from("pkg-config"));
403         let mut cmd = Command::new(exe);
404         if self.is_static(name) {
405             cmd.arg("--static");
406         }
407         cmd.args(args).args(&self.extra_args);
408 
409         if let Ok(value) = self.targetted_env_var("PKG_CONFIG_PATH") {
410             cmd.env("PKG_CONFIG_PATH", value);
411         }
412         if let Ok(value) = self.targetted_env_var("PKG_CONFIG_LIBDIR") {
413             cmd.env("PKG_CONFIG_LIBDIR", value);
414         }
415         if let Ok(value) = self.targetted_env_var("PKG_CONFIG_SYSROOT_DIR") {
416             cmd.env("PKG_CONFIG_SYSROOT_DIR", value);
417         }
418         if self.print_system_libs {
419             cmd.env("PKG_CONFIG_ALLOW_SYSTEM_LIBS", "1");
420         }
421         if self.print_system_cflags {
422             cmd.env("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", "1");
423         }
424         cmd.arg(name);
425         match self.min_version {
426             Bound::Included(ref version) => {
427                 cmd.arg(&format!("{} >= {}", name, version));
428             }
429             Bound::Excluded(ref version) => {
430                 cmd.arg(&format!("{} > {}", name, version));
431             }
432             _ => (),
433         }
434         match self.max_version {
435             Bound::Included(ref version) => {
436                 cmd.arg(&format!("{} <= {}", name, version));
437             }
438             Bound::Excluded(ref version) => {
439                 cmd.arg(&format!("{} < {}", name, version));
440             }
441             _ => (),
442         }
443         cmd
444     }
445 
print_metadata(&self, s: &str)446     fn print_metadata(&self, s: &str) {
447         if self.cargo_metadata {
448             println!("cargo:{}", s);
449         }
450     }
451 
infer_static(&self, name: &str) -> bool452     fn infer_static(&self, name: &str) -> bool {
453         let name = envify(name);
454         if self.env_var_os(&format!("{}_STATIC", name)).is_some() {
455             true
456         } else if self.env_var_os(&format!("{}_DYNAMIC", name)).is_some() {
457             false
458         } else if self.env_var_os("PKG_CONFIG_ALL_STATIC").is_some() {
459             true
460         } else if self.env_var_os("PKG_CONFIG_ALL_DYNAMIC").is_some() {
461             false
462         } else {
463             false
464         }
465     }
466 }
467 
468 // Implement Default manualy since Bound does not implement Default.
469 impl Default for Config {
default() -> Config470     fn default() -> Config {
471         Config {
472             statik: None,
473             min_version: Bound::Unbounded,
474             max_version: Bound::Unbounded,
475             extra_args: vec![],
476             print_system_cflags: false,
477             print_system_libs: false,
478             cargo_metadata: false,
479             env_metadata: false,
480         }
481     }
482 }
483 
484 impl Library {
new() -> Library485     fn new() -> Library {
486         Library {
487             libs: Vec::new(),
488             link_paths: Vec::new(),
489             include_paths: Vec::new(),
490             frameworks: Vec::new(),
491             framework_paths: Vec::new(),
492             defines: HashMap::new(),
493             version: String::new(),
494             _priv: (),
495         }
496     }
497 
parse_libs_cflags(&mut self, name: &str, output: &[u8], config: &Config)498     fn parse_libs_cflags(&mut self, name: &str, output: &[u8], config: &Config) {
499         let mut is_msvc = false;
500         if let Ok(target) = env::var("TARGET") {
501             if target.contains("msvc") {
502                 is_msvc = true;
503             }
504         }
505 
506         let words = split_flags(output);
507         let parts = words
508             .iter()
509             .filter(|l| l.len() > 2)
510             .map(|arg| (&arg[0..2], &arg[2..]))
511             .collect::<Vec<_>>();
512 
513         let mut dirs = Vec::new();
514         let statik = config.is_static(name);
515         for &(flag, val) in &parts {
516             match flag {
517                 "-L" => {
518                     let meta = format!("rustc-link-search=native={}", val);
519                     config.print_metadata(&meta);
520                     dirs.push(PathBuf::from(val));
521                     self.link_paths.push(PathBuf::from(val));
522                 }
523                 "-F" => {
524                     let meta = format!("rustc-link-search=framework={}", val);
525                     config.print_metadata(&meta);
526                     self.framework_paths.push(PathBuf::from(val));
527                 }
528                 "-I" => {
529                     self.include_paths.push(PathBuf::from(val));
530                 }
531                 "-l" => {
532                     // These are provided by the CRT with MSVC
533                     if is_msvc && ["m", "c", "pthread"].contains(&val) {
534                         continue;
535                     }
536 
537                     if statik && is_static_available(val, &dirs) {
538                         let meta = format!("rustc-link-lib=static={}", val);
539                         config.print_metadata(&meta);
540                     } else {
541                         let meta = format!("rustc-link-lib={}", val);
542                         config.print_metadata(&meta);
543                     }
544 
545                     self.libs.push(val.to_string());
546                 }
547                 "-D" => {
548                     let mut iter = val.split('=');
549                     self.defines.insert(
550                         iter.next().unwrap().to_owned(),
551                         iter.next().map(|s| s.to_owned()),
552                     );
553                 }
554                 _ => {}
555             }
556         }
557 
558         let mut iter = words.iter().flat_map(|arg| {
559             if arg.starts_with("-Wl,") {
560                 arg[4..].split(',').collect()
561             } else {
562                 vec![arg.as_ref()]
563             }
564         });
565         while let Some(part) = iter.next() {
566             if part != "-framework" {
567                 continue;
568             }
569             if let Some(lib) = iter.next() {
570                 let meta = format!("rustc-link-lib=framework={}", lib);
571                 config.print_metadata(&meta);
572                 self.frameworks.push(lib.to_string());
573             }
574         }
575     }
576 
parse_modversion(&mut self, output: &str)577     fn parse_modversion(&mut self, output: &str) {
578         self.version.push_str(output.lines().nth(0).unwrap().trim());
579     }
580 }
581 
envify(name: &str) -> String582 fn envify(name: &str) -> String {
583     name.chars()
584         .map(|c| c.to_ascii_uppercase())
585         .map(|c| if c == '-' { '_' } else { c })
586         .collect()
587 }
588 
589 /// System libraries should only be linked dynamically
is_static_available(name: &str, dirs: &[PathBuf]) -> bool590 fn is_static_available(name: &str, dirs: &[PathBuf]) -> bool {
591     let libname = format!("lib{}.a", name);
592     let system_roots = if cfg!(target_os = "macos") {
593         vec![Path::new("/Library"), Path::new("/System")]
594     } else {
595         vec![Path::new("/usr")]
596     };
597 
598     dirs.iter().any(|dir| {
599         !system_roots.iter().any(|sys| dir.starts_with(sys)) && dir.join(&libname).exists()
600     })
601 }
602 
run(mut cmd: Command) -> Result<Vec<u8>, Error>603 fn run(mut cmd: Command) -> Result<Vec<u8>, Error> {
604     match cmd.output() {
605         Ok(output) => {
606             if output.status.success() {
607                 Ok(output.stdout)
608             } else {
609                 Err(Error::Failure {
610                     command: format!("{:?}", cmd),
611                     output,
612                 })
613             }
614         }
615         Err(cause) => Err(Error::Command {
616             command: format!("{:?}", cmd),
617             cause,
618         }),
619     }
620 }
621 
622 /// Split output produced by pkg-config --cflags and / or --libs into separate flags.
623 ///
624 /// Backslash in output is used to preserve literal meaning of following byte.  Different words are
625 /// separated by unescaped space. Other whitespace characters generally should not occur unescaped
626 /// at all, apart from the newline at the end of output. For compatibility with what others
627 /// consumers of pkg-config output would do in this scenario, they are used here for splitting as
628 /// well.
split_flags(output: &[u8]) -> Vec<String>629 fn split_flags(output: &[u8]) -> Vec<String> {
630     let mut word = Vec::new();
631     let mut words = Vec::new();
632     let mut escaped = false;
633 
634     for &b in output {
635         match b {
636             _ if escaped => {
637                 escaped = false;
638                 word.push(b);
639             }
640             b'\\' => escaped = true,
641             b'\t' | b'\n' | b'\r' | b' ' => {
642                 if !word.is_empty() {
643                     words.push(String::from_utf8(word).unwrap());
644                     word = Vec::new();
645                 }
646             }
647             _ => word.push(b),
648         }
649     }
650 
651     if !word.is_empty() {
652         words.push(String::from_utf8(word).unwrap());
653     }
654 
655     words
656 }
657 
658 #[test]
659 #[cfg(target_os = "macos")]
system_library_mac_test()660 fn system_library_mac_test() {
661     assert!(!is_static_available(
662         "PluginManager",
663         &[PathBuf::from("/Library/Frameworks")]
664     ));
665     assert!(!is_static_available(
666         "python2.7",
667         &[PathBuf::from(
668             "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config"
669         )]
670     ));
671     assert!(!is_static_available(
672         "ffi_convenience",
673         &[PathBuf::from(
674             "/Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/ext/ffi_c/libffi-x86_64/.libs"
675         )]
676     ));
677 
678     // Homebrew is in /usr/local, and it's not a part of the OS
679     if Path::new("/usr/local/lib/libpng16.a").exists() {
680         assert!(is_static_available(
681             "png16",
682             &[PathBuf::from("/usr/local/lib")]
683         ));
684 
685         let libpng = Config::new()
686             .range_version("1".."99")
687             .probe("libpng16")
688             .unwrap();
689         assert!(libpng.version.find('\n').is_none());
690     }
691 }
692 
693 #[test]
694 #[cfg(target_os = "linux")]
system_library_linux_test()695 fn system_library_linux_test() {
696     assert!(!is_static_available(
697         "util",
698         &[PathBuf::from("/usr/lib/x86_64-linux-gnu")]
699     ));
700     assert!(!is_static_available("dialog", &[PathBuf::from("/usr/lib")]));
701 }
702