@@ -40,15 +40,15 @@ pub fn build(b: *std.Build) !void {
40
40
"-fno-sanitize=undefined" ,
41
41
};
42
42
43
- const openssl = b . option ( bool , "enable-openssl" , "Use OpenSSL instead of MbedTLS" ) orelse false ;
43
+ // The TLS backend logic is only run for non windows builds.
44
44
var tls_dep : ? * std.Build.Dependency = null ;
45
+ const tls_backend = b .option (
46
+ TlsBackend ,
47
+ "tls-backend" ,
48
+ "Choose Unix TLS/SSL backend (default is mbedtls)" ,
49
+ ) orelse .mbedtls ;
45
50
46
51
if (target .result .os .tag == .windows ) {
47
- if (openssl ) {
48
- std .log .err ("OpenSSL option unsupported on Windows" , .{});
49
- return ;
50
- }
51
-
52
52
lib .linkSystemLibrary ("winhttp" );
53
53
lib .linkSystemLibrary ("rpcrt4" );
54
54
lib .linkSystemLibrary ("crypt32" );
@@ -69,42 +69,43 @@ pub fn build(b: *std.Build) !void {
69
69
lib .addWin32ResourceFile (.{ .file = libgit_src .path ("src/libgit2/git2.rc" ) });
70
70
lib .addCSourceFiles (.{ .root = libgit_root , .files = & util_win32_sources , .flags = & flags });
71
71
} else {
72
- if (openssl ) {
73
- // OpenSSL backend
74
- tls_dep = b .lazyDependency ("openssl" , .{
75
- .target = target ,
76
- .optimize = optimize ,
77
- });
78
- if (tls_dep ) | tls | lib .linkLibrary (tls .artifact ("openssl" ));
79
- features .addValues (.{
80
- .GIT_HTTPS = 1 ,
81
- .GIT_OPENSSL = 1 ,
82
-
83
- .GIT_SHA1_COLLISIONDETECT = 1 ,
84
- .GIT_SHA256_OPENSSL = 1 ,
85
-
86
- .GIT_USE_FUTIMENS = 1 ,
87
- .GIT_IO_POLL = 1 ,
88
- .GIT_IO_SELECT = 1 ,
89
- });
90
- } else {
91
- // MbedTLS backend
92
- tls_dep = b .lazyDependency ("mbedtls" , .{
93
- .target = target ,
94
- .optimize = optimize ,
95
- });
96
- if (tls_dep ) | tls | lib .linkLibrary (tls .artifact ("mbedtls" ));
97
- features .addValues (.{
98
- .GIT_HTTPS = 1 ,
99
- .GIT_MBEDTLS = 1 ,
100
-
101
- .GIT_SHA1_COLLISIONDETECT = 1 ,
102
- .GIT_SHA256_MBEDTLS = 1 ,
103
-
104
- .GIT_USE_FUTIMENS = 1 ,
105
- .GIT_IO_POLL = 1 ,
106
- .GIT_IO_SELECT = 1 ,
107
- });
72
+ switch (tls_backend ) {
73
+ .openssl = > {
74
+ tls_dep = b .lazyDependency ("openssl" , .{
75
+ .target = target ,
76
+ .optimize = optimize ,
77
+ });
78
+ if (tls_dep ) | tls | lib .linkLibrary (tls .artifact ("openssl" ));
79
+ features .addValues (.{
80
+ .GIT_HTTPS = 1 ,
81
+ .GIT_OPENSSL = 1 ,
82
+
83
+ .GIT_SHA1_COLLISIONDETECT = 1 ,
84
+ .GIT_SHA256_OPENSSL = 1 ,
85
+
86
+ .GIT_USE_FUTIMENS = 1 ,
87
+ .GIT_IO_POLL = 1 ,
88
+ .GIT_IO_SELECT = 1 ,
89
+ });
90
+ },
91
+ .mbedtls = > {
92
+ tls_dep = b .lazyDependency ("mbedtls" , .{
93
+ .target = target ,
94
+ .optimize = optimize ,
95
+ });
96
+ if (tls_dep ) | tls | lib .linkLibrary (tls .artifact ("mbedtls" ));
97
+ features .addValues (.{
98
+ .GIT_HTTPS = 1 ,
99
+ .GIT_MBEDTLS = 1 ,
100
+
101
+ .GIT_SHA1_COLLISIONDETECT = 1 ,
102
+ .GIT_SHA256_MBEDTLS = 1 ,
103
+
104
+ .GIT_USE_FUTIMENS = 1 ,
105
+ .GIT_IO_POLL = 1 ,
106
+ .GIT_IO_SELECT = 1 ,
107
+ });
108
+ },
108
109
}
109
110
110
111
// ntlmclient
@@ -116,16 +117,16 @@ pub fn build(b: *std.Build) !void {
116
117
.link_libc = true ,
117
118
});
118
119
ntlm .addIncludePath (libgit_src .path ("deps/ntlmclient" ));
119
- addTlsHeaders (ntlm , tls_dep , openssl );
120
+ maybeAddTlsIncludes (ntlm , tls_dep , tls_backend );
120
121
121
122
const ntlm_cflags = .{
122
123
"-Wno-implicit-fallthrough" ,
123
124
"-DNTLM_STATIC=1" ,
124
125
"-DUNICODE_BUILTIN=1" ,
125
- if ( openssl )
126
- "-DCRYPT_OPENSSL"
127
- else
128
- "-DCRYPT_MBEDTLS" ,
126
+ switch ( tls_backend ) {
127
+ .openssl = > "-DCRYPT_OPENSSL" ,
128
+ .mbedtls = > "-DCRYPT_MBEDTLS" ,
129
+ } ,
129
130
};
130
131
ntlm .addCSourceFiles (.{
131
132
.root = libgit_root ,
@@ -134,10 +135,9 @@ pub fn build(b: *std.Build) !void {
134
135
});
135
136
ntlm .addCSourceFiles (.{
136
137
.root = libgit_root ,
137
- .files = if (openssl ) &.{
138
- "deps/ntlmclient/crypt_openssl.c" ,
139
- } else &.{
140
- "deps/ntlmclient/crypt_mbedtls.c" ,
138
+ .files = switch (tls_backend ) {
139
+ .openssl = > &.{"deps/ntlmclient/crypt_openssl.c" },
140
+ .mbedtls = > &.{"deps/ntlmclient/crypt_mbedtls.c" },
141
141
},
142
142
.flags = & ntlm_cflags ,
143
143
});
@@ -154,10 +154,9 @@ pub fn build(b: *std.Build) !void {
154
154
});
155
155
lib .addCSourceFiles (.{
156
156
.root = libgit_root ,
157
- .files = if (openssl ) &.{
158
- "src/util/hash/openssl.c" ,
159
- } else &.{
160
- "src/util/hash/mbedtls.c" ,
157
+ .files = switch (tls_backend ) {
158
+ .openssl = > &.{"src/util/hash/openssl.c" },
159
+ .mbedtls = > &.{"src/util/hash/mbedtls.c" },
161
160
},
162
161
.flags = & flags ,
163
162
});
@@ -310,7 +309,7 @@ pub fn build(b: *std.Build) !void {
310
309
cli .addIncludePath (libgit_src .path ("include" ));
311
310
cli .addIncludePath (libgit_src .path ("src/util" ));
312
311
cli .addIncludePath (libgit_src .path ("src/cli" ));
313
- addTlsHeaders (cli , tls_dep , openssl );
312
+ maybeAddTlsIncludes (cli , tls_dep , tls_backend );
314
313
315
314
if (target .result .os .tag == .windows )
316
315
cli .addCSourceFiles (.{ .root = libgit_root , .files = & cli_win32_sources })
@@ -355,7 +354,7 @@ pub fn build(b: *std.Build) !void {
355
354
});
356
355
357
356
exe .addIncludePath (libgit_src .path ("include" ));
358
- addTlsHeaders (exe , tls_dep , openssl );
357
+ maybeAddTlsIncludes (exe , tls_dep , tls_backend );
359
358
exe .linkLibrary (lib );
360
359
361
360
// independent install step so you can easily access the binary
@@ -385,7 +384,7 @@ pub fn build(b: *std.Build) !void {
385
384
tests .addConfigHeader (features );
386
385
tests .addIncludePath (libgit_src .path ("include" ));
387
386
tests .addIncludePath (libgit_src .path ("src/util" ));
388
- addTlsHeaders (tests , tls_dep , openssl );
387
+ maybeAddTlsIncludes (tests , tls_dep , tls_backend );
389
388
390
389
tests .linkLibrary (lib );
391
390
@@ -394,10 +393,20 @@ pub fn build(b: *std.Build) !void {
394
393
}
395
394
}
396
395
397
- fn addTlsHeaders (compile : * std.Build.Step.Compile , tls_dep : ? * std.Build.Dependency , openssl_or_mbedtls : bool ) void {
398
- if (tls_dep ) | tls | compile .addIncludePath (
399
- tls .artifact (if (openssl_or_mbedtls ) "openssl" else "mbedtls" ).getEmittedIncludeTree (),
400
- );
396
+ const TlsBackend = enum { openssl , mbedtls };
397
+
398
+ fn maybeAddTlsIncludes (
399
+ compile : * std.Build.Step.Compile ,
400
+ dep : ? * std.Build.Dependency ,
401
+ backend : TlsBackend ,
402
+ ) void {
403
+ if (dep ) | tls | {
404
+ const name = switch (backend ) {
405
+ .openssl = > "openssl" ,
406
+ .mbedtls = > "mbedtls" ,
407
+ };
408
+ compile .addIncludePath (tls .artifact (name ).getEmittedIncludeTree ());
409
+ }
401
410
}
402
411
403
412
const libgit_sources = [_ ][]const u8 {
0 commit comments