Skip to content

Commit b3b13f9

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"] } Note that libgit2/libgit2#6617 has not actually been released in an official libgit2 version, so the prior commit pulled in the latest commit from `main`. Closes rust-lang#1028.
1 parent e1663a8 commit b3b13f9

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ tempfile = "3.1.0"
3333

3434
[features]
3535
unstable = []
36-
default = ["ssh", "https", "ssh_key_from_memory"]
37-
ssh = ["libgit2-sys/ssh"]
36+
default = ["ssh-libssh2", "https"]
37+
ssh = ["ssh-libssh2"]
38+
ssh-libssh2 = ["libgit2-sys/ssh-libssh2"]
39+
ssh-openssh = ["libgit2-sys/ssh-openssh"]
40+
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ 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-libssh2 = ["libssh2-sys"]
37+
ssh-openssh = []
3738
https = ["openssl-sys"]
3839
ssh_key_from_memory = []
3940
vendored = []

libgit2-sys/build.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ 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_openssh = env::var("CARGO_FEATURE_SSH_OPENSSH").is_ok();
2728
let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok();
2829
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();
2930

@@ -175,12 +176,18 @@ The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VEN
175176
features.push_str("#define GIT_ARCH_64 1\n");
176177
}
177178

178-
if ssh {
179+
if ssh_openssh || ssh_libssh2 {
179180
if let Some(path) = env::var_os("DEP_SSH2_INCLUDE") {
180181
cfg.include(path);
181182
}
182183
features.push_str("#define GIT_SSH 1\n");
183-
features.push_str("#define GIT_SSH_MEMORY_CREDENTIALS 1\n");
184+
if ssh_openssh {
185+
features.push_str("#define GIT_SSH_EXEC 1\n");
186+
}
187+
if ssh_libssh2 {
188+
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
189+
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
190+
}
184191
}
185192
if https {
186193
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

@@ -4311,12 +4311,12 @@ pub fn openssl_init() {
43114311
#[doc(hidden)]
43124312
pub fn openssl_init() {}
43134313

4314-
#[cfg(feature = "ssh")]
4314+
#[cfg(feature = "ssh-libssh2")]
43154315
fn ssh_init() {
43164316
libssh2::init();
43174317
}
43184318

4319-
#[cfg(not(feature = "ssh"))]
4319+
#[cfg(not(feature = "ssh-libssh2"))]
43204320
fn ssh_init() {}
43214321

43224322
#[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)