#cargo-build #build-script #cargo-toml #build-time #build-system #build-dependencies #env-var

build pkg-config

A library to run the pkg-config system tool at build time in order to be used in Cargo build scripts

44 releases

0.3.31 Sep 23, 2024
0.3.30 Feb 14, 2024
0.3.29 Jan 17, 2024
0.3.28 Dec 20, 2023
0.1.0 Nov 27, 2014

#4 in Build Utils

Download history 1892950/week @ 2024-07-30 1918991/week @ 2024-08-06 1891187/week @ 2024-08-13 1936587/week @ 2024-08-20 1854192/week @ 2024-08-27 1977233/week @ 2024-09-03 1903620/week @ 2024-09-10 1981800/week @ 2024-09-17 2286976/week @ 2024-09-24 2587606/week @ 2024-10-01 2772671/week @ 2024-10-08 2698296/week @ 2024-10-15 2259163/week @ 2024-10-22 2109698/week @ 2024-10-29 2087879/week @ 2024-11-05 2187122/week @ 2024-11-12

9,110,250 downloads per month
Used in 21,097 crates (821 directly)

MIT/Apache

50KB
844 lines

pkg-config-rs

Build Status Rust

Documentation

A simple library meant to be used as a build dependency with Cargo packages in order to use the system pkg-config tool (if available) to determine where a library is located.

You can use this crate directly to probe for specific libraries, or use system-deps to declare all your pkg-config dependencies in Cargo.toml.

This library requires Rust 1.31+.

Example

Find the system library named foo, with minimum version 1.2.3:

extern crate pkg_config;

fn main() {
    pkg_config::Config::new().atleast_version("1.2.3").probe("foo").unwrap();
}

Find the system library named foo, with no version requirement (not recommended):

extern crate pkg_config;

fn main() {
    pkg_config::probe_library("foo").unwrap();
}

External configuration via target-scoped environment variables

In cross-compilation context, it is useful to manage separately PKG_CONFIG_PATH and a few other variables for the host and the target platform.

The supported variables are: PKG_CONFIG_PATH, PKG_CONFIG_LIBDIR, and PKG_CONFIG_SYSROOT_DIR.

Each of these variables can also be supplied with certain prefixes and suffixes, in the following prioritized order:

  1. <var>_<target> - for example, PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  2. <var>_<target_with_underscores> - for example, PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  3. <build-kind>_<var> - for example, HOST_PKG_CONFIG_PATH or TARGET_PKG_CONFIG_PATH
  4. <var> - a plain PKG_CONFIG_PATH

This crate will allow pkg-config to be used in cross-compilation if PKG_CONFIG_SYSROOT_DIR or PKG_CONFIG is set. You can set PKG_CONFIG_ALLOW_CROSS=1 to bypass the compatibility check, but please note that enabling use of pkg-config in cross-compilation without appropriate sysroot and search paths set is likely to break builds.

Some Rust sys crates support building vendored libraries from source, which may be a work around for lack of cross-compilation support in pkg-config.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in pkg-config-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps