-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.zig
More file actions
146 lines (131 loc) · 4.77 KB
/
build.zig
File metadata and controls
146 lines (131 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const std = @import("std");
const version: std.SemanticVersion = .{ .major = 1, .minor = 11, .patch = 1 };
const CryptoBackend = enum {
auto,
openssl,
mbedtls,
libgcrypt,
wincng,
};
pub fn build(b: *std.Build) void {
const upstream = b.dependency("libssh2", .{});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode") orelse .static;
const strip = b.option(bool, "strip", "Omit debug information");
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 is_windows = target.result.os.tag == .windows;
const mbedtls = crypto_choice == .mbedtls;
const openssl = (crypto_choice == .auto and !is_windows) or crypto_choice == .openssl;
const wincng = (crypto_choice == .auto and is_windows) or crypto_choice == .wincng;
const libgcrypt = crypto_choice == .libgcrypt;
const config_header = b.addConfigHeader(.{
.style = .{
.cmake = upstream.path("src/libssh2_config_cmake.h.in"),
},
.include_path = "libssh2_config.h",
}, .{
.LIBSSH2_API = switch (target.result.os.tag) {
.windows => "__declspec(dllexport)",
else => "",
},
.LIBSSH2_HAVE_ZLIB = zlib,
.HAVE_SYS_UIO_H = !is_windows,
.HAVE_WRITEV = !is_windows,
.HAVE_SYS_SOCKET_H = !is_windows,
.HAVE_NETINET_IN_H = !is_windows,
.HAVE_ARPA_INET_H = !is_windows,
.HAVE_SYS_TYPES_H = !is_windows,
.HAVE_INTTYPES_H = true,
.HAVE_STDINT_H = true,
});
const ssh2_lib = b.addLibrary(.{
.version = version,
.name = "ssh2",
.linkage = linkage,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
.pic = pic,
}),
});
b.installArtifact(ssh2_lib);
ssh2_lib.installHeadersDirectory(upstream.path("include"), "", .{});
ssh2_lib.root_module.addConfigHeader(config_header);
ssh2_lib.root_module.addIncludePath(upstream.path("include"));
ssh2_lib.root_module.addCMacro("HAVE_CONFIG_H", "1");
ssh2_lib.root_module.addCSourceFiles(.{ .files = ssh2_src, .root = upstream.path(""), .flags = ssh2_flags });
if (mbedtls) {
ssh2_lib.root_module.addCMacro("LIBSSH2_MBEDTLS", "1");
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");
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");
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");
if (link_system_crypto) {
ssh2_lib.root_module.linkSystemLibrary("gcrypt", .{});
}
}
if (zlib) {
if (b.systemIntegrationOption("zlib", .{})) {
ssh2_lib.root_module.linkSystemLibrary("zlib", .{});
} else if (b.lazyDependency("zlib", .{
.target = target,
.optimize = optimize,
})) |zlib_dependency| {
ssh2_lib.root_module.linkLibrary(zlib_dependency.artifact("z"));
}
}
}
pub const ssh2_src: []const []const u8 = &.{
"src/agent.c",
"src/bcrypt_pbkdf.c",
"src/blowfish.c",
"src/chacha.c",
"src/channel.c",
"src/cipher-chachapoly.c",
"src/comp.c",
"src/crypt.c",
"src/global.c",
"src/hostkey.c",
"src/keepalive.c",
"src/kex.c",
"src/knownhost.c",
"src/mac.c",
"src/misc.c",
"src/packet.c",
"src/pem.c",
"src/poly1305.c",
"src/publickey.c",
"src/scp.c",
"src/session.c",
"src/sftp.c",
"src/transport.c",
"src/userauth.c",
"src/userauth_kbd_packet.c",
"src/version.c",
"src/crypto.c",
};
pub const ssh2_flags: []const []const u8 = &.{};