Skip to content

Lightpanda: the headless browser designed for AI and automation

dev: support for pre-build shared library

Karl Seguinaf99e845dff6
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7755d548c..055946755 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -16,6 +16,10 @@ By default the build compiles V8 from source, which takes several minutes. Run
[`zig-v8-fork`](https://github.com/lightpanda-io/zig-v8-fork/releases) releases
instead; later `make build` / `make test` pick it up automatically.
+On Linux x86_64, `make download-v8-shared` additionally fetches the shared
+flavor (`libc_v8.so`) that `zig build -Ddev_fast=true` picks up automatically
+for much faster debug rebuilds.
+
## Before opening a PR
- [ ] Tests pass (`make test`).
diff --git a/Makefile b/Makefile
index 0ec21e8ab..9085ae0a6 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,12 @@ ZIG_V8_TAG := $(shell awk -F\' '/^ zig-v8:/{f=1} f&&/default:/{print $$2; exit}
V8_ARCHIVE := libc_v8_$(V8_VERSION)_$(OS)_$(ARCH).a
V8_CACHE := .lp-cache/prebuilt-v8/$(ZIG_V8_TAG)/$(V8_ARCHIVE)
+# The shared flavor serves -Ddev_fast (Linux x86_64 Debug only). It is cached
+# under the name the exe's DT_NEEDED records, libc_v8.so; the tag directory
+# already keys freshness.
+V8_SO_ASSET := libc_v8_$(V8_VERSION)_$(OS)_$(ARCH).so
+V8_SO_CACHE := .lp-cache/prebuilt-v8/$(ZIG_V8_TAG)/libc_v8.so
+
# If the prebuilt archive is in place and the caller hasn't set ZIGFLAGS, point
# the build at it rather than building V8 from source.
ifeq ($(strip $(ZIGFLAGS)),)
@@ -79,7 +85,7 @@ help:
# $(ZIG) commands
# ------------
-.PHONY: build build-v8-snapshot build-dev download-v8 run run-release test bench data end2end clean
+.PHONY: build build-v8-snapshot build-dev download-v8 download-v8-shared run run-release test bench data end2end clean
## Download the prebuilt V8 archive (skips the 10+ min source build)
download-v8:
@@ -91,6 +97,16 @@ download-v8:
|| (rm -f $(V8_CACHE); printf "\033[33mDownload ERROR\033[0m\n"; exit 1) )
@printf "\033[33mV8 ready: %s\033[0m\n" "$(V8_CACHE)"
+## Download the prebuilt shared V8 used by -Ddev_fast builds (Linux x86_64)
+download-v8-shared:
+ @mkdir -p $(dir $(V8_SO_CACHE))
+ @test -f $(V8_SO_CACHE) || ( \
+ printf "\033[36mDownloading prebuilt shared V8 $(V8_VERSION) ($(ZIG_V8_TAG))...\033[0m\n"; \
+ curl -fL --progress-bar -o $(V8_SO_CACHE) \
+ https://github.com/lightpanda-io/zig-v8-fork/releases/download/$(ZIG_V8_TAG)/$(V8_SO_ASSET) \
+ || (rm -f $(V8_SO_CACHE); printf "\033[33mDownload ERROR\033[0m\n"; exit 1) )
+ @printf "\033[33mShared V8 ready: %s\033[0m\n" "$(V8_SO_CACHE)"
+
## Build v8 snapshot
build-v8-snapshot:
@printf "\033[36mBuilding v8 snapshot (release safe)...\033[0m\n"
diff --git a/build.zig b/build.zig
index a95a6ba8b..13716620a 100644
--- a/build.zig
+++ b/build.zig
@@ -64,7 +64,11 @@ pub fn build(b: *Build) !void {
}
}
- const prebuilt_v8_path = b.option([]const u8, "prebuilt_v8_path", "Path to prebuilt libc_v8.a");
+ // dev_fast links V8 shared, so it defaults to the libc_v8.so that
+ // `make download-v8-shared` caches (when present) rather than a
+ // multi-minute from-source build.
+ const prebuilt_v8_path = b.option([]const u8, "prebuilt_v8_path", "Path to a prebuilt libc_v8.a or libc_v8.so") orelse
+ if (dev_fast) findSharedV8Cache(b) else null;
const snapshot_path = b.option([]const u8, "snapshot_path", "Path to v8 snapshot");
const wpt_extensions = b.option(bool, "wpt_extensions", "Extend WebAPI with WPT driver behavior") orelse false;
const shared_v8 = b.option(bool, "shared_v8", "Link V8 as a shared library") orelse dev_fast;
@@ -247,6 +251,44 @@ pub fn build(b: *Build) !void {
}
}
+/// Looks for the shared V8 that `make download-v8-shared` caches. The cache
+/// path is keyed on the zig-v8 release tag, read from the install action so
+/// it cannot drift from CI (the Makefile reads the same source of truth).
+fn findSharedV8Cache(b: *Build) ?[]const u8 {
+ const io = b.graph.io;
+ const action = std.Io.Dir.cwd().readFileAlloc(
+ io,
+ b.pathFromRoot(".github/actions/install/action.yml"),
+ b.allocator,
+ .limited(64 * 1024),
+ ) catch return null;
+
+ const tag = blk: {
+ var in_zig_v8 = false;
+ var lines = std.mem.splitScalar(u8, action, '\n');
+ while (lines.next()) |line| {
+ if (std.mem.startsWith(u8, line, " ") and !std.mem.startsWith(u8, line, " ")) {
+ in_zig_v8 = std.mem.eql(u8, std.mem.trimEnd(u8, line, " \r"), " zig-v8:");
+ continue;
+ }
+ if (!in_zig_v8) continue;
+ const trimmed = std.mem.trim(u8, line, " \r");
+ if (std.mem.startsWith(u8, trimmed, "default:")) {
+ var it = std.mem.splitScalar(u8, trimmed, '\'');
+ _ = it.next();
+ break :blk it.next() orelse return null;
+ }
+ }
+ return null;
+ };
+ if (tag.len == 0) return null;
+
+ const path = b.fmt("{s}/prebuilt-v8/{s}/libc_v8.so", .{ b.pathFromRoot(".lp-cache"), tag });
+ std.Io.Dir.cwd().access(io, path, .{}) catch return null;
+ std.debug.print("Using prebuilt shared V8: {s}\n", .{path});
+ return path;
+}
+
fn linkV8(
b: *Build,
mod: *Build.Module,
diff --git a/build.zig.zon b/build.zig.zon
index 2c8bac0ee..af5e0dec6 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -5,8 +5,8 @@
.minimum_zig_version = "0.16.0",
.dependencies = .{
.v8 = .{
- .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/db264d2c4d70c09e102167799e99cebb8a74713f.tar.gz",
- .hash = "v8-0.0.0-xddH6wsDAwA_VE-G-JbVC9XnMTGzeuYmzGPmxHpj0KIF",
+ .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/47e8be3edae7a28071192556f1a5ffbf31774344.tar.gz",
+ .hash = "v8-0.0.0-xddH6x4GAwB6psyI4sllqMbK7cLkz-Bo3xC9WDheGksn",
},
// .v8 = .{ .path = "../zig-v8-fork" },
.brotli = .{