Skip to content

Commit c7441af

Browse files
committed
Allow overriding of the libgit2 pkgconfig at build time
It is often desirable to Linux distributions to de-bundle packages as much as possible so that system versions of libraries are used instead of statically compiled versions. This is problematic with libgit2-sys as the supported version range is so narrow (also a problem for most libgit2 bindings). A common solution to this is to have co-installable versions of libgit2 where the pkgconfig file is renamed (perhaps to something like `libgit-1.7` or similar). Support this in libgit2-sys so that distributions can override this at build time for arbitrary applications that may use the libgit2 bindings. Signed-off-by: Reilly Brogan <reilly@reillybrogan.com>
1 parent f1f09ce commit c7441af

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libgit2-sys/build.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ use std::process::Command;
66

77
/// Tries to use system libgit2 and emits necessary build script instructions.
88
fn try_system_libgit2() -> Result<pkg_config::Library, pkg_config::Error> {
9+
// Specify `LIBGIT2_OVERRIDE_PKGCONFIG_NAME` to change the name of the pkgconfig configuration
10+
// that will be looked for when checking to see if the system libgit2 is usable. This is
11+
// most useful for distributions that may ship co-installable versions of libgit2 where
12+
// the pkgconfig may be renamed.
13+
println!("cargo:rerun-if-env-changed=LIBGIT2_OVERRIDE_PKGCONFIG_NAME");
14+
let libgit2_pkgconfig =
15+
env::var("LIBGIT2_OVERRIDE_PKGCONFIG_NAME").unwrap_or("libgit2".to_string());
16+
917
let mut cfg = pkg_config::Config::new();
10-
match cfg.range_version("1.8.1".."1.9.0").probe("libgit2") {
18+
match cfg
19+
.range_version("1.8.1".."1.9.0")
20+
.probe(&libgit2_pkgconfig)
21+
{
1122
Ok(lib) => {
1223
for include in &lib.include_paths {
1324
println!("cargo:root={}", include.display());

0 commit comments

Comments
 (0)