Skip to content

Commit d02ba77

Browse files
Merge pull request #984 from lightpanda-io/zig.0.15.1
Zig 0.15.1
2 parents 431db85 + c7c5af4 commit d02ba77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+540
-551
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.14.1'
8+
default: '0.15.1'
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.14.1
4+
ZIG_VERSION: 0.15.1
55

66
on:
77
pull_request:

Dockerfile

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

33
ARG MINISIG=0.12
4-
ARG ZIG=0.14.1
4+
ARG ZIG=0.15.1
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG V8=13.6.233.8
77
ARG ZIG_V8=v0.1.28

README.md

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

166166
### Prerequisites
167167

168-
Lightpanda is written with [Zig](https://ziglang.org/) `0.14.1`. You have to
168+
Lightpanda is written with [Zig](https://ziglang.org/) `0.15.1`. You have to
169169
install it with the right version in order to build the project.
170170

171171
Lightpanda also depends on

build.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Build = std.Build;
2323

2424
/// Do not rename this constant. It is scanned by some scripts to determine
2525
/// which zig version to install.
26-
const recommended_zig_version = "0.14.1";
26+
const recommended_zig_version = "0.15.1";
2727

2828
pub fn build(b: *Build) !void {
2929
switch (comptime builtin.zig_version.order(std.SemanticVersion.parse(recommended_zig_version) catch unreachable)) {
@@ -49,10 +49,15 @@ pub fn build(b: *Build) !void {
4949
const target = b.standardTargetOptions(.{});
5050
const optimize = b.standardOptimizeOption(.{});
5151

52+
// We're still using llvm because the new x86 backend seems to crash
53+
// with v8. This can be reproduced in zig-v8-fork.
54+
5255
const lightpanda_module = b.addModule("lightpanda", .{
5356
.root_source_file = b.path("src/main.zig"),
5457
.target = target,
5558
.optimize = optimize,
59+
.link_libc = true,
60+
.link_libcpp = true,
5661
});
5762
try addDependencies(b, lightpanda_module, opts);
5863

@@ -63,6 +68,7 @@ pub fn build(b: *Build) !void {
6368
// compile and install
6469
const exe = b.addExecutable(.{
6570
.name = "lightpanda",
71+
.use_llvm = true,
6672
.root_module = lightpanda_module,
6773
});
6874
b.installArtifact(exe);
@@ -85,6 +91,7 @@ pub fn build(b: *Build) !void {
8591
// compile
8692
const tests = b.addTest(.{
8793
.root_module = lightpanda_module,
94+
.use_llvm = true,
8895
.test_runner = .{ .path = b.path("src/test_runner.zig"), .mode = .simple },
8996
});
9097

@@ -111,6 +118,7 @@ pub fn build(b: *Build) !void {
111118
// compile and install
112119
const wpt = b.addExecutable(.{
113120
.name = "lightpanda-wpt",
121+
.use_llvm = true,
114122
.root_module = wpt_module,
115123
});
116124

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
.fingerprint = 0xda130f3af836cea0,
66
.dependencies = .{
77
.v8 = .{
8-
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/cf412d5b3d9d608582571d821e0d552337ef690d.tar.gz",
9-
.hash = "v8-0.0.0-xddH69zDAwA4fp1dBo_jEDjS5bhXycPwRlZHp6_X890t",
8+
.url = "https://github.com/lightpanda-io/zig-v8-fork/archive/e62726800663d0397d8766f7185040d8b8b69402.tar.gz",
9+
.hash = "v8-0.0.0-xddH69zDAwD5i0hGhAsv3SPeihlj5fXGpJyO15KqBWOn",
1010
},
11-
//.v8 = .{ .path = "../zig-v8-fork" },
11+
//.v8 = .{ .path = "../zig-v8-fork" }
1212
},
1313
}

src/browser/Scheduler.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,18 @@ test "Scheduler" {
129129
try testing.expectDelta(3, try s.runHighPriority(), 1);
130130
try testing.expectEqual(0, task.calls.items.len);
131131

132-
std.time.sleep(std.time.ns_per_ms * 5);
132+
std.Thread.sleep(std.time.ns_per_ms * 5);
133133
try testing.expectEqual(null, s.runHighPriority());
134134
try testing.expectEqualSlices(u32, &.{1}, task.calls.items);
135135

136136
try s.add(&task, TestTask.run2, 3, .{});
137137
try s.add(&task, TestTask.run1, 2, .{});
138138

139-
std.time.sleep(std.time.ns_per_ms * 5);
139+
std.Thread.sleep(std.time.ns_per_ms * 5);
140140
try testing.expectDelta(null, try s.runHighPriority(), 1);
141141
try testing.expectEqualSlices(u32, &.{ 1, 1, 2 }, task.calls.items);
142142

143-
std.time.sleep(std.time.ns_per_ms * 5);
143+
std.Thread.sleep(std.time.ns_per_ms * 5);
144144
// wont' run secondary
145145
try testing.expectEqual(null, try s.runHighPriority());
146146
try testing.expectEqualSlices(u32, &.{ 1, 1, 2 }, task.calls.items);
@@ -155,13 +155,13 @@ const TestTask = struct {
155155
calls: std.ArrayListUnmanaged(u32) = .{},
156156

157157
fn run1(ctx: *anyopaque) ?u32 {
158-
var self: *TestTask = @alignCast(@ptrCast(ctx));
158+
var self: *TestTask = @ptrCast(@alignCast(ctx));
159159
self.calls.append(self.allocator, 1) catch unreachable;
160160
return null;
161161
}
162162

163163
fn run2(ctx: *anyopaque) ?u32 {
164-
var self: *TestTask = @alignCast(@ptrCast(ctx));
164+
var self: *TestTask = @ptrCast(@alignCast(ctx));
165165
self.calls.append(self.allocator, 2) catch unreachable;
166166
return 2;
167167
}

src/browser/ScriptManager.zig

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ allocator: Allocator,
6262
buffer_pool: BufferPool,
6363
script_pool: std.heap.MemoryPool(PendingScript),
6464

65-
const OrderList = std.DoublyLinkedList(*PendingScript);
65+
const OrderList = std.DoublyLinkedList;
6666

6767
pub fn init(browser: *Browser, page: *Page) ScriptManager {
6868
// page isn't fully initialized, we can setup our reference, but that's it.
@@ -96,7 +96,7 @@ pub fn reset(self: *ScriptManager) void {
9696

9797
fn clearList(_: *const ScriptManager, list: *OrderList) void {
9898
while (list.first) |node| {
99-
const pending_script = node.data;
99+
const pending_script: *PendingScript = @fieldParentPtr("node", node);
100100
// this removes it from the list
101101
pending_script.deinit();
102102
}
@@ -179,7 +179,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
179179
.script = script,
180180
.complete = false,
181181
.manager = self,
182-
.node = .{ .data = pending_script },
182+
.node = .{},
183183
};
184184

185185
if (source == .@"inline") {
@@ -193,7 +193,6 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
193193
log.debug(.http, "script queue", .{ .url = remote_url.? });
194194
}
195195

196-
pending_script.node = .{ .data = pending_script };
197196
self.getList(&pending_script.script).append(&pending_script.node);
198197

199198
errdefer pending_script.deinit();
@@ -323,7 +322,7 @@ fn evaluate(self: *ScriptManager) void {
323322
defer self.is_evaluating = false;
324323

325324
while (self.scripts.first) |n| {
326-
var pending_script = n.data;
325+
var pending_script: *PendingScript = @fieldParentPtr("node", n);
327326
if (pending_script.complete == false) {
328327
return;
329328
}
@@ -343,7 +342,7 @@ fn evaluate(self: *ScriptManager) void {
343342
}
344343

345344
while (self.deferreds.first) |n| {
346-
var pending_script = n.data;
345+
var pending_script: *PendingScript = @fieldParentPtr("node", n);
347346
if (pending_script.complete == false) {
348347
return;
349348
}
@@ -395,15 +394,15 @@ fn getList(self: *ScriptManager, script: *const Script) *OrderList {
395394
}
396395

397396
fn startCallback(transfer: *Http.Transfer) !void {
398-
const script: *PendingScript = @alignCast(@ptrCast(transfer.ctx));
397+
const script: *PendingScript = @ptrCast(@alignCast(transfer.ctx));
399398
script.startCallback(transfer) catch |err| {
400399
log.err(.http, "SM.startCallback", .{ .err = err, .transfer = transfer });
401400
return err;
402401
};
403402
}
404403

405404
fn headerCallback(transfer: *Http.Transfer) !void {
406-
const script: *PendingScript = @alignCast(@ptrCast(transfer.ctx));
405+
const script: *PendingScript = @ptrCast(@alignCast(transfer.ctx));
407406
script.headerCallback(transfer) catch |err| {
408407
log.err(.http, "SM.headerCallback", .{
409408
.err = err,
@@ -415,20 +414,20 @@ fn headerCallback(transfer: *Http.Transfer) !void {
415414
}
416415

417416
fn dataCallback(transfer: *Http.Transfer, data: []const u8) !void {
418-
const script: *PendingScript = @alignCast(@ptrCast(transfer.ctx));
417+
const script: *PendingScript = @ptrCast(@alignCast(transfer.ctx));
419418
script.dataCallback(transfer, data) catch |err| {
420419
log.err(.http, "SM.dataCallback", .{ .err = err, .transfer = transfer, .len = data.len });
421420
return err;
422421
};
423422
}
424423

425424
fn doneCallback(ctx: *anyopaque) !void {
426-
const script: *PendingScript = @alignCast(@ptrCast(ctx));
425+
const script: *PendingScript = @ptrCast(@alignCast(ctx));
427426
script.doneCallback();
428427
}
429428

430429
fn errorCallback(ctx: *anyopaque, err: anyerror) void {
431-
const script: *PendingScript = @alignCast(@ptrCast(ctx));
430+
const script: *PendingScript = @ptrCast(@alignCast(ctx));
432431
script.errorCallback(err);
433432
}
434433

@@ -682,17 +681,22 @@ const BufferPool = struct {
682681
available: List = .{},
683682
allocator: Allocator,
684683
max_concurrent_transfers: u8,
685-
node_pool: std.heap.MemoryPool(List.Node),
684+
mem_pool: std.heap.MemoryPool(Container),
686685

687-
const List = std.DoublyLinkedList(std.ArrayListUnmanaged(u8));
686+
const List = std.DoublyLinkedList;
687+
688+
const Container = struct {
689+
node: List.Node,
690+
buf: std.ArrayListUnmanaged(u8),
691+
};
688692

689693
fn init(allocator: Allocator, max_concurrent_transfers: u8) BufferPool {
690694
return .{
691695
.available = .{},
692696
.count = 0,
693697
.allocator = allocator,
694698
.max_concurrent_transfers = max_concurrent_transfers,
695-
.node_pool = std.heap.MemoryPool(List.Node).init(allocator),
699+
.mem_pool = std.heap.MemoryPool(Container).init(allocator),
696700
};
697701
}
698702

@@ -701,21 +705,23 @@ const BufferPool = struct {
701705

702706
var node = self.available.first;
703707
while (node) |n| {
704-
n.data.deinit(allocator);
708+
const container: *Container = @fieldParentPtr("node", n);
709+
container.buf.deinit(allocator);
705710
node = n.next;
706711
}
707-
self.node_pool.deinit();
712+
self.mem_pool.deinit();
708713
}
709714

710-
fn get(self: *BufferPool) ArrayListUnmanaged(u8) {
715+
fn get(self: *BufferPool) std.ArrayListUnmanaged(u8) {
711716
const node = self.available.popFirst() orelse {
712717
// return a new buffer
713718
return .{};
714719
};
715720

716721
self.count -= 1;
717-
defer self.node_pool.destroy(node);
718-
return node.data;
722+
const container: *Container = @fieldParentPtr("node", node);
723+
defer self.mem_pool.destroy(container);
724+
return container.buf;
719725
}
720726

721727
fn release(self: *BufferPool, buffer: ArrayListUnmanaged(u8)) void {
@@ -727,16 +733,16 @@ const BufferPool = struct {
727733
return;
728734
}
729735

730-
const node = self.node_pool.create() catch |err| {
736+
const container = self.mem_pool.create() catch |err| {
731737
b.deinit(self.allocator);
732738
log.err(.http, "SM BufferPool release", .{ .err = err });
733739
return;
734740
};
735741

736742
b.clearRetainingCapacity();
737-
node.* = .{ .data = b };
743+
container.* = .{ .buf = b, .node = .{} };
738744
self.count += 1;
739-
self.available.append(node);
745+
self.available.append(&container.node);
740746
}
741747
};
742748

@@ -769,7 +775,7 @@ const Blocking = struct {
769775
return error.InvalidStatusCode;
770776
}
771777

772-
var self: *Blocking = @alignCast(@ptrCast(transfer.ctx));
778+
var self: *Blocking = @ptrCast(@alignCast(transfer.ctx));
773779
self.buffer = self.buffer_pool.get();
774780
}
775781

@@ -780,7 +786,7 @@ const Blocking = struct {
780786
// .blocking = true,
781787
// });
782788

783-
var self: *Blocking = @alignCast(@ptrCast(transfer.ctx));
789+
var self: *Blocking = @ptrCast(@alignCast(transfer.ctx));
784790
self.buffer.appendSlice(self.allocator, data) catch |err| {
785791
log.err(.http, "SM.dataCallback", .{
786792
.err = err,
@@ -793,15 +799,15 @@ const Blocking = struct {
793799
}
794800

795801
fn doneCallback(ctx: *anyopaque) !void {
796-
var self: *Blocking = @alignCast(@ptrCast(ctx));
802+
var self: *Blocking = @ptrCast(@alignCast(ctx));
797803
self.state = .{ .done = .{
798804
.buffer = self.buffer,
799805
.buffer_pool = self.buffer_pool,
800806
} };
801807
}
802808

803809
fn errorCallback(ctx: *anyopaque, err: anyerror) void {
804-
var self: *Blocking = @alignCast(@ptrCast(ctx));
810+
var self: *Blocking = @ptrCast(@alignCast(ctx));
805811
self.state = .{ .err = err };
806812
self.buffer_pool.release(self.buffer);
807813
}

src/browser/dom/character_data.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub const CharacterData = struct {
102102
// netsurf's CharacterData (text, comment) doesn't implement the
103103
// dom_node_get_attributes and thus will crash if we try to call nodeIsEqualNode.
104104
pub fn _isEqualNode(self: *parser.CharacterData, other_node: *parser.Node) !bool {
105-
if (try parser.nodeType(@alignCast(@ptrCast(self))) != try parser.nodeType(other_node)) {
105+
if (try parser.nodeType(@ptrCast(@alignCast(self))) != try parser.nodeType(other_node)) {
106106
return false;
107107
}
108108

src/browser/dom/document.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ pub const Document = struct {
258258
}
259259

260260
pub fn getActiveElement(self: *parser.Document, page: *Page) !?*parser.Element {
261-
if (page.getNodeState(@alignCast(@ptrCast(self)))) |state| {
261+
if (page.getNodeState(@ptrCast(@alignCast(self)))) |state| {
262262
if (state.active_element) |ae| {
263263
return ae;
264264
}
265265
}
266266

267267
if (try parser.documentHTMLBody(page.window.document)) |body| {
268-
return @alignCast(@ptrCast(body));
268+
return @ptrCast(@alignCast(body));
269269
}
270270

271271
return try parser.documentGetDocumentElement(self);
@@ -281,7 +281,7 @@ pub const Document = struct {
281281
// we could look for the "disabled" attribute, but that's only meaningful
282282
// on certain types, and libdom's vtable doesn't seem to expose this.
283283
pub fn setFocus(self: *parser.Document, e: *parser.ElementHTML, page: *Page) !void {
284-
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
284+
const state = try page.getOrCreateNodeState(@ptrCast(@alignCast(self)));
285285
state.active_element = @ptrCast(e);
286286
}
287287

@@ -295,7 +295,7 @@ pub const Document = struct {
295295
}
296296

297297
pub fn get_adoptedStyleSheets(self: *parser.Document, page: *Page) !Env.JsObject {
298-
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
298+
const state = try page.getOrCreateNodeState(@ptrCast(@alignCast(self)));
299299
if (state.adopted_style_sheets) |obj| {
300300
return obj;
301301
}
@@ -306,7 +306,7 @@ pub const Document = struct {
306306
}
307307

308308
pub fn set_adoptedStyleSheets(self: *parser.Document, sheets: Env.JsObject, page: *Page) !void {
309-
const state = try page.getOrCreateNodeState(@alignCast(@ptrCast(self)));
309+
const state = try page.getOrCreateNodeState(@ptrCast(@alignCast(self)));
310310
state.adopted_style_sheets = try sheets.persist();
311311
}
312312
};

0 commit comments

Comments
 (0)