Merge pull request #620 from lightpanda-io/upgrade_v8
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

Upgrade v8
This commit is contained in:
Karl Seguin
2025-05-16 08:17:15 +08:00
committed by GitHub
6 changed files with 59 additions and 63 deletions

View File

@@ -17,11 +17,11 @@ inputs:
zig-v8: zig-v8:
description: 'zig v8 version to install' description: 'zig v8 version to install'
required: false required: false
default: 'v0.1.21' default: 'v0.1.22'
v8: v8:
description: 'v8 version to install' description: 'v8 version to install'
required: false required: false
default: '11.1.134' default: '13.6.233.8'
cache-dir: cache-dir:
description: 'cache dir to use' description: 'cache dir to use'
required: false required: false
@@ -59,11 +59,11 @@ runs:
- name: install v8 - name: install v8
shell: bash shell: bash
run: | run: |
mkdir -p v8/build/${{inputs.arch}}-${{inputs.os}}/debug/ninja/obj/zig/ mkdir -p v8/out/debug/obj/zig/
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/build/${{inputs.arch}}-${{inputs.os}}/debug/ninja/obj/zig/libc_v8.a ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/out/debug/obj/zig/libc_v8.a
mkdir -p v8/build/${{inputs.arch}}-${{inputs.os}}/release/ninja/obj/zig/ mkdir -p v8/out/release/obj/zig/
ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/build/${{inputs.arch}}-${{inputs.os}}/release/ninja/obj/zig/libc_v8.a ln -s ${{ inputs.cache-dir }}/v8/libc_v8.a v8/out/release/obj/zig/libc_v8.a
- name: libiconv - name: libiconv
shell: bash shell: bash

View File

@@ -5,7 +5,7 @@ ARG ZIG=0.14.0
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
ARG ARCH=x86_64 ARG ARCH=x86_64
ARG V8=11.1.134 ARG V8=11.1.134
ARG ZIG_V8=v0.1.21 ARG ZIG_V8=v0.1.22
RUN apt-get update -yq && \ RUN apt-get update -yq && \
apt-get install -yq xz-utils \ apt-get install -yq xz-utils \

View File

@@ -161,7 +161,7 @@ For Debian/Ubuntu based Linux:
sudo apt install xz-utils \ sudo apt install xz-utils \
python3 ca-certificates git \ python3 ca-certificates git \
pkg-config libglib2.0-dev \ pkg-config libglib2.0-dev \
gperf libexpat1-dev \ gperf libexpat1-dev unzip \
cmake clang cmake clang
``` ```

View File

@@ -158,29 +158,25 @@ fn common(b: *std.Build, opts: *std.Build.Step.Options, step: *std.Build.Step.Co
mod.addImport("v8", v8_mod); mod.addImport("v8", v8_mod);
} }
const mode_str: []const u8 = if (mod.optimize.? == .Debug) "debug" else "release";
// FIXME: we are tied to native v8 builds, currently:
// - aarch64-macos
// - x86_64-linux
const os = target.result.os.tag;
const arch = target.result.cpu.arch;
switch (os) {
.macos => {},
.linux => {
// TODO: why do we need it? It should be linked already when we built v8
mod.link_libcpp = true;
},
else => return error.OsNotSupported,
}
const lib_path = try std.fmt.allocPrint( const lib_path = try std.fmt.allocPrint(
mod.owner.allocator, mod.owner.allocator,
"v8/build/{s}-{s}/{s}/ninja/obj/zig/libc_v8.a", "v8/out/{s}/obj/zig/libc_v8.a",
.{ @tagName(arch), @tagName(os), mode_str }, .{if (mod.optimize.? == .Debug) "debug" else "release"},
); );
mod.link_libcpp = true;
mod.addObjectFile(mod.owner.path(lib_path)); mod.addObjectFile(mod.owner.path(lib_path));
switch (target.result.os.tag) {
.macos => {
// v8 has a dependency, abseil-cpp, which, on Mac, uses CoreFoundation
mod.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
mod.linkFramework("CoreFoundation", .{});
},
else => {},
}
mod.addImport("build_info", opts.createModule()); mod.addImport("build_info", opts.createModule());
mod.addObjectFile(mod.owner.path(lib_path));
} }
fn moduleNetSurf(b: *std.Build, step: *std.Build.Step.Compile, target: std.Build.ResolvedTarget) !void { fn moduleNetSurf(b: *std.Build, step: *std.Build.Step.Compile, target: std.Build.ResolvedTarget) !void {

View File

@@ -13,8 +13,8 @@
.hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd", .hash = "tigerbeetle_io-0.0.0-ViLgxpyRBAB5BMfIcj3KMXfbJzwARs9uSl8aRy2OXULd",
}, },
.v8 = .{ .v8 = .{
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/fc764e7d29bc1514924e8df09255a057e03d453a.tar.gz", .url = "https://github.com/lightpanda-io/zig-v8-fork/archive/4809111f930293c6d5082971ad7ffc3d822b6f37.tar.gz",
.hash = "v8-0.0.0-xddH6zUZIQBJf109L94sC-mWH1NJXWCnOJGJttKtfasI", .hash = "v8-0.0.0-xddH632xAwAjF7ieh48tjbMpu7fVVGr3r3aLwmBbFvPk",
}, },
//.v8 = .{ .path = "../zig-v8-fork" }, //.v8 = .{ .path = "../zig-v8-fork" },
//.tigerbeetle_io = .{ .path = "../tigerbeetle-io" }, //.tigerbeetle_io = .{ .path = "../tigerbeetle-io" },

View File

@@ -594,7 +594,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
var origin: ?v8.ScriptOrigin = null; var origin: ?v8.ScriptOrigin = null;
if (name) |n| { if (name) |n| {
const scr_name = v8.String.initUtf8(isolate, n); const scr_name = v8.String.initUtf8(isolate, n);
origin = v8.ScriptOrigin.initDefault(self.isolate, scr_name.toValue()); origin = v8.ScriptOrigin.initDefault(scr_name.toValue());
} }
const scr_js = v8.String.initUtf8(isolate, src); const scr_js = v8.String.initUtf8(isolate, src);
const scr = v8.Script.compile(context, scr_js, origin) catch { const scr = v8.Script.compile(context, scr_js, origin) catch {
@@ -1142,7 +1142,6 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
const script_source = v8.String.initUtf8(isolate, src); const script_source = v8.String.initUtf8(isolate, src);
const origin = v8.ScriptOrigin.init( const origin = v8.ScriptOrigin.init(
isolate,
script_name.toValue(), script_name.toValue(),
0, // resource_line_offset 0, // resource_line_offset
0, // resource_column_offset 0, // resource_column_offset
@@ -1201,14 +1200,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
if (@hasDecl(Struct, "get_symbol_toStringTag") == false) { if (@hasDecl(Struct, "get_symbol_toStringTag") == false) {
// If this WAS defined, then we would have created it in generateProperty. // If this WAS defined, then we would have created it in generateProperty.
// But if it isn't, we create a default one // But if it isn't, we create a default one
const key = v8.Symbol.getToStringTag(isolate).toName(); const string_tag_callback = v8.FunctionTemplate.initCallback(isolate, struct {
template_proto.setGetter(key, struct { fn stringTag(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
fn stringTag(_: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void { const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
const class_name = v8.String.initUtf8(info.getIsolate(), comptime classNameForStruct(Struct)); const class_name = v8.String.initUtf8(info.getIsolate(), comptime classNameForStruct(Struct));
info.getReturnValue().set(class_name); info.getReturnValue().set(class_name);
} }
}.stringTag); }.stringTag);
const key = v8.Symbol.getToStringTag(isolate).toName();
template_proto.setAccessorGetter(key, string_tag_callback);
} }
generateIndexer(Struct, template_proto); generateIndexer(Struct, template_proto);
@@ -1309,9 +1309,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
js_name = v8.String.initUtf8(isolate, name).toName(); js_name = v8.String.initUtf8(isolate, name).toName();
} }
const getter_callback = struct { const getter_callback = v8.FunctionTemplate.initCallback(isolate, struct {
fn callback(_: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void { fn callback(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
const info = v8.PropertyCallbackInfo.initFromV8(raw_info); const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
var caller = Caller(Self, State).init(info); var caller = Caller(Self, State).init(info);
defer caller.deinit(); defer caller.deinit();
@@ -1320,28 +1320,30 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
caller.handleError(Struct, named_function, err, info); caller.handleError(Struct, named_function, err, info);
}; };
} }
}.callback; }.callback);
const setter_name = "set_" ++ name; const setter_name = "set_" ++ name;
if (@hasDecl(Struct, setter_name) == false) { if (@hasDecl(Struct, setter_name) == false) {
template_proto.setGetter(js_name, getter_callback); template_proto.setAccessorGetter(js_name, getter_callback);
return; return;
} }
const setter_callback = struct { const setter_callback = v8.FunctionTemplate.initCallback(isolate, struct {
fn callback(_: ?*const v8.C_Name, raw_value: ?*const v8.C_Value, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void { fn callback(raw_info: ?*const v8.C_FunctionCallbackInfo) callconv(.c) void {
const info = v8.PropertyCallbackInfo.initFromV8(raw_info); const info = v8.FunctionCallbackInfo.initFromV8(raw_info);
var caller = Caller(Self, State).init(info); var caller = Caller(Self, State).init(info);
defer caller.deinit(); defer caller.deinit();
const js_value = v8.Value{ .handle = raw_value.? }; std.debug.assert(info.length() == 1);
const js_value = info.getArg(0);
const named_function = comptime NamedFunction.init(Struct, "set_" ++ name); const named_function = comptime NamedFunction.init(Struct, "set_" ++ name);
caller.setter(Struct, named_function, js_value, info) catch |err| { caller.setter(Struct, named_function, js_value, info) catch |err| {
caller.handleError(Struct, named_function, err, info); caller.handleError(Struct, named_function, err, info);
}; };
} }
}.callback; }.callback);
template_proto.setGetterAndSetter(js_name, getter_callback, setter_callback);
template_proto.setAccessorGetterAndSetter(js_name, getter_callback, setter_callback);
} }
fn generateIndexer(comptime Struct: type, template_proto: v8.ObjectTemplate) void { fn generateIndexer(comptime Struct: type, template_proto: v8.ObjectTemplate) void {
@@ -1350,14 +1352,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
} }
const configuration = v8.IndexedPropertyHandlerConfiguration{ const configuration = v8.IndexedPropertyHandlerConfiguration{
.getter = struct { .getter = struct {
fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void { fn callback(idx: u32, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
const info = v8.PropertyCallbackInfo.initFromV8(raw_info); const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
var caller = Caller(Self, State).init(info); var caller = Caller(Self, State).init(info);
defer caller.deinit(); defer caller.deinit();
const named_function = comptime NamedFunction.init(Struct, "indexed_get"); const named_function = comptime NamedFunction.init(Struct, "indexed_get");
caller.getIndex(Struct, named_function, idx, info) catch |err| { return caller.getIndex(Struct, named_function, idx, info) catch |err| blk: {
caller.handleError(Struct, named_function, err, info); caller.handleError(Struct, named_function, err, info);
break :blk v8.Intercepted.No;
}; };
} }
}.callback, }.callback,
@@ -1379,14 +1382,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
} }
const configuration = v8.NamedPropertyHandlerConfiguration{ const configuration = v8.NamedPropertyHandlerConfiguration{
.getter = struct { .getter = struct {
fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) void { fn callback(c_name: ?*const v8.C_Name, raw_info: ?*const v8.C_PropertyCallbackInfo) callconv(.c) u8 {
const info = v8.PropertyCallbackInfo.initFromV8(raw_info); const info = v8.PropertyCallbackInfo.initFromV8(raw_info);
var caller = Caller(Self, State).init(info); var caller = Caller(Self, State).init(info);
defer caller.deinit(); defer caller.deinit();
const named_function = comptime NamedFunction.init(Struct, "named_get"); const named_function = comptime NamedFunction.init(Struct, "named_get");
caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| { return caller.getNamedIndex(Struct, named_function, .{ .handle = c_name.? }, info) catch |err| blk: {
caller.handleError(Struct, named_function, err, info); caller.handleError(Struct, named_function, err, info);
break :blk v8.Intercepted.No;
}; };
} }
}.callback, }.callback,
@@ -1762,7 +1766,7 @@ fn Caller(comptime E: type, comptime State: type) type {
info.getReturnValue().set(try self.zigValueToJs(res)); info.getReturnValue().set(try self.zigValueToJs(res));
} }
fn getter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, info: v8.PropertyCallbackInfo) !void { fn getter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, info: v8.FunctionCallbackInfo) !void {
const func = @field(Struct, named_function.name); const func = @field(Struct, named_function.name);
const Getter = @TypeOf(func); const Getter = @TypeOf(func);
if (@typeInfo(Getter).@"fn".return_type == null) { if (@typeInfo(Getter).@"fn".return_type == null) {
@@ -1788,7 +1792,7 @@ fn Caller(comptime E: type, comptime State: type) type {
info.getReturnValue().set(try self.zigValueToJs(res)); info.getReturnValue().set(try self.zigValueToJs(res));
} }
fn setter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, js_value: v8.Value, info: v8.PropertyCallbackInfo) !void { fn setter(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, js_value: v8.Value, info: v8.FunctionCallbackInfo) !void {
const func = @field(Struct, named_function.name); const func = @field(Struct, named_function.name);
comptime assertSelfReceiver(Struct, named_function); comptime assertSelfReceiver(Struct, named_function);
@@ -1820,7 +1824,7 @@ fn Caller(comptime E: type, comptime State: type) type {
_ = @call(.auto, func, args); _ = @call(.auto, func, args);
} }
fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !void { fn getIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, idx: u32, info: v8.PropertyCallbackInfo) !u8 {
const func = @field(Struct, named_function.name); const func = @field(Struct, named_function.name);
const IndexedGet = @TypeOf(func); const IndexedGet = @TypeOf(func);
if (@typeInfo(IndexedGet).@"fn".return_type == null) { if (@typeInfo(IndexedGet).@"fn".return_type == null) {
@@ -1849,15 +1853,13 @@ fn Caller(comptime E: type, comptime State: type) type {
const res = @call(.auto, func, args); const res = @call(.auto, func, args);
if (has_value == false) { if (has_value == false) {
// for an indexed parameter, say nodes[10000], we should return return v8.Intercepted.No;
// undefined, not null, if the index is out of rante
info.getReturnValue().set(try self.zigValueToJs({}));
} else {
info.getReturnValue().set(try self.zigValueToJs(res));
} }
info.getReturnValue().set(try self.zigValueToJs(res));
return v8.Intercepted.Yes;
} }
fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !void { fn getNamedIndex(self: *Self, comptime Struct: type, comptime named_function: NamedFunction, name: v8.Name, info: v8.PropertyCallbackInfo) !u8 {
const func = @field(Struct, named_function.name); const func = @field(Struct, named_function.name);
const NamedGet = @TypeOf(func); const NamedGet = @TypeOf(func);
if (@typeInfo(NamedGet).@"fn".return_type == null) { if (@typeInfo(NamedGet).@"fn".return_type == null) {
@@ -1885,12 +1887,10 @@ fn Caller(comptime E: type, comptime State: type) type {
const res = @call(.auto, func, args); const res = @call(.auto, func, args);
if (has_value == false) { if (has_value == false) {
// for an indexed parameter, say nodes[10000], we should return return v8.Intercepted.No;
// undefined, not null, if the index is out of rante
info.getReturnValue().set(try self.zigValueToJs({}));
} else {
info.getReturnValue().set(try self.zigValueToJs(res));
} }
info.getReturnValue().set(try self.zigValueToJs(res));
return v8.Intercepted.Yes;
} }
fn nameToString(self: *Self, name: v8.Name) ![]const u8 { fn nameToString(self: *Self, name: v8.Name) ![]const u8 {