| 1 |
# pkg-config-rs |
| 2 |
|
| 3 |
[](https://github.com/rust-lang/pkg-config-rs/actions) |
| 4 |
[](https://github.com/rust-lang/pkg-config-rs) |
| 5 |
|
| 6 |
[Documentation](https://docs.rs/pkg-config) |
| 7 |
|
| 8 |
A simple library meant to be used as a build dependency with Cargo packages in |
| 9 |
order to use the system `pkg-config` tool (if available) to determine where a |
| 10 |
library is located. |
| 11 |
|
| 12 |
You can use this crate directly to probe for specific libraries, or use |
| 13 |
[system-deps](https://github.com/gdesmott/system-deps) to declare all your |
| 14 |
`pkg-config` dependencies in `Cargo.toml`. |
| 15 |
|
| 16 |
This library requires Rust 1.63+. |
| 17 |
|
| 18 |
## Example |
| 19 |
|
| 20 |
Find the system library named `foo`, with minimum version 1.2.3: |
| 21 |
|
| 22 |
```rust |
| 23 |
fn main() { |
| 24 |
pkg_config::Config::new().atleast_version("1.2.3").probe("foo").unwrap(); |
| 25 |
} |
| 26 |
``` |
| 27 |
|
| 28 |
Find the system library named `foo`, with no version requirement (not |
| 29 |
recommended): |
| 30 |
|
| 31 |
```rust |
| 32 |
fn main() { |
| 33 |
pkg_config::probe_library("foo").unwrap(); |
| 34 |
} |
| 35 |
``` |
| 36 |
|
| 37 |
## External configuration via target-scoped environment variables |
| 38 |
|
| 39 |
In cross-compilation context, it is useful to manage separately |
| 40 |
`PKG_CONFIG_PATH` and a few other variables for the `host` and the `target` |
| 41 |
platform. |
| 42 |
|
| 43 |
The supported variables are: `PKG_CONFIG_PATH`, `PKG_CONFIG_LIBDIR`, and |
| 44 |
`PKG_CONFIG_SYSROOT_DIR`. |
| 45 |
|
| 46 |
Each of these variables can also be supplied with certain prefixes and suffixes, |
| 47 |
in the following prioritized order: |
| 48 |
|
| 49 |
1. `<var>_<target>` - for example, `PKG_CONFIG_PATH_x86_64-unknown-linux-gnu` |
| 50 |
2. `<var>_<target_with_underscores>` - for example, |
| 51 |
`PKG_CONFIG_PATH_x86_64_unknown_linux_gnu` |
| 52 |
3. `<build-kind>_<var>` - for example, `HOST_PKG_CONFIG_PATH` or |
| 53 |
`TARGET_PKG_CONFIG_PATH` |
| 54 |
4. `<var>` - a plain `PKG_CONFIG_PATH` |
| 55 |
|
| 56 |
This crate will allow `pkg-config` to be used in cross-compilation if |
| 57 |
`PKG_CONFIG_SYSROOT_DIR` or `PKG_CONFIG` is set. You can set |
| 58 |
`PKG_CONFIG_ALLOW_CROSS=1` to bypass the compatibility check, but please note |
| 59 |
that enabling use of `pkg-config` in cross-compilation without appropriate |
| 60 |
sysroot and search paths set is likely to break builds. |
| 61 |
|
| 62 |
Some Rust sys crates support building vendored libraries from source, which may |
| 63 |
be a work around for lack of cross-compilation support in `pkg-config`. |
| 64 |
|
| 65 |
## License |
| 66 |
|
| 67 |
This project is licensed under either of |
| 68 |
|
| 69 |
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
| 70 |
https://www.apache.org/licenses/LICENSE-2.0) |
| 71 |
* MIT license ([LICENSE-MIT](LICENSE-MIT) or |
| 72 |
https://opensource.org/license/mit) |
| 73 |
|
| 74 |
at your option. |
| 75 |
|
| 76 |
### Contribution |
| 77 |
|
| 78 |
Unless you explicitly state otherwise, any contribution intentionally submitted |
| 79 |
for inclusion in pkg-config-rs by you, as defined in the Apache-2.0 license, |
| 80 |
shall be dual licensed as above, without any additional terms or conditions. |