Skip to content

Commit d67e17d

Browse files
authored
feat(linking): control link mode of dependencies (#9)
1 parent 9de45c3 commit d67e17d

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ const libssh2_dependency = b.dependency("libssh2", .{
3636
.strip = true, // Strip debug information (default=false)
3737
.linkage = .static, // Whether to link statically or dynamically (default=static)
3838
.@"crypto-backend" = .auto, // auto will to default to wincng on windows, openssl everywhere else. (default=auto)
39+
.@"openssl-linkage" = .static, // each dependency's linkage can be configured to static/dynamic linking
3940
});
4041
```
41-
42-
```
43-
44-
```

build.zig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub fn build(b: *std.Build) void {
2121

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

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

7175
if (mbedtls) {
7276
ssh2_lib.root_module.addCMacro("LIBSSH2_MBEDTLS", "1");
73-
ssh2_lib.linkSystemLibrary("mbedtls");
74-
ssh2_lib.linkSystemLibrary("mbedcrypto");
75-
ssh2_lib.linkSystemLibrary("mbedx509");
77+
ssh2_lib.linkSystemLibrary2("mbedtls", .{ .preferred_link_mode = mbedtls_linkage });
78+
ssh2_lib.linkSystemLibrary2("mbedcrypto", .{ .preferred_link_mode = mbedtls_linkage });
79+
ssh2_lib.linkSystemLibrary2("mbedx509", .{ .preferred_link_mode = mbedtls_linkage });
7680
}
7781

7882
if (openssl) {
7983
ssh2_lib.root_module.addCMacro("LIBSSH2_OPENSSL", "1");
80-
ssh2_lib.linkSystemLibrary("ssl");
81-
ssh2_lib.linkSystemLibrary("crypto");
84+
ssh2_lib.linkSystemLibrary2("ssl", .{ .preferred_link_mode = openssl_linkage });
85+
ssh2_lib.linkSystemLibrary2("crypto", .{ .preferred_link_mode = openssl_linkage });
8286
}
8387

8488
if (wincng) {
8589
ssh2_lib.root_module.addCMacro("LIBSSH2_WINCNG", "1");
86-
// Windows system libs (zig handles names)
87-
ssh2_lib.linkSystemLibrary("bcrypt");
88-
ssh2_lib.linkSystemLibrary("ncrypt");
90+
ssh2_lib.linkSystemLibrary2("bcrypt", .{ .preferred_link_mode = wincng_linkage });
91+
ssh2_lib.linkSystemLibrary2("ncrypt", .{ .preferred_link_mode = wincng_linkage });
8992
}
9093

9194
if (libgcrypt) {
9295
ssh2_lib.root_module.addCMacro("LIBSSH2_LIBGCRYPT", "1");
93-
ssh2_lib.linkSystemLibrary("gcrypt");
96+
ssh2_lib.linkSystemLibrary2("gcrypt", .{ .preferred_link_mode = gcrypt_linkage });
9497
}
9598

9699
if (zlib) {

0 commit comments

Comments
 (0)