Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const libssh2_dependency = b.dependency("libssh2", .{
.strip = true, // Strip debug information (default=false)
.linkage = .static, // Whether to link statically or dynamically (default=static)
.@"crypto-backend" = .auto, // auto will to default to wincng on windows, openssl everywhere else. (default=auto)
.@"openssl-linkage" = .static, // each dependency's linkage can be configured to static/dynamic linking
});
```

```

```
21 changes: 12 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub fn build(b: *std.Build) void {

const crypto_choice = b.option(CryptoBackend, "crypto-backend", "Crypto backend: auto|openssl|mbedtls|libgcrypt|wincng") orelse .auto;
const zlib = b.option(bool, "zlib", "Enable SSH payload compression (links zlib)") orelse false;
const mbedtls_linkage = b.option(std.builtin.LinkMode, "mbedtls-linkage", "static|dynamic") orelse .static;
const openssl_linkage = b.option(std.builtin.LinkMode, "openssl-linkage", "static|dynamic") orelse .static;
const wincng_linkage = b.option(std.builtin.LinkMode, "wincng-linkage", "static|dynamic") orelse .static;
const gcrypt_linkage = b.option(std.builtin.LinkMode, "gcrypt-linkage", "static|dynamic") orelse .static;

const is_windows = target.result.os.tag == .windows;
const mbedtls = crypto_choice == .mbedtls;
Expand Down Expand Up @@ -70,27 +74,26 @@ pub fn build(b: *std.Build) void {

if (mbedtls) {
ssh2_lib.root_module.addCMacro("LIBSSH2_MBEDTLS", "1");
ssh2_lib.linkSystemLibrary("mbedtls");
ssh2_lib.linkSystemLibrary("mbedcrypto");
ssh2_lib.linkSystemLibrary("mbedx509");
ssh2_lib.linkSystemLibrary2("mbedtls", .{ .preferred_link_mode = mbedtls_linkage });
ssh2_lib.linkSystemLibrary2("mbedcrypto", .{ .preferred_link_mode = mbedtls_linkage });
ssh2_lib.linkSystemLibrary2("mbedx509", .{ .preferred_link_mode = mbedtls_linkage });
}

if (openssl) {
ssh2_lib.root_module.addCMacro("LIBSSH2_OPENSSL", "1");
ssh2_lib.linkSystemLibrary("ssl");
ssh2_lib.linkSystemLibrary("crypto");
ssh2_lib.linkSystemLibrary2("ssl", .{ .preferred_link_mode = openssl_linkage });
ssh2_lib.linkSystemLibrary2("crypto", .{ .preferred_link_mode = openssl_linkage });
}

if (wincng) {
ssh2_lib.root_module.addCMacro("LIBSSH2_WINCNG", "1");
// Windows system libs (zig handles names)
ssh2_lib.linkSystemLibrary("bcrypt");
ssh2_lib.linkSystemLibrary("ncrypt");
ssh2_lib.linkSystemLibrary2("bcrypt", .{ .preferred_link_mode = wincng_linkage });
ssh2_lib.linkSystemLibrary2("ncrypt", .{ .preferred_link_mode = wincng_linkage });
}

if (libgcrypt) {
ssh2_lib.root_module.addCMacro("LIBSSH2_LIBGCRYPT", "1");
ssh2_lib.linkSystemLibrary("gcrypt");
ssh2_lib.linkSystemLibrary2("gcrypt", .{ .preferred_link_mode = gcrypt_linkage });
}

if (zlib) {
Expand Down