pkgconf
Parses pkg-config output into structured types for both linking (--libs) and bindgen (--cflags), with proper --whole-archive and static library support.
Why not the pkg-config crate?
- It reorders
-Wl,--whole-archive/-lflags, breaking libraries with constructor functions (DPDK'sRTE_INIT, SPDK'sSPDK_SUBSYSTEM_REGISTER) - It doesn't auto-detect static vs dynamic linking based on
.afile availability
Usage
use PkgConfigParser;
// In build.rs — single call for both linking and bindgen
let pkg = new
.force_whole_archive
.probe
.expect;
// Emit cargo linker directives (no_bundle=true for -sys crates)
emit_cargo_metadata;
// Get clang args for bindgen
let clang_args = to_clang_args;
default
.header
.clang_args
.generate
.expect;
Link Kinds
| Condition | Cargo Directive |
|---|---|
No .a found (or in system dir) |
rustc-link-lib=name |
.a exists, outside whole-archive region |
rustc-link-lib=static:-bundle=name |
.a exists, inside whole-archive region |
rustc-link-lib=static:+whole-archive,-bundle=name |
License
MIT