Skip to content

Commit f6e90a7

Browse files
committed
Add support for zlib-ng
Depend on libz-sys 1.1.0, and provide "zlib-ng-compat" features to opt into zlib-ng. Use feature dependencies to ensure that either all C libraries opt in or none do. This provides a substantial performance boost when compressing or decompressing objects in a git2 repository.
1 parent c2a2613 commit f6e90a7

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ url = "2.0"
2020
bitflags = "1.1.0"
2121
libc = "0.2"
2222
log = "0.4.8"
23-
libgit2-sys = { path = "libgit2-sys", version = "0.12.9" }
23+
libgit2-sys = { path = "libgit2-sys", version = "0.12.10" }
2424

2525
[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
2626
openssl-sys = { version = "0.9.0", optional = true }
@@ -39,6 +39,7 @@ ssh = ["libgit2-sys/ssh"]
3939
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"]
4040
vendored-openssl = ["openssl-sys/vendored"]
4141
ssh_key_from_memory = ["libgit2-sys/ssh_key_from_memory"]
42+
zlib-ng-compat = ["libgit2-sys/zlib-ng-compat"]
4243

4344
[workspace]
4445
members = ["systest", "git2-curl"]

git2-curl/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Intended to be used with the git2 crate.
1313
edition = "2018"
1414

1515
[dependencies]
16-
curl = "0.4"
16+
curl = "0.4.33"
1717
url = "2.0"
1818
log = "0.4"
1919
git2 = { path = "..", version = "0.13", default-features = false }
@@ -24,6 +24,9 @@ conduit = "0.8"
2424
conduit-git-http-backend = "0.8"
2525
tempfile = "3.0"
2626

27+
[features]
28+
zlib-ng-compat = ["git2/zlib-ng-compat", "curl/zlib-ng-compat"]
29+
2730
[[test]]
2831
name = "all"
2932
harness = false

libgit2-sys/Cargo.toml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libgit2-sys"
3-
version = "0.12.9+1.0.1"
3+
version = "0.12.10+1.0.1"
44
authors = ["Josh Triplett <josh@joshtriplett.org>", "Alex Crichton <alex@alexcrichton.com>"]
55
links = "git2"
66
build = "build.rs"
@@ -18,8 +18,8 @@ path = "lib.rs"
1818

1919
[dependencies]
2020
libc = "0.2"
21-
libssh2-sys = { version = "0.2.11", optional = true }
22-
libz-sys = "1.0.22"
21+
libssh2-sys = { version = "0.2.19", optional = true }
22+
libz-sys = { version = "1.1.0", default-features = false, features = ["libc"] }
2323

2424
[build-dependencies]
2525
pkg-config = "0.3.7"
@@ -32,3 +32,9 @@ openssl-sys = { version = "0.9", optional = true }
3232
ssh = ["libssh2-sys"]
3333
https = ["openssl-sys"]
3434
ssh_key_from_memory = []
35+
# Cargo does not support requiring features on an optional dependency without
36+
# requiring the dependency. Rather than introduce additional complexity, we
37+
# just require libssh2 when using zlib-ng-compat. This will require building
38+
# libssh2, but it will not add code to the final binary without the "ssh"
39+
# feature enabled.
40+
zlib-ng-compat = ["libz-sys/zlib-ng", "libssh2-sys/zlib-ng-compat"]

libgit2-sys/build.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ use std::process::Command;
66
fn main() {
77
let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
88
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
9-
10-
let mut cfg = pkg_config::Config::new();
11-
if let Ok(lib) = cfg.atleast_version("1.0.0").probe("libgit2") {
12-
for include in &lib.include_paths {
13-
println!("cargo:root={}", include.display());
9+
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();
10+
11+
// To use zlib-ng in zlib-compat mode, we have to build libgit2 ourselves.
12+
if !zlib_ng_compat {
13+
let mut cfg = pkg_config::Config::new();
14+
if let Ok(lib) = cfg.atleast_version("1.0.0").probe("libgit2") {
15+
for include in &lib.include_paths {
16+
println!("cargo:root={}", include.display());
17+
}
18+
return;
1419
}
15-
return;
1620
}
1721

1822
if !Path::new("libgit2/.git").exists() {

0 commit comments

Comments
 (0)