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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +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
.@"link-system-crypto-backend" = true, // If enabled will link against system libraries (default=true)
});
```
29 changes: 17 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ pub fn build(b: *std.Build) void {
const pic = b.option(bool, "pie", "Produce Position Independent Code");

const crypto_choice = b.option(CryptoBackend, "crypto-backend", "Crypto backend: auto|openssl|mbedtls|libgcrypt|wincng") orelse .auto;
const link_system_crypto = b.option(bool, "link-system-crypto-backend", "If true, library will link against system libraries") orelse true;
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 @@ -74,26 +71,34 @@ pub fn build(b: *std.Build) void {

if (mbedtls) {
ssh2_lib.root_module.addCMacro("LIBSSH2_MBEDTLS", "1");
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 (link_system_crypto) {
ssh2_lib.root_module.linkSystemLibrary("mbedtls", .{});
ssh2_lib.root_module.linkSystemLibrary("mbedcrypto", .{});
ssh2_lib.root_module.linkSystemLibrary("mbedx509", .{});
}
}

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

if (wincng) {
ssh2_lib.root_module.addCMacro("LIBSSH2_WINCNG", "1");
ssh2_lib.linkSystemLibrary2("bcrypt", .{ .preferred_link_mode = wincng_linkage });
ssh2_lib.linkSystemLibrary2("ncrypt", .{ .preferred_link_mode = wincng_linkage });
if (link_system_crypto) {
ssh2_lib.root_module.linkSystemLibrary("bcrypt", .{});
ssh2_lib.root_module.linkSystemLibrary("ncrypt", .{});
}
}

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

if (zlib) {
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
.hash = "N-V-__8AAATRLQBu_rNy4X2UK6RtcdYK_yAzkV6OcCqgo5aK",
},
.zlib = .{
.url = "git+https://github.com/allyourcodebase/zlib.git#61e7df7e996ec5a5f13a653db3c419adb340d6ef",
.hash = "zlib-1.3.1-ZZQ7lbYMAAB1hTSOKSXAKAgHsfDcyWNH_37ojw5WSpgR",
.url = "git+https://github.com/allyourcodebase/zlib.git#3599c16d41dbe749ae51b0ff7ab864c61adc779a",
.hash = "zlib-1.3.1-ZZQ7lc8NAABUbHzDe_cSWboCqMbrLkVwvFkKnojgeiT2",
.lazy = true,
},
},
Expand Down