Skip to content

Commit 1e99a91

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"] } This commit is stacked on top of #1032, and should only be merged after libgit2 v1.8.0 has been released. Closes #1028.
1 parent 7d0742e commit 1e99a91

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ tempfile = "3.1.0"
3434
[features]
3535
unstable = []
3636
default = ["ssh", "https", "ssh_key_from_memory"]
37-
ssh = ["libgit2-sys/ssh"]
37+
ssh = ["ssh-libssh2"]
38+
ssh-libssh2 = ["libgit2-sys/ssh-libssh2"]
39+
ssh-openssh = ["libgit2-sys/ssh-openssh"]
40+
ssh_key_from_memory = ["libgit2-sys/ssh_key_from_memory"]
3841
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"]
3942
vendored-libgit2 = ["libgit2-sys/vendored"]
4043
vendored-openssl = ["openssl-sys/vendored", "libgit2-sys/vendored-openssl"]
41-
ssh_key_from_memory = ["libgit2-sys/ssh_key_from_memory"]
4244
zlib-ng-compat = ["libgit2-sys/zlib-ng-compat"]
4345

4446
[workspace]

libgit2-sys/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ 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 = []
39+
ssh_key_from_memory = ["ssh-libssh2"]
3740
https = ["openssl-sys"]
38-
ssh_key_from_memory = []
3941
vendored = []
4042
vendored-openssl = ["openssl-sys/vendored"]
4143
zlib-ng-compat = ["libz-sys/zlib-ng", "libssh2-sys?/zlib-ng-compat"]

libgit2-sys/build.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ fn try_system_libgit2() -> Result<pkg_config::Library, pkg_config::Error> {
2323

2424
fn main() {
2525
let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
26-
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
26+
let ssh_libssh2 = env::var("CARGO_FEATURE_SSH_LIBSSH2").is_ok();
27+
let ssh_libssh2_key_from_memory = env::var("CARGO_FEATURE_SSH_KEY_FROM_MEMORY").is_ok();
28+
let ssh_openssh = env::var("CARGO_FEATURE_SSH_OPENSSH").is_ok();
2729
let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok();
2830
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();
2931

@@ -175,13 +177,20 @@ The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VEN
175177
features.push_str("#define GIT_ARCH_64 1\n");
176178
}
177179

178-
if ssh {
180+
if ssh_openssh || ssh_libssh2 {
179181
if let Some(path) = env::var_os("DEP_SSH2_INCLUDE") {
180182
cfg.include(path);
181183
}
182184
features.push_str("#define GIT_SSH 1\n");
183-
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
184-
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
185+
if ssh_openssh {
186+
features.push_str("#define GIT_SSH_EXEC 1\n");
187+
}
188+
if ssh_libssh2 {
189+
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
190+
if ssh_libssh2_key_from_memory {
191+
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
192+
}
193+
}
185194
}
186195
if https {
187196
features.push_str("#define GIT_HTTPS 1\n");

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

@@ -4322,12 +4322,12 @@ pub fn openssl_init() {
43224322
#[doc(hidden)]
43234323
pub fn openssl_init() {}
43244324

4325-
#[cfg(feature = "ssh")]
4325+
#[cfg(feature = "ssh-libssh2")]
43264326
fn ssh_init() {
43274327
libssh2::init();
43284328
}
43294329

4330-
#[cfg(not(feature = "ssh"))]
4330+
#[cfg(not(feature = "ssh-libssh2"))]
43314331
fn ssh_init() {}
43324332

43334333
#[doc(hidden)]

src/cred.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ echo password=$2
659659
}
660660

661661
#[test]
662-
#[cfg(feature = "ssh")]
662+
#[cfg(feature = "ssh-libssh2")]
663663
fn ssh_key_from_memory() {
664664
let cred = Cred::ssh_key_from_memory(
665665
"test",

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)