Skip to content

Commit 24aa8e2

Browse files
Merge pull request #480 from lightpanda-io/zig-0.14
Zig 0.14
2 parents 17d3d62 + 0a0c155 commit 24aa8e2

File tree

28 files changed

+91
-210
lines changed

28 files changed

+91
-210
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[submodule "vendor/zig-js-runtime"]
22
path = vendor/zig-js-runtime
33
url = https://github.com/lightpanda-io/zig-js-runtime.git/
4+
branch = zig-0.14
45
[submodule "vendor/netsurf/libwapcaplet"]
56
path = vendor/netsurf/libwapcaplet
67
url = https://github.com/lightpanda-io/libwapcaplet.git/
@@ -28,3 +29,4 @@
2829
[submodule "vendor/zig-async-io"]
2930
path = vendor/zig-async-io
3031
url = https://github.com/lightpanda-io/zig-async-io.git/
32+
branch = zig-0.14

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:24.04
22

33
ARG MINISIG=0.12
4-
ARG ZIG=0.13.0
4+
ARG ZIG=0.14.0
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG ARCH=x86_64
77
ARG V8=11.1.134

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can also follow the progress of our Javascript support in our dedicated [zig
140140

141141
### Prerequisites
142142

143-
Lightpanda is written with [Zig](https://ziglang.org/) `0.13.0`. You have to
143+
Lightpanda is written with [Zig](https://ziglang.org/) `0.14.0`. You have to
144144
install it with the right version in order to build the project.
145145

146146
Lightpanda also depends on

build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn build(b: *std.Build) !void {
108108
// compile
109109
const tests = b.addTest(.{
110110
.root_source_file = b.path("src/main_tests.zig"),
111-
.test_runner = b.path("src/main_tests.zig"),
111+
.test_runner = .{ .path = b.path("src/main_tests.zig"), .mode = .simple },
112112
.target = target,
113113
.optimize = mode,
114114
});
@@ -134,7 +134,7 @@ pub fn build(b: *std.Build) !void {
134134
// compile
135135
const unit_tests = b.addTest(.{
136136
.root_source_file = b.path("src/unit_tests.zig"),
137-
.test_runner = b.path("src/unit_tests.zig"),
137+
.test_runner = .{ .path = b.path("src/unit_tests.zig"), .mode = .simple },
138138
.target = target,
139139
.optimize = mode,
140140
});
@@ -195,7 +195,7 @@ fn common(
195195
step.root_module.addImport("asyncio", asyncio);
196196

197197
const tlsmod = b.addModule("tls", .{
198-
.root_source_file = b.path("vendor/tls.zig/src/main.zig"),
198+
.root_source_file = b.path("vendor/tls.zig/src/root.zig"),
199199
});
200200
step.root_module.addImport("tls", tlsmod);
201201
}

src/browser/browser.zig

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ pub const Session = struct {
156156

157157
const ContextT = @TypeOf(ctx);
158158
const InspectorContainer = switch (@typeInfo(ContextT)) {
159-
.Struct => ContextT,
160-
.Pointer => |ptr| ptr.child,
161-
.Void => NoopInspector,
159+
.@"struct" => ContextT,
160+
.pointer => |ptr| ptr.child,
161+
.void => NoopInspector,
162162
else => @compileError("invalid context type"),
163163
};
164164

165165
// const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
166166
self.inspector = try jsruntime.Inspector.init(
167167
arena,
168-
self.env, // TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
168+
&self.env,
169169
if (@TypeOf(ctx) == void) @constCast(@ptrCast(&{})) else ctx,
170170
InspectorContainer.onInspectorResponse,
171171
InspectorContainer.onInspectorEvent,
@@ -231,7 +231,7 @@ pub const Session = struct {
231231

232232
// load polyfills
233233
// TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
234-
try polyfill.load(self.arena.allocator(), self.env);
234+
try polyfill.load(self.arena.allocator(), &self.env);
235235

236236
// inspector
237237
self.contextCreated(page, aux_data);
@@ -264,7 +264,7 @@ pub const Session = struct {
264264

265265
fn contextCreated(self: *Session, page: *Page, aux_data: ?[]const u8) void {
266266
log.debug("inspector context created", .{});
267-
self.inspector.contextCreated(self.env, "", page.origin orelse "://", aux_data);
267+
self.inspector.contextCreated(&self.env, "", page.origin orelse "://", aux_data);
268268
}
269269
};
270270

@@ -316,15 +316,15 @@ pub const Page = struct {
316316
pub fn wait(self: *Page) !void {
317317
// try catch
318318
var try_catch: jsruntime.TryCatch = undefined;
319-
try_catch.init(self.session.env);
319+
try_catch.init(&self.session.env);
320320
defer try_catch.deinit();
321321

322322
self.session.env.wait() catch |err| {
323323
// the js env could not be started if the document wasn't an HTML.
324324
if (err == error.EnvNotStarted) return;
325325

326326
const arena = self.arena;
327-
if (try try_catch.err(arena, self.session.env)) |msg| {
327+
if (try try_catch.err(arena, &self.session.env)) |msg| {
328328
defer arena.free(msg);
329329
log.info("wait error: {s}", .{msg});
330330
return;
@@ -591,9 +591,7 @@ pub const Page = struct {
591591
// TODO handle charset attribute
592592
const opt_text = try parser.nodeTextContent(parser.elementToNode(s.element));
593593
if (opt_text) |text| {
594-
// TODO: change to &self.session.env when
595-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
596-
try s.eval(self.arena, self.session.env, text);
594+
try s.eval(self.arena, &self.session.env, text);
597595
return;
598596
}
599597

@@ -656,11 +654,8 @@ pub const Page = struct {
656654
// received.
657655
fn fetchScript(self: *const Page, s: *const Script) !void {
658656
const arena = self.arena;
659-
660657
const body = try self.fetchData(arena, s.src, null);
661-
// TODO: change to &self.session.env when
662-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
663-
try s.eval(arena, self.session.env, body);
658+
try s.eval(arena, &self.session.env, body);
664659
}
665660

666661
const Script = struct {
@@ -683,9 +678,8 @@ pub const Page = struct {
683678

684679
return .{
685680
.element = e,
686-
.kind = kind(try parser.elementGetAttribute(e, "type")),
681+
.kind = parseKind(try parser.elementGetAttribute(e, "type")),
687682
.is_async = try parser.elementGetAttribute(e, "async") != null,
688-
689683
.src = try parser.elementGetAttribute(e, "src") orelse "inline",
690684
};
691685
}
@@ -695,15 +689,15 @@ pub const Page = struct {
695689
// > type indicates that the script is a "classic script", containing
696690
// > JavaScript code.
697691
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
698-
fn kind(stype: ?[]const u8) Kind {
692+
fn parseKind(stype: ?[]const u8) Kind {
699693
if (stype == null or stype.?.len == 0) return .javascript;
700694
if (std.mem.eql(u8, stype.?, "application/javascript")) return .javascript;
701695
if (std.mem.eql(u8, stype.?, "module")) return .module;
702696

703697
return .unknown;
704698
}
705699

706-
fn eval(self: Script, arena: Allocator, env: Env, body: []const u8) !void {
700+
fn eval(self: Script, arena: Allocator, env: *const Env, body: []const u8) !void {
707701
var try_catch: jsruntime.TryCatch = undefined;
708702
try_catch.init(env);
709703
defer try_catch.deinit();

src/browser/mime.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub const Mime = struct {
245245
const bit_len = @bitSizeOf(@TypeOf(target.*)) - 8;
246246
const byte_len = bit_len / 8;
247247

248-
const T = @Type(.{ .Int = .{
248+
const T = @Type(.{ .int = .{
249249
.bits = bit_len,
250250
.signedness = .unsigned,
251251
} });

src/cdp/cdp.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
454454
pub fn sendResult(self: *Self, result: anytype, opts: SendResultOpts) !void {
455455
return self.sender.sendJSON(.{
456456
.id = self.input.id,
457-
.result = if (comptime @typeInfo(@TypeOf(result)) == .Null) struct {}{} else result,
457+
.result = if (comptime @typeInfo(@TypeOf(result)) == .null) struct {}{} else result,
458458
.sessionId = if (opts.include_session_id) self.input.session_id else null,
459459
});
460460
}
@@ -466,7 +466,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
466466
// Events ALWAYS go to the client. self.sender should not be used
467467
return self.cdp.sendJSON(.{
468468
.method = method,
469-
.params = if (comptime @typeInfo(@TypeOf(p)) == .Null) struct {}{} else p,
469+
.params = if (comptime @typeInfo(@TypeOf(p)) == .null) struct {}{} else p,
470470
.sessionId = opts.session_id,
471471
});
472472
}

src/cdp/testing.zig

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const TestContext = struct {
174174

175175
pub fn processMessage(self: *TestContext, msg: anytype) !void {
176176
var json_message: []const u8 = undefined;
177-
if (@typeInfo(@TypeOf(msg)) != .Pointer) {
178-
json_message = try json.stringifyAlloc(self.arena.allocator(), msg, .{});
177+
if (@typeInfo(@TypeOf(msg)) != .pointer) {
178+
json_message = try std.json.stringifyAlloc(self.arena.allocator(), msg, .{});
179179
} else {
180180
// assume this is a string we want to send as-is, if it isn't, we'll
181181
// get a compile error, so no big deal.
@@ -196,7 +196,7 @@ const TestContext = struct {
196196
pub fn expectSentResult(self: *TestContext, expected: anytype, opts: ExpectResultOpts) !void {
197197
const expected_result = .{
198198
.id = opts.id,
199-
.result = if (comptime @typeInfo(@TypeOf(expected)) == .Null) struct {}{} else expected,
199+
.result = if (comptime @typeInfo(@TypeOf(expected)) == .null) struct {}{} else expected,
200200
.sessionId = opts.session_id,
201201
};
202202

@@ -210,7 +210,7 @@ const TestContext = struct {
210210
pub fn expectSentEvent(self: *TestContext, method: []const u8, params: anytype, opts: ExpectEventOpts) !void {
211211
const expected_event = .{
212212
.method = method,
213-
.params = if (comptime @typeInfo(@TypeOf(params)) == .Null) struct {}{} else params,
213+
.params = if (comptime @typeInfo(@TypeOf(params)) == .null) struct {}{} else params,
214214
.sessionId = opts.session_id,
215215
};
216216

@@ -323,96 +323,3 @@ fn compareJsonValues(a: std.json.Value, b: std.json.Value) bool {
323323
},
324324
}
325325
}
326-
327-
// fn compareAnyToJsonValue(expected: anytype, actual: json.Value) bool {
328-
// switch (@typeInfo(@TypeOf(expected))) {
329-
// .Optional => {
330-
// if (expected) |e| {
331-
// return compareAnyToJsonValue(e, actual);
332-
// }
333-
// return actual == .null;
334-
// },
335-
// .Int, .ComptimeInt => {
336-
// if (actual != .integer) {
337-
// return false;
338-
// }
339-
// return expected == actual.integer;
340-
// },
341-
// .Float, .ComptimeFloat => {
342-
// if (actual != .float) {
343-
// return false;
344-
// }
345-
// return expected == actual.float;
346-
// },
347-
// .Bool => {
348-
// if (actual != .bool) {
349-
// return false;
350-
// }
351-
// return expected == actual.bool;
352-
// },
353-
// .Pointer => |ptr| switch (ptr.size) {
354-
// .One => switch (@typeInfo(ptr.child)) {
355-
// .Struct => return compareAnyToJsonValue(expected.*, actual),
356-
// .Array => |arr| if (arr.child == u8) {
357-
// if (actual != .string) {
358-
// return false;
359-
// }
360-
// return std.mem.eql(u8, expected, actual.string);
361-
// },
362-
// else => {},
363-
// },
364-
// .Slice => switch (ptr.child) {
365-
// u8 => {
366-
// if (actual != .string) {
367-
// return false;
368-
// }
369-
// return std.mem.eql(u8, expected, actual.string);
370-
// },
371-
// else => {},
372-
// },
373-
// else => {},
374-
// },
375-
// .Struct => |s| {
376-
// if (s.is_tuple) {
377-
// // how an array might look in an anytype
378-
// if (actual != .array) {
379-
// return false;
380-
// }
381-
// if (s.fields.len != actual.array.items.len) {
382-
// return false;
383-
// }
384-
385-
// inline for (s.fields, 0..) |f, i| {
386-
// const e = @field(expected, f.name);
387-
// if (compareAnyToJsonValue(e, actual.array.items[i]) == false) {
388-
// return false;
389-
// }
390-
// }
391-
// return true;
392-
// }
393-
394-
// if (s.fields.len == 0) {
395-
// return (actual == .array and actual.array.items.len == 0);
396-
// }
397-
398-
// if (actual != .object) {
399-
// return false;
400-
// }
401-
// inline for (s.fields) |f| {
402-
// const e = @field(expected, f.name);
403-
// if (actual.object.get(f.name)) |a| {
404-
// if (compareAnyToJsonValue(e, a) == false) {
405-
// return false;
406-
// }
407-
// } else if (@typeInfo(f.type) != .Optional or e != null) {
408-
// // We don't JSON serialize nulls. So if we're expecting
409-
// // a null, that should show up as a missing field.
410-
// return false;
411-
// }
412-
// }
413-
// return true;
414-
// },
415-
// else => {},
416-
// }
417-
// @compileError("Can't compare " ++ @typeName(@TypeOf(expected)));
418-
// }

0 commit comments

Comments
 (0)