The pkg-config
dependency is harmless because that small crate just calls pkg-config
and parses its output. There's an issue though that its error type is String
so one can't expect to discriminate failure modes. I've just been considering making a PR to add a proper error type to pkg-config
.
As to pkg-config
alternatives it seems to me that the only "idiomatic" alternative is building the dependency from source if pkg-config
fails for whatever reason. Page Moved
The actual libgit2
build script does something slightly different and unexpected however:
if env::var("LIBGIT2_SYS_USE_PKG_CONFIG").is_ok() {
if pkg_config::find_library("libgit2").is_ok() {
return
}
}
openssl-sys
can't get away with building from source so it allows setting the search paths in env variables and calls pkg-config
if none of them are set:
let lib_dir = env::var("OPENSSL_LIB_DIR").ok();
let include_dir = env::var("OPENSSL_INCLUDE_DIR").ok();
if lib_dir.is_none() && include_dir.is_none() {
// rustc doesn't seem to work with pkg-config's output in mingw64
if !target.contains("windows") {
if let Ok(info) = pkg_config::find_library("openssl") {
// avoid empty include paths as they are not supported by GCC
if info.include_paths.len() > 0 {
let paths = env::join_paths(info.include_paths).unwrap();
println!("cargo:include={}", paths.to_str().unwrap());
}
return;
}
}
if let Some(mingw_paths) = get_mingw_in_path() {
for path in mingw_paths {
println!("cargo:rustc-link-search=native={}", path);
}
}
}