fn pkg_config()

in neqo-crypto/build.rs [292:337]


fn pkg_config() -> Vec<String> {
    let modversion = Command::new("pkg-config")
        .args(["--modversion", "nss"])
        .output()
        .expect("pkg-config reports NSS as absent")
        .stdout;
    let modversion = String::from_utf8(modversion).expect("non-UTF8 from pkg-config");
    let modversion = modversion.trim();
    // The NSS version number does not follow semver numbering, because it omits the patch version
    // when that's 0. Deal with that.
    let modversion_for_cmp = if modversion.chars().filter(|c| *c == '.').count() == 1 {
        modversion.to_owned() + ".0"
    } else {
        modversion.to_owned()
    };
    let modversion_for_cmp =
        Version::parse(&modversion_for_cmp).expect("NSS version not in semver format");
    let version_req = VersionReq::parse(&format!(">={}", MINIMUM_NSS_VERSION.trim())).unwrap();
    assert!(
        version_req.matches(&modversion_for_cmp),
        "neqo has NSS version requirement {version_req}, found {modversion}"
    );

    let cfg = Command::new("pkg-config")
        .args(["--cflags", "--libs", "nss"])
        .output()
        .expect("NSS flags not returned by pkg-config")
        .stdout;
    let cfg_str = String::from_utf8(cfg).expect("non-UTF8 from pkg-config");

    let mut flags: Vec<String> = Vec::new();
    for f in cfg_str.split(' ') {
        if let Some(include) = f.strip_prefix("-I") {
            flags.push(String::from(f));
            println!("cargo:include={include}");
        } else if let Some(path) = f.strip_prefix("-L") {
            println!("cargo:rustc-link-search=native={path}");
        } else if let Some(lib) = f.strip_prefix("-l") {
            println!("cargo:rustc-link-lib=dylib={lib}");
        } else {
            println!("Warning: Unknown flag from pkg-config: {f}");
        }
    }

    flags
}