From 71c7f7d46de7ac91659fb131ff8eb5490640eacb Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Wed, 1 Oct 2025 01:03:12 +0300 Subject: [PATCH 1/3] fix: use `b.systemIntegrationOption` in build.zig --- build.zig | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/build.zig b/build.zig index 61096bf..15e140c 100644 --- a/build.zig +++ b/build.zig @@ -21,10 +21,6 @@ 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; @@ -74,26 +70,44 @@ 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 (b.systemIntegrationOption("mbedtls", .{ .default = true })) { + ssh2_lib.linkSystemLibrary("mbedtls"); + ssh2_lib.linkSystemLibrary("mbedcrypto"); + ssh2_lib.linkSystemLibrary("mbedx509"); + } else { + // TODO: Add lazy dependency to build.zig.zon for linking statically. + // For now it's the users resposibility to compile and statically link against library + } } 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 (b.systemIntegrationOption("openssl", .{ .default = true })) { + ssh2_lib.linkSystemLibrary("ssl"); + ssh2_lib.linkSystemLibrary("crypto"); + } else { + // TODO: Add lazy dependency to build.zig.zon for linking statically. + // For now it's the users resposibility to compile and statically link against library + } } if (wincng) { + // There is no need to provide `b.systemIntegrationOption` here, + // because on windows this library MUST be dynamically linked. There is no static version. + 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 }); + ssh2_lib.linkSystemLibrary2("bcrypt", .{}); + ssh2_lib.linkSystemLibrary2("ncrypt", .{}); } if (libgcrypt) { ssh2_lib.root_module.addCMacro("LIBSSH2_LIBGCRYPT", "1"); - ssh2_lib.linkSystemLibrary2("gcrypt", .{ .preferred_link_mode = gcrypt_linkage }); + if (b.systemIntegrationOption("libgcrypt", .{ .default = true })) { + ssh2_lib.linkSystemLibrary("gcrypt"); + } else { + // TODO: Add lazy dependency to build.zig.zon for linking statically. + // For now it's the users resposibility to compile and statically link against library + } } if (zlib) { From 17a9e4cb4bd8f3c07394f8928680ebe2a8bc5395 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Wed, 1 Oct 2025 01:15:11 +0300 Subject: [PATCH 2/3] fix: update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 706ed98..d7e41c3 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ 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 }); ``` + +By default libssh2 will dynamically link against the crypto backend. +This can be changed through system integration options, i.e. `-fsys` and `-fno-sys` From 8178ba28a2f36f8f54cb24562e80317581b78812 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 5 Oct 2025 21:12:31 +0300 Subject: [PATCH 3/3] fix: update comments --- README.md | 2 +- build.zig | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d7e41c3..ae6780b 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,4 @@ const libssh2_dependency = b.dependency("libssh2", .{ ``` By default libssh2 will dynamically link against the crypto backend. -This can be changed through system integration options, i.e. `-fsys` and `-fno-sys` +This can be disable through the system integration options, i.e. `-fsys` and `-fno-sys` diff --git a/build.zig b/build.zig index 15e140c..109a883 100644 --- a/build.zig +++ b/build.zig @@ -75,8 +75,8 @@ pub fn build(b: *std.Build) void { ssh2_lib.linkSystemLibrary("mbedcrypto"); ssh2_lib.linkSystemLibrary("mbedx509"); } else { - // TODO: Add lazy dependency to build.zig.zon for linking statically. - // For now it's the users resposibility to compile and statically link against library + // TODO: Add lazy dependency to build.zig.zon and statically link against library. + // For now it's the users resposibility to compile and link against the library } } @@ -86,14 +86,14 @@ pub fn build(b: *std.Build) void { ssh2_lib.linkSystemLibrary("ssl"); ssh2_lib.linkSystemLibrary("crypto"); } else { - // TODO: Add lazy dependency to build.zig.zon for linking statically. - // For now it's the users resposibility to compile and statically link against library + // TODO: Add lazy dependency to build.zig.zon and statically link against library. + // For now it's the users resposibility to compile and link against the library } } if (wincng) { // There is no need to provide `b.systemIntegrationOption` here, - // because on windows this library MUST be dynamically linked. There is no static version. + // because on windows this library MUST be dynamically linked. ssh2_lib.root_module.addCMacro("LIBSSH2_WINCNG", "1"); ssh2_lib.linkSystemLibrary2("bcrypt", .{}); @@ -105,8 +105,8 @@ pub fn build(b: *std.Build) void { if (b.systemIntegrationOption("libgcrypt", .{ .default = true })) { ssh2_lib.linkSystemLibrary("gcrypt"); } else { - // TODO: Add lazy dependency to build.zig.zon for linking statically. - // For now it's the users resposibility to compile and statically link against library + // TODO: Add lazy dependency to build.zig.zon and statically link against library. + // For now it's the users resposibility to compile and link against the library } }