Skip to content

Commit 8614b5d

Browse files
committed
libgit2: Add support for OpenSSH instead of libssh2
This commit changes the original `ssh` feature into two new ones: `ssh-libssh2` and `ssh-openssh`. By default, the `ssh-libssh2` feature is enabled for backwards compatibility. To use OpenSSH instead, the following listing in `Cargo.toml` can be used: git2-rs = { version = "...", default-features = false, features = ["https", "ssh-openssh"] }
1 parent 8152297 commit 8614b5d

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

Diff for: Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ tempfile = "3.1.0"
3434
[features]
3535
unstable = []
3636
default = ["ssh", "https"]
37-
ssh = ["libgit2-sys/ssh"]
37+
ssh = ["ssh-libssh2"]
38+
ssh-libssh2 = ["libgit2-sys/ssh-libssh2"]
39+
ssh-openssh = ["libgit2-sys/ssh-openssh"]
3840
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"]
3941
vendored-libgit2 = ["libgit2-sys/vendored"]
4042
vendored-openssl = ["openssl-sys/vendored", "libgit2-sys/vendored-openssl"]

Diff for: libgit2-sys/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ cc = { version = "1.0.43", features = ['parallel'] }
3333
openssl-sys = { version = "0.9.45", optional = true }
3434

3535
[features]
36-
ssh = ["libssh2-sys"]
36+
ssh = ["ssh-libssh2"]
37+
ssh-libssh2 = ["libssh2-sys"]
38+
ssh-openssh = []
3739
https = ["openssl-sys"]
3840
vendored = []
3941
vendored-openssl = ["openssl-sys/vendored"]

Diff for: libgit2-sys/build.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ fn main() {
2929
);
3030

3131
let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
32-
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
32+
let ssh_libssh2 = env::var("CARGO_FEATURE_SSH_LIBSSH2").is_ok();
33+
let ssh_openssh = env::var("CARGO_FEATURE_SSH_OPENSSH").is_ok();
3334
let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok();
3435
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();
3536

@@ -182,13 +183,18 @@ The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VEN
182183
features.push_str("#define GIT_ARCH_64 1\n");
183184
}
184185

185-
if ssh {
186+
if ssh_openssh || ssh_libssh2 {
186187
if let Some(path) = env::var_os("DEP_SSH2_INCLUDE") {
187188
cfg.include(path);
188189
}
189190
features.push_str("#define GIT_SSH 1\n");
190-
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
191-
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
191+
if ssh_openssh {
192+
features.push_str("#define GIT_SSH_EXEC 1\n");
193+
}
194+
if ssh_libssh2 {
195+
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
196+
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
197+
}
192198
}
193199
if https {
194200
features.push_str("#define GIT_HTTPS 1\n");

Diff for: libgit2-sys/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extern crate libz_sys as libz;
66

77
use libc::{c_char, c_int, c_uchar, c_uint, c_void, size_t};
8-
#[cfg(feature = "ssh")]
8+
#[cfg(feature = "ssh-libssh2")]
99
use libssh2_sys as libssh2;
1010
use std::ffi::CStr;
1111

@@ -4353,12 +4353,12 @@ pub fn openssl_init() {
43534353
#[doc(hidden)]
43544354
pub fn openssl_init() {}
43554355

4356-
#[cfg(feature = "ssh")]
4356+
#[cfg(feature = "ssh-libssh2")]
43574357
fn ssh_init() {
43584358
libssh2::init();
43594359
}
43604360

4361-
#[cfg(not(feature = "ssh"))]
4361+
#[cfg(not(feature = "ssh-libssh2"))]
43624362
fn ssh_init() {}
43634363

43644364
#[doc(hidden)]

Diff for: src/cred.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ echo password=$2
671671
}
672672

673673
#[test]
674-
#[cfg(feature = "ssh")]
674+
#[cfg(feature = "ssh-libssh2")]
675675
fn ssh_key_from_memory() {
676676
let cred = Cred::ssh_key_from_memory(
677677
"test",

Diff for: systest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build = "build.rs"
66
edition = "2018"
77

88
[dependencies]
9-
libgit2-sys = { path = "../libgit2-sys", features = ['https', 'ssh'] }
9+
libgit2-sys = { path = "../libgit2-sys", features = ['https', 'ssh-libssh2'] }
1010
libc = "0.2"
1111

1212
[build-dependencies]

0 commit comments

Comments
 (0)