Skip to content

Commit 96a53c4

Browse files
committed
add an option to build libcurl with BoringSSL
1 parent 927cbe7 commit 96a53c4

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

build.zig

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub fn build(b: *Build) !void {
4646
b.option([]const u8, "git_commit", "Current git commit") orelse "dev",
4747
);
4848

49+
const use_boringssl = b.option(bool, "use-boringssl", "Whether use BoringSSL (default:false)") orelse false;
50+
4951
const target = b.standardTargetOptions(.{});
5052
const optimize = b.standardOptimizeOption(.{});
5153

@@ -59,15 +61,15 @@ pub fn build(b: *Build) !void {
5961
.link_libc = true,
6062
.link_libcpp = true,
6163
});
62-
try addDependencies(b, lightpanda_module, opts);
64+
try addDependencies(b, lightpanda_module, opts, use_boringssl);
6365

6466
{
6567
// browser
6668
// -------
6769

6870
// compile and install
6971
const exe = b.addExecutable(.{
70-
.name = "lightpanda",
72+
.name = if (use_boringssl) "lightpanda-boringssl" else "lightpanda-mbedtls",
7173
.use_llvm = true,
7274
.root_module = lightpanda_module,
7375
});
@@ -113,7 +115,7 @@ pub fn build(b: *Build) !void {
113115
.target = target,
114116
.optimize = optimize,
115117
});
116-
try addDependencies(b, wpt_module, opts);
118+
try addDependencies(b, wpt_module, opts, use_boringssl);
117119

118120
// compile and install
119121
const wpt = b.addExecutable(.{
@@ -151,7 +153,7 @@ pub fn build(b: *Build) !void {
151153
}
152154
}
153155

154-
fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !void {
156+
fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options, use_boringssl: bool) !void {
155157
try moduleNetSurf(b, mod);
156158
mod.addImport("build_config", opts.createModule());
157159

@@ -374,16 +376,39 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
374376
mod.addCMacro("STDC_HEADERS", "1");
375377
mod.addCMacro("TIME_WITH_SYS_TIME", "1");
376378
mod.addCMacro("USE_NGHTTP2", "1");
377-
mod.addCMacro("USE_MBEDTLS", "1");
379+
if (use_boringssl) {
380+
mod.addCMacro("USE_OPENSSL", "1");
381+
mod.addCMacro("OPENSSL_IS_BORINGSSL", "1");
382+
} else {
383+
mod.addCMacro("USE_MBEDTLS", "1");
384+
}
378385
mod.addCMacro("USE_THREADS_POSIX", "1");
379386
mod.addCMacro("USE_UNIX_SOCKETS", "1");
380387
}
381388

382389
try buildZlib(b, mod);
383390
try buildBrotli(b, mod);
384-
try buildMbedtls(b, mod);
391+
if (use_boringssl) {
392+
const maybe_boringssl_dep = b.lazyDependency("boringssl-zig", .{
393+
.target = target,
394+
.optimize = mod.optimize.?,
395+
.force_pic = true,
396+
});
397+
398+
if (maybe_boringssl_dep) |boringssl_dep| {
399+
const ssl = boringssl_dep.artifact("ssl");
400+
ssl.bundle_ubsan_rt = false;
401+
const crypto = boringssl_dep.artifact("crypto");
402+
crypto.bundle_ubsan_rt = false;
403+
404+
mod.linkLibrary(ssl);
405+
mod.linkLibrary(crypto);
406+
}
407+
} else {
408+
try buildMbedtls(b, mod);
409+
}
385410
try buildNghttp2(b, mod);
386-
try buildCurl(b, mod);
411+
try buildCurl(b, mod, use_boringssl);
387412
try buildAda(b, mod);
388413

389414
switch (target.result.os.tag) {
@@ -674,7 +699,7 @@ fn buildNghttp2(b: *Build, m: *Build.Module) !void {
674699
} });
675700
}
676701

677-
fn buildCurl(b: *Build, m: *Build.Module) !void {
702+
fn buildCurl(b: *Build, m: *Build.Module, use_boringssl: bool) !void {
678703
const curl = b.addLibrary(.{
679704
.name = "curl",
680705
.root_module = m,
@@ -842,13 +867,22 @@ fn buildCurl(b: *Build, m: *Build.Module) !void {
842867
root ++ "lib/vauth/spnego_sspi.c",
843868
root ++ "lib/vauth/vauth.c",
844869
root ++ "lib/vtls/cipher_suite.c",
845-
root ++ "lib/vtls/mbedtls.c",
846-
root ++ "lib/vtls/mbedtls_threadlock.c",
847870
root ++ "lib/vtls/vtls.c",
848871
root ++ "lib/vtls/vtls_scache.c",
849872
root ++ "lib/vtls/x509asn1.c",
850873
},
851874
});
875+
876+
curl.addCSourceFiles(.{
877+
.files = if (use_boringssl) &.{
878+
root ++ "lib/vtls/openssl.c",
879+
root ++ "lib/vtls/hostcheck.c",
880+
root ++ "lib/vtls/keylog.c",
881+
} else &.{
882+
root ++ "lib/vtls/mbedtls.c",
883+
root ++ "lib/vtls/mbedtls_threadlock.c",
884+
},
885+
});
852886
}
853887

854888
pub fn buildAda(b: *Build, m: *Build.Module) !void {

build.zig.zon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
.url = "https://github.com/ada-url/ada/releases/download/v3.3.0/singleheader.zip",
1414
.hash = "N-V-__8AAPmhFAAw64ALjlzd5YMtzpSrmZ6KymsT84BKfB4s",
1515
},
16+
.@"boringssl-zig" = .{
17+
.url = "git+https://github.com/Syndica/boringssl-zig.git#01b27c04e42cbb50173348bf2f225b2e223ef87a",
18+
.hash = "boringssl-0.1.0-VtJeWehMAAA4RNnwRnzEvKcS9rjsR1QVRw1uJrwXxmVK",
19+
.lazy = true,
20+
},
1621
},
1722
}

0 commit comments

Comments
 (0)