From f4544da758d7bd53b61d0a955f329846265fa2b4 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Mon, 5 Oct 2026 11:33:42 +0800 Subject: [PATCH] Fix build Update zig-v8-fork dependency Optimize string.repeat Provide arraybuffer allocation max size (pre-merging https://github.com/lightpanda-io/browser/pull/3751 since the zig-v8-fork now needs it). --- .github/actions/install/action.yml | 2 +- .github/actions/v8-snapshot/action.yml | 2 +- Dockerfile | 2 +- build.zig | 4 +++- build.zig.zon | 4 ++-- src/browser/js/Env.zig | 2 +- src/browser/js/Snapshot.zig | 2 +- src/string.zig | 16 ++++++++-------- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/actions/install/action.yml b/.github/actions/install/action.yml index 631db155a..2fb1bfe5a 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/install/action.yml @@ -13,7 +13,7 @@ inputs: zig-v8: description: 'zig v8 version to install' required: false - default: 'v0.5.8' + default: 'v0.5.9' v8: description: 'v8 version to install' required: false diff --git a/.github/actions/v8-snapshot/action.yml b/.github/actions/v8-snapshot/action.yml index 53a0c8b2a..89b9ae06d 100644 --- a/.github/actions/v8-snapshot/action.yml +++ b/.github/actions/v8-snapshot/action.yml @@ -13,7 +13,7 @@ inputs: zig-v8: description: 'zig-v8 release tag the prebuilt lib came from' required: false - default: 'v0.5.8' + default: 'v0.5.9' runs: using: "composite" diff --git a/Dockerfile b/Dockerfile index 822aebd89..0b2455142 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM debian:stable-slim ARG MINISIG=0.12 ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U ARG V8=15.5.35.13 -ARG ZIG_V8=v0.5.8 +ARG ZIG_V8=v0.5.9 ARG TARGETPLATFORM RUN apt-get update -yq && \ diff --git a/build.zig b/build.zig index 8677c590d..0707fa034 100644 --- a/build.zig +++ b/build.zig @@ -306,11 +306,13 @@ fn findPrebuiltV8(b: *Build, target: Build.ResolvedTarget, dev_fast: bool) ?[]co @tagName(target.result.cpu.arch), }) }); }; - b.dependOnFileMetadata(b.path(path)); std.Io.Dir.cwd().access(io, rootPath(b, path), .{}) catch { + // Zig can't track a missing file as a configure dependency; the + // source-build path poisons the configure cache instead. std.debug.print("No prebuilt V8 at {s}; using the V8 source-build path. `make download-v8` fetches the prebuilt.\n", .{path}); return null; }; + b.dependOnFileMetadata(b.path(path)); std.debug.print("Using prebuilt V8: {s}\n", .{path}); return path; } diff --git a/build.zig.zon b/build.zig.zon index 3bf2fac20..36d0d6241 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,8 +5,8 @@ .minimum_zig_version = "0.17.0", .dependencies = .{ .v8 = .{ - .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/10f6a11e81fd4809988a24e3f5b3d5d4fd3a73fe.tar.gz", - .hash = "v8-0.0.0-xddH6w1QAwDcuJPtc73VXElNBsgPgrRBqQR__jWhy_C4", + .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/b73e4fa2d0afe5036745ae7d332cc5cb7e7adb53.tar.gz", + .hash = "v8-0.0.0-xddH64tVAwDZKW4zyy2h9cKXeWfWSjupsZIwTbYxSL9T", }, // .v8 = .{ .path = "../zig-v8-fork" }, .brotli = .{ diff --git a/src/browser/js/Env.zig b/src/browser/js/Env.zig index 7a10714bc..bfb523ac2 100644 --- a/src/browser/js/Env.zig +++ b/src/browser/js/Env.zig @@ -153,7 +153,7 @@ pub fn init(app: *App, opts: InitOpts) !Env { v8.v8__Isolate__CreateParams__CONSTRUCT(params); params.snapshot_blob = @ptrCast(&snapshot.startup_data); - params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator().?; + params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator(4 * 1024 * 1024 * 1024).?; errdefer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); params.external_references = &snapshot.external_references; diff --git a/src/browser/js/Snapshot.zig b/src/browser/js/Snapshot.zig index 35e5504b2..c2ab63146 100644 --- a/src/browser/js/Snapshot.zig +++ b/src/browser/js/Snapshot.zig @@ -142,7 +142,7 @@ pub fn create() !Snapshot { var params: v8.CreateParams = undefined; v8.v8__Isolate__CreateParams__CONSTRUCT(¶ms); - params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator(); + params.array_buffer_allocator = v8.v8__ArrayBuffer__Allocator__NewDefaultAllocator(4 * 1024 * 1024 * 1024); defer v8.v8__ArrayBuffer__Allocator__DELETE(params.array_buffer_allocator.?); params.external_references = @ptrCast(&external_references); diff --git a/src/string.zig b/src/string.zig index 4d9d76bc2..1d0230274 100644 --- a/src/string.zig +++ b/src/string.zig @@ -545,15 +545,15 @@ pub fn repeat(comptime s: []const u8, comptime n: usize) *const [s.len * n:0]u8 fn Repeated(comptime s: []const u8, comptime n: usize) type { return struct { const value: [s.len * n:0]u8 = blk: { - var buf: [s.len * n:0]u8 = undefined; - if (s.len == 1) { - buf = @splat(s[0]); - } else { - @setEvalBranchQuota(1000 + 10 * n); - for (0..n) |i| @memcpy(buf[i * s.len ..][0..s.len], s); + // Doubling: log2(n) concatenations instead of n comptime memcpys. + var acc: []const u8 = ""; + var pow: []const u8 = s; + var k = n; + while (k > 0) : (k >>= 1) { + if (k & 1 == 1) acc = acc ++ pow; + if (k > 1) pow = pow ++ pow; } - buf[buf.len] = 0; - break :blk buf; + break :blk acc[0 .. s.len * n].* ++ [_:0]u8{}; }; }; }