Skip to content

Commit

Permalink
libgit2: Add support for OpenSSH instead of libssh2
Browse files Browse the repository at this point in the history
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"] }
  • Loading branch information
bnjmnt4n committed Jan 11, 2025
1 parent 8152297 commit 8614b5d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ tempfile = "3.1.0"
[features]
unstable = []
default = ["ssh", "https"]
ssh = ["libgit2-sys/ssh"]
ssh = ["ssh-libssh2"]
ssh-libssh2 = ["libgit2-sys/ssh-libssh2"]
ssh-openssh = ["libgit2-sys/ssh-openssh"]
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"]
vendored-libgit2 = ["libgit2-sys/vendored"]
vendored-openssl = ["openssl-sys/vendored", "libgit2-sys/vendored-openssl"]
Expand Down
4 changes: 3 additions & 1 deletion libgit2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ cc = { version = "1.0.43", features = ['parallel'] }
openssl-sys = { version = "0.9.45", optional = true }

[features]
ssh = ["libssh2-sys"]
ssh = ["ssh-libssh2"]
ssh-libssh2 = ["libssh2-sys"]
ssh-openssh = []
https = ["openssl-sys"]
vendored = []
vendored-openssl = ["openssl-sys/vendored"]
Expand Down
14 changes: 10 additions & 4 deletions libgit2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ fn main() {
);

let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
let ssh_libssh2 = env::var("CARGO_FEATURE_SSH_LIBSSH2").is_ok();
let ssh_openssh = env::var("CARGO_FEATURE_SSH_OPENSSH").is_ok();
let vendored = env::var("CARGO_FEATURE_VENDORED").is_ok();
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();

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

if ssh {
if ssh_openssh || ssh_libssh2 {
if let Some(path) = env::var_os("DEP_SSH2_INCLUDE") {
cfg.include(path);
}
features.push_str("#define GIT_SSH 1\n");
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
if ssh_openssh {
features.push_str("#define GIT_SSH_EXEC 1\n");
}
if ssh_libssh2 {
features.push_str("#define GIT_SSH_LIBSSH2 1\n");
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
}
}
if https {
features.push_str("#define GIT_HTTPS 1\n");
Expand Down
6 changes: 3 additions & 3 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate libz_sys as libz;

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

Expand Down Expand Up @@ -4353,12 +4353,12 @@ pub fn openssl_init() {
#[doc(hidden)]
pub fn openssl_init() {}

#[cfg(feature = "ssh")]
#[cfg(feature = "ssh-libssh2")]
fn ssh_init() {
libssh2::init();
}

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

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion src/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ echo password=$2
}

#[test]
#[cfg(feature = "ssh")]
#[cfg(feature = "ssh-libssh2")]
fn ssh_key_from_memory() {
let cred = Cred::ssh_key_from_memory(
"test",
Expand Down
2 changes: 1 addition & 1 deletion systest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build = "build.rs"
edition = "2018"

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

[build-dependencies]
Expand Down

0 comments on commit 8614b5d

Please sign in to comment.