Skip to content

Commit 5013ca7

Browse files
committed
Zig 0.14 compatibility
1 parent 4f67135 commit 5013ca7

File tree

16 files changed

+157
-146
lines changed

16 files changed

+157
-146
lines changed

.github/actions/install/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
zig:
66
description: 'Zig version to install'
77
required: false
8-
default: '0.13.0'
8+
default: '0.14.0'
99
arch:
1010
description: 'CPU arch used to select the v8 lib'
1111
required: false

.github/workflows/zig-fmt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: zig-fmt
22

33
env:
4-
ZIG_VERSION: 0.13.0
4+
ZIG_VERSION: 0.14.0
55

66
on:
77
pull_request:

.gitmodules

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[submodule "vendor/zig-v8"]
22
path = vendor/zig-v8
3-
url = https://github.com/Browsercore/zig-v8-fork.git/
3+
url = https://github.com/lightpanda-io/zig-v8-fork.git/
4+
branch = zig-0.14
45
[submodule "vendor/tigerbeetle-io"]
56
path = vendor/tigerbeetle-io
6-
url = https://github.com/Browsercore/tigerbeetle-io.git/
7+
url = https://github.com/lightpanda-io/tigerbeetle-io.git/
8+
branch = zig-0.14
79
[submodule "vendor/linenoise-mob"]
810
path = vendor/linenoise-mob
911
url = https://github.com/rain-1/linenoise-mob.git/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ exit with Ctrl+D or "exit"
153153

154154
### Prerequisites
155155

156-
zig-js-runtime is written with [Zig](https://ziglang.org/) `0.13.0`. You have to
156+
zig-js-runtime is written with [Zig](https://ziglang.org/) `0.14.0`. You have to
157157
install it with the right version in order to build the project.
158158

159159
To be able to build the v8 engine, you have to install some libs:

build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const pkgs = packages("");
2020

2121
/// Do not rename this constant. It is scanned by some scripts to determine
2222
/// which zig version to install.
23-
pub const recommended_zig_version = "0.13.0";
23+
pub const recommended_zig_version = "0.14.0";
2424

2525
pub fn build(b: *std.Build) !void {
2626
switch (comptime builtin.zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) {
@@ -67,7 +67,7 @@ pub fn build(b: *std.Build) !void {
6767
.optimize = mode,
6868
});
6969

70-
try common(b, &bench.root_module, options);
70+
try common(b, bench.root_module, options);
7171
if (mode == .ReleaseSafe) {
7272
// remove debug info
7373
// TODO: check if mandatory in release-safe
@@ -95,7 +95,7 @@ pub fn build(b: *std.Build) !void {
9595
.target = target,
9696
.optimize = mode,
9797
});
98-
try common(b, &shell.root_module, options);
98+
try common(b, shell.root_module, options);
9999
try pkgs.add_shell(shell);
100100
if (mode == .ReleaseSafe) {
101101
// remove debug info
@@ -121,11 +121,11 @@ pub fn build(b: *std.Build) !void {
121121
// compile
122122
const tests = b.addTest(.{
123123
.root_source_file = b.path("src/run_tests.zig"),
124+
.test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple },
124125
.target = target,
125126
.optimize = mode,
126127
});
127-
try common(b, &tests.root_module, options);
128-
tests.test_runner = b.path("src/test_runner.zig");
128+
try common(b, tests.root_module, options);
129129
const run_tests = b.addRunArtifact(tests);
130130

131131
// step

src/bench.zig

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,18 @@ pub const Allocator = struct {
9999
.alloc = alloc,
100100
.resize = resize,
101101
.free = free,
102+
.remap = remap,
102103
} };
103104
}
104105

105106
fn alloc(
106107
ctx: *anyopaque,
107108
len: usize,
108-
log2_ptr_align: u8,
109+
alignment: std.mem.Alignment,
109110
return_address: usize,
110111
) ?[*]u8 {
111112
const self: *Allocator = @ptrCast(@alignCast(ctx));
112-
const result = self.parent_allocator.rawAlloc(len, log2_ptr_align, return_address);
113+
const result = self.parent_allocator.rawAlloc(len, alignment, return_address);
113114
self.alloc_nb += 1;
114115
self.size += len;
115116
return result;
@@ -118,26 +119,39 @@ pub const Allocator = struct {
118119
fn resize(
119120
ctx: *anyopaque,
120121
old_mem: []u8,
121-
log2_old_align: u8,
122+
alignment: std.mem.Alignment,
122123
new_len: usize,
123124
ra: usize,
124125
) bool {
125126
const self: *Allocator = @ptrCast(@alignCast(ctx));
126-
const result = self.parent_allocator.rawResize(old_mem, log2_old_align, new_len, ra);
127+
const result = self.parent_allocator.rawResize(old_mem, alignment, new_len, ra);
127128
self.realloc_nb += 1; // TODO: only if result is not null?
128129
return result;
129130
}
130131

131132
fn free(
132133
ctx: *anyopaque,
133134
old_mem: []u8,
134-
log2_old_align: u8,
135+
alignment: std.mem.Alignment,
135136
ra: usize,
136137
) void {
137138
const self: *Allocator = @ptrCast(@alignCast(ctx));
138-
self.parent_allocator.rawFree(old_mem, log2_old_align, ra);
139+
self.parent_allocator.rawFree(old_mem, alignment, ra);
139140
self.free_nb += 1;
140141
}
142+
143+
fn remap(
144+
ctx: *anyopaque,
145+
memory: []u8,
146+
alignment: std.mem.Alignment,
147+
new_len: usize,
148+
ret_addr: usize,
149+
) ?[*]u8 {
150+
const self: *Allocator = @ptrCast(@alignCast(ctx));
151+
const result = self.parent_allocator.rawRemap(memory, alignment, new_len, ret_addr);
152+
self.realloc_nb += 1; // TODO: only if result is not null?
153+
return result;
154+
}
141155
};
142156

143157
pub fn allocator(parent_allocator: std.mem.Allocator) Allocator {

src/engines/v8/callback.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub const Func = struct {
314314
pub fn call(self: Func, nat_args: anytype) anyerror!void {
315315
// ensure Native args and JS args are not both provided
316316
const info = @typeInfo(@TypeOf(nat_args));
317-
if (comptime info != .Null) {
317+
if (comptime info != .null) {
318318
// TODO: could be a compile error if we use generics for JS args
319319
std.debug.assert(self.js_args_pers.len == 0);
320320
}
@@ -330,16 +330,16 @@ pub const Func = struct {
330330
// retrieve arguments
331331
var args = try self.nat_ctx.alloc.alloc(v8.Value, self.js_args_pers.len);
332332
defer self.nat_ctx.alloc.free(args);
333-
if (comptime info == .Struct) {
333+
if (comptime info == .@"struct") {
334334

335335
// - Native arguments provided on function call
336-
std.debug.assert(info.Struct.is_tuple);
337-
args = try self.nat_ctx.alloc.alloc(v8.Value, info.Struct.fields.len);
336+
std.debug.assert(info.@"struct".is_tuple);
337+
args = try self.nat_ctx.alloc.alloc(v8.Value, info.@"struct".fields.len);
338338
comptime var i = 0;
339-
inline while (i < info.Struct.fields.len) {
339+
inline while (i < info.@"struct".fields.len) {
340340
comptime var ret: refl.Type = undefined;
341341
comptime {
342-
ret = try refl.Type.reflect(info.Struct.fields[i].type, null);
342+
ret = try refl.Type.reflect(info.@"struct".fields[i].type, null);
343343
try ret.lookup(gen.Types);
344344
}
345345
args[i] = try setNativeType(

src/engines/v8/generate.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ pub fn setNativeType(
618618
const info = @typeInfo(@TypeOf(res));
619619

620620
// Optional
621-
if (info == .Optional) {
621+
if (info == .optional) {
622622
if (res == null) {
623623
// if null just return JS null
624624
return isolate.initNull().toValue();
@@ -919,7 +919,7 @@ fn callFunc(
919919
const function = @field(T_refl.T, func.name);
920920
const res_T = comptime func.return_type.underErr() orelse func.return_type.T;
921921
var res: res_T = undefined;
922-
if (comptime @typeInfo(func.return_type.T) == .ErrorUnion) {
922+
if (comptime @typeInfo(func.return_type.T) == .error_union) {
923923
res = @call(.auto, function, args) catch |err| {
924924
// TODO: how to handle internal errors vs user errors
925925
const js_err = throwError(
@@ -1106,7 +1106,7 @@ fn staticAttrsKeys(
11061106
return;
11071107
}
11081108
const attrs_T = T_refl.static_attrs_T.?;
1109-
inline for (@typeInfo(attrs_T).Struct.fields, 0..) |field, i| {
1109+
inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |field, i| {
11101110
keys[i] = v8.String.initUtf8(isolate, field.name).toName();
11111111
}
11121112
}
@@ -1121,7 +1121,7 @@ fn staticAttrsValues(
11211121
}
11221122
const attrs_T = T_refl.static_attrs_T.?;
11231123
const attrs = comptime T_refl.staticAttrs(attrs_T);
1124-
inline for (@typeInfo(attrs_T).Struct.fields, 0..) |field, i| {
1124+
inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |field, i| {
11251125
const value = comptime @field(attrs, field.name);
11261126
values[i] = nativeToJS(@TypeOf(value), value, isolate) catch unreachable;
11271127
}
@@ -1137,7 +1137,7 @@ fn setStaticAttrs(
11371137
return;
11381138
}
11391139
const attrs_T = T_refl.static_attrs_T.?;
1140-
inline for (@typeInfo(attrs_T).Struct.fields, 0..) |_, i| {
1140+
inline for (@typeInfo(attrs_T).@"struct".fields, 0..) |_, i| {
11411141
template.set(keys[i], values[i], v8.PropertyAttribute.ReadOnly + v8.PropertyAttribute.DontDelete);
11421142
}
11431143
}
@@ -1198,7 +1198,7 @@ pub fn loadFunctionTemplate(
11981198
// static attributes keys and values
11991199
comptime var static_nb: usize = undefined;
12001200
if (T_refl.static_attrs_T) |attr_T| {
1201-
static_nb = @typeInfo(attr_T).Struct.fields.len;
1201+
static_nb = @typeInfo(attr_T).@"struct".fields.len;
12021202
} else {
12031203
static_nb = 0;
12041204
}

src/engines/v8/types_primitives.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn jsToNative(
9191
// JS Null or Undefined value
9292
if (js_val.isNull() or js_val.isUndefined()) {
9393
// if Native optional type return null
94-
if (comptime info == .Optional) {
94+
if (comptime info == .optional) {
9595
return null;
9696
}
9797
// Here we should normally return an error
@@ -104,8 +104,8 @@ pub fn jsToNative(
104104
}
105105

106106
// unwrap Optional
107-
if (info == .Optional) {
108-
return try jsToNative(alloc, info.Optional.child, js_val, isolate, ctx);
107+
if (info == .optional) {
108+
return try jsToNative(alloc, info.optional.child, js_val, isolate, ctx);
109109
}
110110

111111
// JS values
@@ -185,7 +185,7 @@ pub fn jsToObject(
185185
// JS Null or Undefined value
186186
if (js_val.isNull() or js_val.isUndefined()) {
187187
// if Native optional type return null
188-
if (comptime info == .Optional) {
188+
if (comptime info == .optional) {
189189
return null;
190190
}
191191
}
@@ -196,8 +196,8 @@ pub fn jsToObject(
196196
}
197197

198198
// unwrap Optional
199-
if (comptime info == .Optional) {
200-
return try jsToObject(alloc, nested_T, info.Optional.child, js_val, isolate, ctx);
199+
if (comptime info == .optional) {
200+
return try jsToObject(alloc, nested_T, info.optional.child, js_val, isolate, ctx);
201201
}
202202

203203
const js_obj = js_val.castTo(v8.Object);

src/engines/v8/v8.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub const JSObject = struct {
531531
var js_value: v8.Value = undefined;
532532
if (comptime refl.isBuiltinType(@TypeOf(value))) {
533533
js_value = try nativeToJS(@TypeOf(value), value, isolate);
534-
} else if (@typeInfo(@TypeOf(value)) == .Union) {
534+
} else if (@typeInfo(@TypeOf(value)) == .@"union") {
535535
// NOTE: inspired by std.meta.TagPayloadByName
536536
const activeTag = @tagName(std.meta.activeTag(value));
537537
inline for (std.meta.fields(@TypeOf(value))) |field| {

0 commit comments

Comments
 (0)