From 97091c3f3e170e59b00f669a7f1a2043f4ffd735 Mon Sep 17 00:00:00 2001 From: Waleed Khan Date: Fri, 27 Aug 2021 12:30:05 -0700 Subject: [PATCH] Add `vendored` feature (#739) As per https://github.com/rust-lang/git2-rs/issues/721, some consumers may prefer to build `libgit2` themselves to simplify distribution. To test the vendored version, you can run: ``` cargo build --features vendored-libgit2` ``` That being said, the test `branch::tests::name_is_valid` fails on macOS. This test is currently broken as per https://github.com/rust-lang/git2-rs/issues/721#issuecomment-860256600 --- Cargo.toml | 1 + libgit2-sys/Cargo.toml | 1 + libgit2-sys/build.rs | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 191173bf02..7bdde1284d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ unstable = [] default = ["ssh", "https", "ssh_key_from_memory"] ssh = ["libgit2-sys/ssh"] https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"] +vendored-libgit2 = ["libgit2-sys/vendored"] vendored-openssl = ["openssl-sys/vendored", "libgit2-sys/vendored-openssl"] ssh_key_from_memory = ["libgit2-sys/ssh_key_from_memory"] zlib-ng-compat = ["libgit2-sys/zlib-ng-compat"] diff --git a/libgit2-sys/Cargo.toml b/libgit2-sys/Cargo.toml index 99266f4a9c..ed4299a36c 100644 --- a/libgit2-sys/Cargo.toml +++ b/libgit2-sys/Cargo.toml @@ -36,6 +36,7 @@ openssl-sys = { version = "0.9", optional = true } ssh = ["libssh2-sys"] https = ["openssl-sys"] ssh_key_from_memory = [] +vendored = [] vendored-openssl = ["openssl-sys/vendored"] # Cargo does not support requiring features on an optional dependency without # requiring the dependency. Rather than introduce additional complexity, we diff --git a/libgit2-sys/build.rs b/libgit2-sys/build.rs index 12831ec73b..3bd2ceb993 100644 --- a/libgit2-sys/build.rs +++ b/libgit2-sys/build.rs @@ -7,10 +7,12 @@ use std::process::Command; fn main() { let https = env::var("CARGO_FEATURE_HTTPS").is_ok(); let ssh = env::var("CARGO_FEATURE_SSH").is_ok(); + let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok(); let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok(); // To use zlib-ng in zlib-compat mode, we have to build libgit2 ourselves. - if !zlib_ng_compat { + let try_to_use_system_libgit2 = !vendored && !zlib_ng_compat; + if try_to_use_system_libgit2 { let mut cfg = pkg_config::Config::new(); if let Ok(lib) = cfg.atleast_version("1.1.0").probe("libgit2") { for include in &lib.include_paths {