@@ -40,6 +40,11 @@ pub fn build(b: *std.Build) !void {
40
40
"-fno-sanitize=undefined" ,
41
41
};
42
42
43
+ const openssl = switch (target .result .os .tag ) {
44
+ .linux = > b .option (bool , "enable-openssl" , "Enable OpenSSL support" ) orelse false ,
45
+ else = > false ,
46
+ };
47
+
43
48
if (target .result .os .tag == .windows ) {
44
49
lib .linkSystemLibrary ("winhttp" );
45
50
lib .linkSystemLibrary ("rpcrt4" );
@@ -61,20 +66,37 @@ pub fn build(b: *std.Build) !void {
61
66
lib .addWin32ResourceFile (.{ .file = libgit_src .path ("src/libgit2/git2.rc" ) });
62
67
lib .addCSourceFiles (.{ .root = libgit_root , .files = & util_win32_sources , .flags = & flags });
63
68
} else {
64
- // mbedTLS https and SHA backend
65
- lib .linkSystemLibrary ("mbedtls" );
66
- lib .linkSystemLibrary ("mbedcrypto" );
67
- lib .linkSystemLibrary ("mbedx509" );
68
- features .addValues (.{
69
- .GIT_HTTPS = 1 ,
70
- .GIT_MBEDTLS = 1 ,
71
- .GIT_SHA1_MBEDTLS = 1 ,
72
- .GIT_SHA256_MBEDTLS = 1 ,
73
-
74
- .GIT_USE_FUTIMENS = 1 ,
75
- .GIT_IO_POLL = 1 ,
76
- .GIT_IO_SELECT = 1 ,
77
- });
69
+ if (openssl ) {
70
+ // OpenSSL backend
71
+ const openssl_dep = b .dependency ("openssl" , .{});
72
+ const openssl_lib = openssl_dep .artifact ("openssl" );
73
+ lib .linkLibrary (openssl_lib );
74
+ features .addValues (.{
75
+ .GIT_HTTPS = 1 ,
76
+ .GIT_OPENSSL = 1 ,
77
+ .GIT_SHA1_OPENSSL = 1 ,
78
+ .GIT_SHA256_OPENSSL = 1 ,
79
+
80
+ .GIT_USE_FUTIMENS = 1 ,
81
+ .GIT_IO_POLL = 1 ,
82
+ .GIT_IO_SELECT = 1 ,
83
+ });
84
+ } else {
85
+ // mbedTLS https and SHA backend
86
+ lib .linkSystemLibrary ("mbedtls" );
87
+ lib .linkSystemLibrary ("mbedcrypto" );
88
+ lib .linkSystemLibrary ("mbedx509" );
89
+ features .addValues (.{
90
+ .GIT_HTTPS = 1 ,
91
+ .GIT_MBEDTLS = 1 ,
92
+ .GIT_SHA1_MBEDTLS = 1 ,
93
+ .GIT_SHA256_MBEDTLS = 1 ,
94
+
95
+ .GIT_USE_FUTIMENS = 1 ,
96
+ .GIT_IO_POLL = 1 ,
97
+ .GIT_IO_SELECT = 1 ,
98
+ });
99
+ }
78
100
79
101
// ntlmclient
80
102
{
@@ -85,15 +107,30 @@ pub fn build(b: *std.Build) !void {
85
107
.link_libc = true ,
86
108
});
87
109
ntlm .addIncludePath (libgit_src .path ("deps/ntlmclient" ));
110
+ if (openssl ) addOpenSSLHeaders (ntlm );
111
+
112
+ const ntlm_cflags = .{
113
+ "-Wno-implicit-fallthrough" ,
114
+ "-DNTLM_STATIC=1" ,
115
+ "-DUNICODE_BUILTIN=1" ,
116
+ if (openssl )
117
+ "-DCRYPT_OPENSSL"
118
+ else
119
+ "-DCRYPT_MBEDTLS" ,
120
+ };
88
121
ntlm .addCSourceFiles (.{
89
122
.root = libgit_root ,
90
123
.files = & ntlm_sources ,
91
- .flags = &.{
92
- "-Wno-implicit-fallthrough" ,
93
- "-DNTLM_STATIC=1" ,
94
- "-DUNICODE_BUILTIN=1" ,
95
- "-DCRYPT_MBEDTLS" ,
124
+ .flags = & ntlm_cflags ,
125
+ });
126
+ ntlm .addCSourceFiles (.{
127
+ .root = libgit_root ,
128
+ .files = if (openssl ) &.{
129
+ "deps/ntlmclient/crypt_openssl.c" ,
130
+ } else &.{
131
+ "deps/ntlmclient/crypt_mbedtls.c" ,
96
132
},
133
+ .flags = & ntlm_cflags ,
97
134
});
98
135
99
136
lib .linkLibrary (ntlm );
@@ -106,6 +143,15 @@ pub fn build(b: *std.Build) !void {
106
143
.files = & util_unix_sources ,
107
144
.flags = & flags ,
108
145
});
146
+ lib .addCSourceFiles (.{
147
+ .root = libgit_root ,
148
+ .files = if (openssl ) &.{
149
+ "src/util/hash/openssl.c" ,
150
+ } else &.{
151
+ "src/util/hash/mbedtls.c" ,
152
+ },
153
+ .flags = & flags ,
154
+ });
109
155
}
110
156
111
157
if (b .option (bool , "enable-ssh" , "Enable SSH support" ) orelse false ) {
@@ -249,6 +295,7 @@ pub fn build(b: *std.Build) !void {
249
295
cli .addIncludePath (libgit_src .path ("include" ));
250
296
cli .addIncludePath (libgit_src .path ("src/util" ));
251
297
cli .addIncludePath (libgit_src .path ("src/cli" ));
298
+ if (openssl ) addOpenSSLHeaders (cli );
252
299
253
300
if (target .result .os .tag == .windows )
254
301
cli .addCSourceFiles (.{ .root = libgit_root , .files = & cli_win32_sources })
@@ -293,6 +340,7 @@ pub fn build(b: *std.Build) !void {
293
340
});
294
341
295
342
exe .addIncludePath (libgit_src .path ("include" ));
343
+ if (openssl ) addOpenSSLHeaders (exe );
296
344
exe .linkLibrary (lib );
297
345
298
346
// independent install step so you can easily access the binary
@@ -322,6 +370,7 @@ pub fn build(b: *std.Build) !void {
322
370
tests .addConfigHeader (features );
323
371
tests .addIncludePath (libgit_src .path ("include" ));
324
372
tests .addIncludePath (libgit_src .path ("src/util" ));
373
+ if (openssl ) addOpenSSLHeaders (tests );
325
374
326
375
tests .linkLibrary (lib );
327
376
@@ -330,6 +379,13 @@ pub fn build(b: *std.Build) !void {
330
379
}
331
380
}
332
381
382
+ fn addOpenSSLHeaders (compile : * std.Build.Step.Compile ) void {
383
+ const b = compile .step .owner ;
384
+ const openssl_dep = b .dependency ("openssl" , .{});
385
+ const openssl_lib = openssl_dep .artifact ("openssl" );
386
+ compile .addIncludePath (openssl_lib .getEmittedIncludeTree ());
387
+ }
388
+
333
389
const libgit_sources = [_ ][]const u8 {
334
390
"src/libgit2/annotated_commit.c" ,
335
391
"src/libgit2/apply.c" ,
@@ -502,8 +558,6 @@ const util_unix_sources = [_][]const u8{
502
558
"src/util/unix/map.c" ,
503
559
"src/util/unix/process.c" ,
504
560
"src/util/unix/realpath.c" ,
505
-
506
- "src/util/hash/mbedtls.c" ,
507
561
};
508
562
509
563
const util_win32_sources = [_ ][]const u8 {
@@ -579,7 +633,6 @@ const xdiff_sources = [_][]const u8{
579
633
580
634
const ntlm_sources = [_ ][]const u8 {
581
635
"deps/ntlmclient/crypt_builtin_md4.c" ,
582
- "deps/ntlmclient/crypt_mbedtls.c" ,
583
636
"deps/ntlmclient/ntlm.c" ,
584
637
"deps/ntlmclient/unicode_builtin.c" ,
585
638
"deps/ntlmclient/util.c" ,
0 commit comments