Skip to content

Lightpanda: the headless browser designed for AI and automation

`curl`: enable zstd

Halil Durak258a47ad5749
diff --git a/build.zig b/build.zig
index 0707fa034..bfd56af45 100644
--- a/build.zig
+++ b/build.zig
@@ -532,6 +532,9 @@ fn linkCurl(b: *Build, mod: *Build.Module, deps: Deps, is_tsan: bool, section: b
const brotli = buildBrotli(b, deps.target, deps.optimize, is_tsan, section);
for (brotli) |lib| curl.root_module.linkLibrary(lib);
+ const zstd = buildZstd(b, deps.target, deps.optimize, is_tsan, section);
+ curl.root_module.linkLibrary(zstd);
+
const nghttp2 = buildNghttp2(b, deps.target, deps.optimize, is_tsan, section);
curl.root_module.linkLibrary(nghttp2);
@@ -627,6 +630,34 @@ fn buildBrotli(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optim
return .{ brotlicmn, brotlidec, brotlienc };
}
+fn buildZstd(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize, is_tsan: bool, section: bool) *Build.Step.Compile {
+ const dep = b.dependency("zstd", .{});
+
+ const mod = cLibModule(b, target, optimize, is_tsan);
+ const lib = sectionize(b.addLibrary(.{ .name = "zstd", .root_module = mod }), section);
+ lib.installHeader(dep.path("lib/zstd.h"), "zstd.h");
+ lib.installHeader(dep.path("lib/zstd_errors.h"), "zstd_errors.h");
+ // curl only decodes, so the compressor is left out.
+ mod.addCSourceFiles(.{
+ .root = dep.path("lib"),
+ .flags = &.{
+ // RFC 9659 caps the zstd content coding's window at 8MB, as Chrome does.
+ "-DZSTD_MAXWINDOWSIZE_DEFAULT=(1<<23)",
+ },
+ .files = &.{
+ "common/debug.c", "common/entropy_common.c",
+ "common/error_private.c", "common/fse_decompress.c",
+ "common/xxhash.c", "common/zstd_common.c",
+ "decompress/huf_decompress.c", "decompress/zstd_ddict.c",
+ "decompress/zstd_decompress.c", "decompress/zstd_decompress_block.c",
+ // Empty unless the x86_64 BMI2 fast path is enabled.
+ "decompress/huf_decompress_amd64.S",
+ },
+ });
+
+ return lib;
+}
+
fn buildBoringSsl(b: *Build, target: Build.ResolvedTarget, optimize: std.lang.Optimize, section: bool) [2]*Build.Step.Compile {
const dep = b.dependency("boringssl-zig", .{
.target = target,
@@ -721,6 +752,7 @@ fn buildCurl(
const config = .{
.HAVE_LIBZ = true,
.HAVE_BROTLI = true,
+ .HAVE_ZSTD = true,
.USE_NGHTTP2 = true,
.USE_OPENSSL = true,
diff --git a/build.zig.zon b/build.zig.zon
index 36d0d6241..c2d740db0 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -18,6 +18,10 @@
.url = "https://github.com/madler/zlib/releases/download/v1.3.2/zlib-1.3.2.tar.gz",
.hash = "N-V-__8AAJ2cNgAgfBtAw33Bxfu1IWISDeKKSr3DAqoAysIJ",
},
+ .zstd = .{
+ .url = "https://github.com/facebook/zstd/releases/download/v1.5.7/zstd-1.5.7.tar.gz",
+ .hash = "N-V-__8AAPZ7fwBg4JoCzM_0o2A8wxH2hsUUeiU1iuZv53L5",
+ },
.nghttp2 = .{
.url = "https://github.com/nghttp2/nghttp2/releases/download/v1.70.0/nghttp2-1.70.0.tar.gz",
.hash = "N-V-__8AACay2gDbHrByjNGWvyH8G9Gp30uRgZqobYOF1nhb",