Skip to content

Commit 18fb7c6

Browse files
committed
Zig 0.14 compatibility
1 parent 671dbcf commit 18fb7c6

File tree

24 files changed

+66
-181
lines changed

24 files changed

+66
-181
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
@@ -137,7 +137,7 @@ You can also follow the progress of our Javascript support in our dedicated [zig
137137

138138
### Prerequisites
139139

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

143143
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ pub const Session = struct {
151151

152152
const ContextT = @TypeOf(ctx);
153153
const InspectorContainer = switch (@typeInfo(ContextT)) {
154-
.Struct => ContextT,
155-
.Pointer => |ptr| ptr.child,
156-
.Void => NoopInspector,
154+
.@"struct" => ContextT,
155+
.pointer => |ptr| ptr.child,
156+
.void => NoopInspector,
157157
else => @compileError("invalid context type"),
158158
};
159159

@@ -673,9 +673,8 @@ pub const Page = struct {
673673

674674
return .{
675675
.element = e,
676-
.kind = kind(try parser.elementGetAttribute(e, "type")),
676+
.kind = parseKind(try parser.elementGetAttribute(e, "type")),
677677
.is_async = try parser.elementGetAttribute(e, "async") != null,
678-
679678
.src = try parser.elementGetAttribute(e, "src") orelse "inline",
680679
};
681680
}
@@ -685,7 +684,7 @@ pub const Page = struct {
685684
// > type indicates that the script is a "classic script", containing
686685
// > JavaScript code.
687686
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
688-
fn kind(stype: ?[]const u8) Kind {
687+
fn parseKind(stype: ?[]const u8) Kind {
689688
if (stype == null or stype.?.len == 0) return .javascript;
690689
if (std.mem.eql(u8, stype.?, "application/javascript")) return .javascript;
691690
if (std.mem.eql(u8, stype.?, "module")) return .module;

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
@@ -457,7 +457,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
457457
pub fn sendResult(self: *Self, result: anytype, opts: SendResultOpts) !void {
458458
return self.sender.sendJSON(.{
459459
.id = self.input.id,
460-
.result = if (comptime @typeInfo(@TypeOf(result)) == .Null) struct {}{} else result,
460+
.result = if (comptime @typeInfo(@TypeOf(result)) == .null) struct {}{} else result,
461461
.sessionId = if (opts.include_session_id) self.input.session_id else null,
462462
});
463463
}
@@ -469,7 +469,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
469469
// Events ALWAYS go to the client. self.sender should not be used
470470
return self.cdp.sendJSON(.{
471471
.method = method,
472-
.params = if (comptime @typeInfo(@TypeOf(p)) == .Null) struct {}{} else p,
472+
.params = if (comptime @typeInfo(@TypeOf(p)) == .null) struct {}{} else p,
473473
.sessionId = opts.session_id,
474474
});
475475
}

src/cdp/testing.zig

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

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

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

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

0 commit comments

Comments
 (0)