From 0e3806ab98f65b6cbcc7e57d7551dcfd44821100 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 4 Jun 2025 21:33:19 +0200 Subject: [PATCH 01/13] zig: port log.MsgStore to 0.15.0-dev.703+597dd328e --- src/log.zig | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/log.zig b/src/log.zig index 71d3521..4c4e038 100644 --- a/src/log.zig +++ b/src/log.zig @@ -10,9 +10,14 @@ receiver: Receiver, subscriber: ?tp.pid, heap: [32 + 1024]u8, fba: std.heap.FixedBufferAllocator, -msg_store: MsgStoreT, +msg_store: MsgStore, + +const MsgStore = std.DoublyLinkedList; +const MsgStoreEntry = struct { + data: []u8, + node: MsgStore.Node, +}; -const MsgStoreT = std.DoublyLinkedList([]u8); const Receiver = tp.Receiver(*Self); const StartArgs = struct { @@ -38,7 +43,7 @@ fn init(args: StartArgs) !*Self { .subscriber = null, .heap = undefined, .fba = std.heap.FixedBufferAllocator.init(&p.heap), - .msg_store = MsgStoreT{}, + .msg_store = MsgStore{}, }; return p; } @@ -55,17 +60,18 @@ fn log(msg: []const u8) void { fn store(self: *Self, m: tp.message) void { const allocator: std.mem.Allocator = self.fba.allocator(); const buf: []u8 = allocator.alloc(u8, m.len()) catch return; - var node: *MsgStoreT.Node = allocator.create(MsgStoreT.Node) catch return; - node.data = buf; + var msg: *MsgStoreEntry = allocator.create(MsgStoreEntry) catch return; + msg.data = buf; @memcpy(buf, m.buf); - self.msg_store.append(node); + self.msg_store.append(&msg.node); } fn store_send(self: *Self) void { var node = self.msg_store.first; if (self.subscriber) |sub| { while (node) |node_| { - sub.send_raw(tp.message{ .buf = node_.data }) catch return; + const msg: *MsgStoreEntry = @fieldParentPtr("node", node_); + sub.send_raw(tp.message{ .buf = msg.data }) catch return; node = node_.next; } } @@ -73,7 +79,7 @@ fn store_send(self: *Self) void { } fn store_reset(self: *Self) void { - self.msg_store = MsgStoreT{}; + self.msg_store = MsgStore{}; self.fba.reset(); } From 6fb364d64b087a0df6d6038efe0bd1c4ad3a0e0e Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 4 Jun 2025 22:37:21 +0200 Subject: [PATCH 02/13] zig: update to zig-0.15.0-dev.703+597dd328e --- build.zig.version | 2 +- build.zig.zon | 4 ++-- src/buffer/Buffer.zig | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.zig.version b/build.zig.version index 930e300..3cfe6f2 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.14.1 +0.15.0-dev.703+597dd328e diff --git a/build.zig.zon b/build.zig.zon index feb6ad0..e66f66f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -27,8 +27,8 @@ .hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX", }, .vaxis = .{ - .url = "https://github.com/neurocyte/libvaxis/archive/6137cb4c44a7350996f0946a069739e5075d1f23.tar.gz", - .hash = "vaxis-0.1.0-BWNV_HwOCQCw5wTV63hQGSc1QJzsNcytH6sGf1GBc0hP", + .url = "https://github.com/neurocyte/libvaxis/archive/64a29f4f91292bc79dc9afb9a254cbdfb35e29a6.tar.gz", + .hash = "vaxis-0.1.0-BWNV_KEOCQCzedUR1prWhPUcgsRmw8f-r5JBc3s4DLJf", }, .zeit = .{ .url = "https://github.com/rockorager/zeit/archive/8fd203f85f597f16e0a525c1f1ca1e0bffded809.tar.gz", diff --git a/src/buffer/Buffer.zig b/src/buffer/Buffer.zig index c90bf76..b86af65 100644 --- a/src/buffer/Buffer.zig +++ b/src/buffer/Buffer.zig @@ -1222,6 +1222,7 @@ pub const LoadFromFileError = error{ LockViolation, ProcessNotFound, Canceled, + PermissionDenied, }; pub fn load_from_file( @@ -1327,6 +1328,8 @@ pub const StoreToFileError = error{ SystemResources, Unexpected, WouldBlock, + PermissionDenied, + MessageTooBig, }; pub fn store_to_existing_file_const(self: *const Self, file_path: []const u8) StoreToFileError!void { From 4d608d413ad5db398cc4ce7e93defeefdc9c2561 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 18 Jun 2025 10:41:12 +0200 Subject: [PATCH 03/13] build: update to zig-0.15.0-dev.836+080ee25ec --- build.zig.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.version b/build.zig.version index 3cfe6f2..3e217e6 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.15.0-dev.703+597dd328e +0.15.0-dev.836+080ee25ec From e28169458ecdeaef564d6dd17b8968e53a3626a6 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 30 Jun 2025 16:01:44 +0200 Subject: [PATCH 04/13] build: update to zig-0.15.0-dev.877+0adcfd60f --- build.zig.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.version b/build.zig.version index 3e217e6..aa1059e 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.15.0-dev.836+080ee25ec +0.15.0-dev.877+0adcfd60f From 0a4c1a57b128967ae39b69a582c1ca30c39f7499 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 1 Jul 2025 19:48:48 +0200 Subject: [PATCH 05/13] build: update std/debug.zig to zig-0.15.0-dev.877+0adcfd60f --- src/renderer/vaxis/renderer.zig | 2 +- src/renderer/vaxis/std/debug.zig | 64 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 8d3cd1f..08130db 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -124,7 +124,7 @@ pub fn install_crash_handler() void { } const act = std.posix.Sigaction{ .handler = .{ .sigaction = handle_crash }, - .mask = std.posix.empty_sigset, + .mask = std.posix.sigemptyset(), .flags = (std.posix.SA.SIGINFO | std.posix.SA.RESTART), }; diff --git a/src/renderer/vaxis/std/debug.zig b/src/renderer/vaxis/std/debug.zig index d155d5a..8608184 100644 --- a/src/renderer/vaxis/std/debug.zig +++ b/src/renderer/vaxis/std/debug.zig @@ -78,13 +78,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { @branchHint(.cold); call("invalid error code", @returnAddress()); } - pub fn castTruncatedData() noreturn { + pub fn integerOutOfBounds() noreturn { @branchHint(.cold); - call("integer cast truncated bits", @returnAddress()); - } - pub fn negativeToUnsigned() noreturn { - @branchHint(.cold); - call("attempt to cast negative value to unsigned integer", @returnAddress()); + call("integer does not fit in destination type", @returnAddress()); } pub fn integerOverflow() noreturn { @branchHint(.cold); @@ -126,9 +122,9 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { @branchHint(.cold); call("for loop over objects with non-equal lengths", @returnAddress()); } - pub fn memcpyLenMismatch() noreturn { + pub fn copyLenMismatch() noreturn { @branchHint(.cold); - call("@memcpy arguments have non-equal lengths", @returnAddress()); + call("source and destination arguments have non-equal lengths", @returnAddress()); } pub fn memcpyAlias() noreturn { @branchHint(.cold); @@ -165,9 +161,11 @@ pub const sys_can_stack_trace = switch (builtin.cpu.arch) { // `@returnAddress()` in LLVM 10 gives // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address". + // On Emscripten, Zig only supports `@returnAddress()` in debug builds + // because Emscripten's implementation is very slow. .wasm32, .wasm64, - => native_os == .emscripten, + => native_os == .emscripten and builtin.mode == .Debug, // `@returnAddress()` is unsupported in LLVM 13. .bpfel, @@ -586,15 +584,20 @@ pub fn defaultPanic( // For backends that cannot handle the language features depended on by the // default panic handler, we have a simpler panic handler: - if (builtin.zig_backend == .stage2_wasm or - builtin.zig_backend == .stage2_arm or - builtin.zig_backend == .stage2_aarch64 or - builtin.zig_backend == .stage2_x86 or - (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf and builtin.target.ofmt != .macho)) or - builtin.zig_backend == .stage2_sparc64 or - builtin.zig_backend == .stage2_spirv64) - { - @trap(); + switch (builtin.zig_backend) { + .stage2_aarch64, + .stage2_arm, + .stage2_powerpc, + .stage2_riscv64, + .stage2_spirv, + .stage2_wasm, + .stage2_x86, + => @trap(), + .stage2_x86_64 => switch (builtin.target.ofmt) { + .elf, .macho => {}, + else => @trap(), + }, + else => {}, } switch (builtin.os.tag) { @@ -615,9 +618,9 @@ pub fn defaultPanic( // isn't visible on actual hardware if directly booted into inline for ([_]?*uefi.protocol.SimpleTextOutput{ uefi.system_table.std_err, uefi.system_table.con_out }) |o| { if (o) |out| { - _ = out.setAttribute(uefi.protocol.SimpleTextOutput.red); - _ = out.outputString(exit_msg); - _ = out.setAttribute(uefi.protocol.SimpleTextOutput.white); + out.setAttribute(.{ .foreground = .red }) catch {}; + _ = out.outputString(exit_msg) catch {}; + out.setAttribute(.{ .foreground = .white }) catch {}; } } @@ -752,7 +755,7 @@ pub const StackIterator = struct { pub fn init(first_address: ?usize, fp: ?usize) StackIterator { if (native_arch.isSPARC()) { // Flush all the register windows on stack. - asm volatile (if (std.Target.sparc.featureSetHas(builtin.cpu.features, .v9)) + asm volatile (if (builtin.cpu.has(.sparc, .v9)) "flushw" else "ta 3" // ST_FLUSH_WINDOWS @@ -905,6 +908,8 @@ pub const StackIterator = struct { } } + if (builtin.omit_frame_pointer) return null; + const fp = if (comptime native_arch.isSPARC()) // On SPARC the offset is positive. (!) math.add(usize, it.fp, fp_offset) catch return null @@ -1371,12 +1376,11 @@ pub fn attachSegfaultHandler() void { windows_segfault_handle = windows.kernel32.AddVectoredExceptionHandler(0, handleSegfaultWindows); return; } - var act = posix.Sigaction{ + const act = posix.Sigaction{ .handler = .{ .sigaction = handleSegfaultPosix }, - .mask = posix.empty_sigset, + .mask = posix.sigemptyset(), .flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND), }; - updateSegfaultHandler(&act); } @@ -1388,9 +1392,9 @@ fn resetSegfaultHandler() void { } return; } - var act = posix.Sigaction{ + const act = posix.Sigaction{ .handler = .{ .handler = posix.SIG.DFL }, - .mask = posix.empty_sigset, + .mask = posix.sigemptyset(), .flags = 0, }; updateSegfaultHandler(&act); @@ -1504,6 +1508,12 @@ fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(.winapi) c_ } fn handleSegfaultWindowsExtra(info: *windows.EXCEPTION_POINTERS, msg: u8, label: ?[]const u8) noreturn { + // For backends that cannot handle the language features used by this segfault handler, we have a simpler one, + switch (builtin.zig_backend) { + .stage2_x86_64 => if (builtin.target.ofmt == .coff) @trap(), + else => {}, + } + comptime assert(windows.CONTEXT != void); nosuspend switch (panic_stage) { 0 => { From e5b20974e851b0795c2c2981ca953fb0a984ed0c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 14 Jul 2025 20:40:49 +0200 Subject: [PATCH 06/13] build: update to zig-0.15.0-dev.936+fc2c1883b The last pre-writergate version. --- build.zig.version | 2 +- build.zig.zon | 12 ++++++------ src/syntax/build.zig.zon | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build.zig.version b/build.zig.version index aa1059e..ca633d3 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.15.0-dev.877+0adcfd60f +0.15.0-dev.936+fc2c1883b diff --git a/build.zig.zon b/build.zig.zon index 000a830..a2e2509 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -15,8 +15,8 @@ .hash = "dizzy-1.0.0-AAAAAM1wAAAiDbx_6RwcVEOBk8p2XOu8t9WPNc3K7kBK", }, .thespian = .{ - .url = "https://github.com/neurocyte/thespian/archive/ccdcbbff09f945eec063ebf889581db3e1312107.tar.gz", - .hash = "thespian-0.0.1-owFOjlgaBgCqc3FCnB4Xyg8-9jyIDWgHSJMGx_nt5Kcc", + .url = "https://github.com/neurocyte/thespian/archive/9af61100d08d79ec52e98fa34ea36611dcc1c361.tar.gz", + .hash = "thespian-0.0.1-owFOjlgaBgAwqxQerLVXpy7blPPZjTqdfH9MLf9_v7dt", }, .themes = .{ .url = "https://github.com/neurocyte/flow-themes/releases/download/master-952f9f630ea9544088fd30293666ee0650b7a690/flow-themes.tar.gz", @@ -27,12 +27,12 @@ .hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX", }, .vaxis = .{ - .url = "https://github.com/neurocyte/libvaxis/archive/64a29f4f91292bc79dc9afb9a254cbdfb35e29a6.tar.gz", - .hash = "vaxis-0.1.0-BWNV_KEOCQCzedUR1prWhPUcgsRmw8f-r5JBc3s4DLJf", + .url = "https://github.com/neurocyte/libvaxis/archive/2a4137dadbe560b13b712fd3aa8a1c313fdd8c6e.tar.gz", + .hash = "vaxis-0.1.0-BWNV_KMOCQAe8oPD6cCn62Rg7oIVgF8FEWLpcAi7xDZQ", }, .zeit = .{ - .url = "https://github.com/rockorager/zeit/archive/8fd203f85f597f16e0a525c1f1ca1e0bffded809.tar.gz", - .hash = "zeit-0.0.0-AAAAACVbAgAiIzg1rccZU1qOfO_dKQKme7-37xmEQcqc", + .url = "https://github.com/rockorager/zeit/archive/991f38266f86535e68431675e8feb84efa1f011b.tar.gz", + .hash = "zeit-0.6.0-5I6bk0t7AgCPM_cY1DoqJB2pnmG7MMtpdO5IxNpryJDy", }, .win32 = .{ .url = "https://github.com/marlersoft/zigwin32/archive/e8739b32a33ce48a3286aba31918b26a9dfc6ef0.tar.gz", diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index 70ca5d8..d8f5c7a 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -6,12 +6,12 @@ .dependencies = .{ .tree_sitter = .{ - .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-1c3ad59bd98ee430b166054030dac4c46d641e39/source.tar.gz", - .hash = "N-V-__8AANMzUiemOR2eNnrtlMmAGHFqij6VYtDUiaFfn6Dw", + .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-353313ad92324f2e9edc10082ce4768d49e44e7e/source.tar.gz", + .hash = "N-V-__8AAEU0UidDMndETXNGKGW66b0yAu58jXL5dmLbOcfH", }, .cbor = .{ - .url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz", - .hash = "cbor-1.0.0-RcQE_HvqAACcrLH7t3IDZOshgY2xqJA_UX330MvwSepb", + .url = "https://github.com/neurocyte/cbor/archive/5ea4b7319146f29bb1aa9acf65982feaba9edc3d.tar.gz", + .hash = "cbor-1.0.0-RcQE_GDyAABovyRXoYFX8zD_NVOLGDc9l5g09-W-svMR", }, }, .paths = .{ From 891945bab1a720a2fe19101c4d62b5ee76c602d9 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 17:00:06 +0200 Subject: [PATCH 07/13] build: update flow-syntax for 0.15.0-dev.1034+bd97b6618 --- src/syntax/build.zig | 12 ++++++------ src/syntax/build.zig.zon | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/syntax/build.zig b/src/syntax/build.zig index 2b3a149..e287604 100644 --- a/src/syntax/build.zig +++ b/src/syntax/build.zig @@ -14,10 +14,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); - const tree_sitter_host_dep = b.dependency("tree_sitter", .{ - .target = b.graph.host, - .optimize = optimize, - }); + const tree_sitter_host_dep = b.dependency("tree_sitter", .{}); const cbor_dep = b.dependency("cbor", .{ .target = target, @@ -26,8 +23,11 @@ pub fn build(b: *std.Build) void { const ts_bin_query_gen = b.addExecutable(.{ .name = "ts_bin_query_gen", - .target = b.graph.host, - .root_source_file = b.path("src/ts_bin_query_gen.zig"), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/ts_bin_query_gen.zig"), + .target = target, + .optimize = optimize, + }), }); ts_bin_query_gen.linkLibC(); ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor")); diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index d8f5c7a..218a167 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -6,12 +6,12 @@ .dependencies = .{ .tree_sitter = .{ - .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-353313ad92324f2e9edc10082ce4768d49e44e7e/source.tar.gz", - .hash = "N-V-__8AAEU0UidDMndETXNGKGW66b0yAu58jXL5dmLbOcfH", + .url = "https://github.com/neurocyte/tree-sitter/releases/download/master-f1f032d24f621e2ee4deab1c424d3bf9fb809f6e/source.tar.gz", + .hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyN88UicDHlr22vQnOZ3DW9NWN1gOhDwLuCRXvrh2", }, .cbor = .{ - .url = "https://github.com/neurocyte/cbor/archive/5ea4b7319146f29bb1aa9acf65982feaba9edc3d.tar.gz", - .hash = "cbor-1.0.0-RcQE_GDyAABovyRXoYFX8zD_NVOLGDc9l5g09-W-svMR", + .url = "git+https://github.com/neurocyte/cbor#6eccce0b984296e7d05c20d83933cb31530e4fac", + .hash = "cbor-1.0.0-RcQE_N3yAADXjbyvhsmTQ6lf22l1nYgePq5FT8NaC4ic", }, }, .paths = .{ From 4cb6d0af05a95cf86019d064999045b7415c6f75 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 17:45:42 +0200 Subject: [PATCH 08/13] build: update to zig-0.15.0-dev.1034+bd97b6618 --- build.zig.version | 2 +- build.zig.zon | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.zig.version b/build.zig.version index ca633d3..2e95286 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.15.0-dev.936+fc2c1883b +0.15.0-dev.1034+bd97b6618 diff --git a/build.zig.zon b/build.zig.zon index a2e2509..d60a43c 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -15,8 +15,8 @@ .hash = "dizzy-1.0.0-AAAAAM1wAAAiDbx_6RwcVEOBk8p2XOu8t9WPNc3K7kBK", }, .thespian = .{ - .url = "https://github.com/neurocyte/thespian/archive/9af61100d08d79ec52e98fa34ea36611dcc1c361.tar.gz", - .hash = "thespian-0.0.1-owFOjlgaBgAwqxQerLVXpy7blPPZjTqdfH9MLf9_v7dt", + .url = "git+https://github.com/neurocyte/thespian#4d317d7bf02eef26da56eddd2d49e46984b50572", + .hash = "thespian-0.0.1-owFOjuEaBgA9zNohtfOqnA8alObpvYjJNNDjEV8dKvLj", }, .themes = .{ .url = "https://github.com/neurocyte/flow-themes/releases/download/master-952f9f630ea9544088fd30293666ee0650b7a690/flow-themes.tar.gz", From 82c431c952e7f17eee3f1b2e493b09833ebdf3ea Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Thu, 17 Jul 2025 11:57:58 +0200 Subject: [PATCH 09/13] update to zig 0.15.0-dev.1048+f43f89a70 --- src/syntax/build.zig | 4 ++-- src/syntax/build.zig.zon | 2 +- src/syntax/src/file_type.zig | 2 +- src/syntax/src/syntax.zig | 8 ++++---- src/syntax/src/treez_dummy.zig | 4 ++-- src/syntax/src/ts_bin_query_gen.zig | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/syntax/build.zig b/src/syntax/build.zig index e287604..4251ae1 100644 --- a/src/syntax/build.zig +++ b/src/syntax/build.zig @@ -25,8 +25,8 @@ pub fn build(b: *std.Build) void { .name = "ts_bin_query_gen", .root_module = b.createModule(.{ .root_source_file = b.path("src/ts_bin_query_gen.zig"), - .target = target, - .optimize = optimize, + .target = b.graph.host, + .optimize = .Debug, }), }); ts_bin_query_gen.linkLibC(); diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index 218a167..5d8194d 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -2,7 +2,7 @@ .name = .flow_syntax, .version = "0.1.0", .fingerprint = 0x3ba2584ea1cec85f, - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.0-dev.1048+f43f89a70", .dependencies = .{ .tree_sitter = .{ diff --git a/src/syntax/src/file_type.zig b/src/syntax/src/file_type.zig index 88a1494..9faa6fa 100644 --- a/src/syntax/src/file_type.zig +++ b/src/syntax/src/file_type.zig @@ -87,7 +87,7 @@ fn ft_func_name(comptime lang: []const u8) []const u8 { return &func_name; } -pub const LangFn = *const fn () callconv(.C) ?*const treez.Language; +pub const LangFn = *const fn () callconv(.c) ?*const treez.Language; pub const FirstLineMatch = struct { prefix: ?[]const u8 = null, diff --git a/src/syntax/src/syntax.zig b/src/syntax/src/syntax.zig index bd67ccf..cb54b08 100644 --- a/src/syntax/src/syntax.zig +++ b/src/syntax/src/syntax.zig @@ -45,12 +45,12 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q return self; } -pub fn static_create_file_type(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { +pub fn create_file_type_static(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.get_by_name_static(lang_name) orelse return error.NotFound; return create(file_type, allocator, query_cache); } -pub fn static_create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { +pub fn create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.guess_static(file_path, content) orelse return error.NotFound; return create(file_type, allocator, query_cache); } @@ -98,7 +98,7 @@ pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const result = ctx.buffer.get_from_pos(.{ .row = position.row, .col = position.column }, &ctx.result_buf, ctx.metrics); bytes_read.* = @intCast(result.len); @@ -124,7 +124,7 @@ pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void { const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { bytes_read.* = 0; const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const pos = (find_line_begin(ctx.content, position.row) orelse return "") + position.column; diff --git a/src/syntax/src/treez_dummy.zig b/src/syntax/src/treez_dummy.zig index b73b1f4..bee4c42 100644 --- a/src/syntax/src/treez_dummy.zig +++ b/src/syntax/src/treez_dummy.zig @@ -23,12 +23,12 @@ pub const InputEncoding = enum(c_uint) { }; pub const Input = extern struct { payload: ?*anyopaque, - read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.C) [*:0]const u8, + read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.c) [*:0]const u8, encoding: InputEncoding, }; pub const Language = struct { var dummy: @This() = .{}; - pub fn LangFn() callconv(.C) ?*const Language { + pub fn LangFn() callconv(.c) ?*const Language { return &dummy; } }; diff --git a/src/syntax/src/ts_bin_query_gen.zig b/src/syntax/src/ts_bin_query_gen.zig index e32c6ef..2584921 100644 --- a/src/syntax/src/ts_bin_query_gen.zig +++ b/src/syntax/src/ts_bin_query_gen.zig @@ -91,7 +91,7 @@ const FileType = struct { highlights: [:0]const u8, injections: ?[:0]const u8, }; -const LangFn = *const fn () callconv(.C) ?*const treez.Language; +const LangFn = *const fn () callconv(.c) ?*const treez.Language; fn load_file_types(comptime Namespace: type) []const FileType { comptime switch (@typeInfo(Namespace)) { From 05d8fe370881ee1ffec8a3629a0c2eea22885e78 Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Thu, 17 Jul 2025 11:57:58 +0200 Subject: [PATCH 10/13] update to zig 0.15.0-dev.1048+f43f89a70 --- src/syntax/build.zig | 4 ++-- src/syntax/build.zig.zon | 2 +- src/syntax/src/file_type.zig | 2 +- src/syntax/src/syntax.zig | 8 ++++---- src/syntax/src/treez_dummy.zig | 4 ++-- src/syntax/src/ts_bin_query_gen.zig | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/syntax/build.zig b/src/syntax/build.zig index e287604..4251ae1 100644 --- a/src/syntax/build.zig +++ b/src/syntax/build.zig @@ -25,8 +25,8 @@ pub fn build(b: *std.Build) void { .name = "ts_bin_query_gen", .root_module = b.createModule(.{ .root_source_file = b.path("src/ts_bin_query_gen.zig"), - .target = target, - .optimize = optimize, + .target = b.graph.host, + .optimize = .Debug, }), }); ts_bin_query_gen.linkLibC(); diff --git a/src/syntax/build.zig.zon b/src/syntax/build.zig.zon index 218a167..5d8194d 100644 --- a/src/syntax/build.zig.zon +++ b/src/syntax/build.zig.zon @@ -2,7 +2,7 @@ .name = .flow_syntax, .version = "0.1.0", .fingerprint = 0x3ba2584ea1cec85f, - .minimum_zig_version = "0.14.1", + .minimum_zig_version = "0.15.0-dev.1048+f43f89a70", .dependencies = .{ .tree_sitter = .{ diff --git a/src/syntax/src/file_type.zig b/src/syntax/src/file_type.zig index 88a1494..9faa6fa 100644 --- a/src/syntax/src/file_type.zig +++ b/src/syntax/src/file_type.zig @@ -87,7 +87,7 @@ fn ft_func_name(comptime lang: []const u8) []const u8 { return &func_name; } -pub const LangFn = *const fn () callconv(.C) ?*const treez.Language; +pub const LangFn = *const fn () callconv(.c) ?*const treez.Language; pub const FirstLineMatch = struct { prefix: ?[]const u8 = null, diff --git a/src/syntax/src/syntax.zig b/src/syntax/src/syntax.zig index bd67ccf..cb54b08 100644 --- a/src/syntax/src/syntax.zig +++ b/src/syntax/src/syntax.zig @@ -45,12 +45,12 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q return self; } -pub fn static_create_file_type(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { +pub fn create_file_type_static(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.get_by_name_static(lang_name) orelse return error.NotFound; return create(file_type, allocator, query_cache); } -pub fn static_create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { +pub fn create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self { const file_type = FileType.guess_static(file_path, content) orelse return error.NotFound; return create(file_type, allocator, query_cache); } @@ -98,7 +98,7 @@ pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const result = ctx.buffer.get_from_pos(.{ .row = position.row, .col = position.column }, &ctx.result_buf, ctx.metrics); bytes_read.* = @intCast(result.len); @@ -124,7 +124,7 @@ pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void { const input: Input = .{ .payload = &state, .read = struct { - fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 { + fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 { bytes_read.* = 0; const ctx: *State = @ptrCast(@alignCast(payload orelse return "")); const pos = (find_line_begin(ctx.content, position.row) orelse return "") + position.column; diff --git a/src/syntax/src/treez_dummy.zig b/src/syntax/src/treez_dummy.zig index b73b1f4..bee4c42 100644 --- a/src/syntax/src/treez_dummy.zig +++ b/src/syntax/src/treez_dummy.zig @@ -23,12 +23,12 @@ pub const InputEncoding = enum(c_uint) { }; pub const Input = extern struct { payload: ?*anyopaque, - read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.C) [*:0]const u8, + read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.c) [*:0]const u8, encoding: InputEncoding, }; pub const Language = struct { var dummy: @This() = .{}; - pub fn LangFn() callconv(.C) ?*const Language { + pub fn LangFn() callconv(.c) ?*const Language { return &dummy; } }; diff --git a/src/syntax/src/ts_bin_query_gen.zig b/src/syntax/src/ts_bin_query_gen.zig index e32c6ef..2584921 100644 --- a/src/syntax/src/ts_bin_query_gen.zig +++ b/src/syntax/src/ts_bin_query_gen.zig @@ -91,7 +91,7 @@ const FileType = struct { highlights: [:0]const u8, injections: ?[:0]const u8, }; -const LangFn = *const fn () callconv(.C) ?*const treez.Language; +const LangFn = *const fn () callconv(.c) ?*const treez.Language; fn load_file_types(comptime Namespace: type) []const FileType { comptime switch (@typeInfo(Namespace)) { From a1c9c53d5c2c2f1bf5e1fd4b7d847f99691f1094 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 21 Jul 2025 12:58:46 +0200 Subject: [PATCH 11/13] build: update fuzzig for zig-0.15.0-dev.1034+bd97b6618 --- build.zig.zon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index d60a43c..c02835b 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -23,8 +23,8 @@ .hash = "N-V-__8AAJiAIgDMVIi8CRb_xko9_qVQ-UiQzd5FTBBr0aPa", }, .fuzzig = .{ - .url = "https://github.com/fjebaker/fuzzig/archive/44c04733c7c0fee3db83672aaaaf4ed03e943156.tar.gz", - .hash = "fuzzig-0.1.1-AAAAALNIAQBmbHr-MPalGuR393Vem2pTQXI7_LXeNJgX", + .url = "https://github.com/fjebaker/fuzzig/archive/4251fe4230d38e721514394a485db62ee1667ff3.tar.gz", + .hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D", }, .vaxis = .{ .url = "https://github.com/neurocyte/libvaxis/archive/2a4137dadbe560b13b712fd3aa8a1c313fdd8c6e.tar.gz", From 6f20c8a13732200e87752f39db3823f455a0d426 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 22 Jul 2025 13:38:07 +0200 Subject: [PATCH 12/13] build: update dizzy --- build.zig.zon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index a2e2509..91b4e9f 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -11,8 +11,8 @@ .hash = "flags-0.8.0-AAAAAJV0AACuGBBnpUnHqZzAhoGTp4ibFROBQQQZGRqx", }, .dizzy = .{ - .url = "https://github.com/neurocyte/dizzy/archive/455d18369cbb2a0458ba70be919cd378338d695e.tar.gz", - .hash = "dizzy-1.0.0-AAAAAM1wAAAiDbx_6RwcVEOBk8p2XOu8t9WPNc3K7kBK", + .url = "https://github.com/neurocyte/dizzy/archive/c9219d23daccd9aa226cfde754fea278cb516459.tar.gz", + .hash = "dizzy-1.0.0-q40X4YCRAAAGYO9QOZiYYSOwiiFlqZlecMuQcxPiBcXM", }, .thespian = .{ .url = "https://github.com/neurocyte/thespian/archive/9af61100d08d79ec52e98fa34ea36611dcc1c361.tar.gz", From a2a771c775ad46cfe3492a42aa3effea95bab3d6 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 5 Aug 2025 20:11:35 +0200 Subject: [PATCH 13/13] WIP: refactor: port to writergate --- build.zig | 36 ++++++++++++++++---------- build.zig.version | 2 +- build.zig.zon | 16 +++++++----- src/list_languages.zig | 2 +- src/main.zig | 44 ++++++++++++++++++++------------ src/renderer/vaxis/renderer.zig | 9 ++++--- src/renderer/vaxis/std/debug.zig | 23 ++++++++++------- 7 files changed, 81 insertions(+), 51 deletions(-) diff --git a/build.zig b/build.zig index 313e84b..f1fb7c5 100644 --- a/build.zig +++ b/build.zig @@ -446,9 +446,11 @@ pub fn build_exe( const keybind_test_run_cmd = blk: { const tests = b.addTest(.{ - .root_source_file = b.path("src/keybind/keybind.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/keybind/keybind.zig"), + .target = target, + .optimize = optimize, + }), }); tests.root_module.addImport("cbor", cbor_mod); tests.root_module.addImport("command", command_mod); @@ -567,10 +569,12 @@ pub fn build_exe( const exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, - .strip = strip, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + .strip = strip, + }), .win32_manifest = b.path("src/win32/flow.manifest"), }); @@ -619,9 +623,11 @@ pub fn build_exe( const check_exe = b.addExecutable(.{ .name = exe_name, - .root_source_file = b.path("src/main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), }); check_exe.root_module.addImport("build_options", options_mod); @@ -644,12 +650,14 @@ pub fn build_exe( check_step.dependOn(&check_exe.step); const tests = b.addTest(.{ - .root_source_file = b.path("test/tests.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("test/tests.zig"), + .target = target, + .optimize = optimize, + .strip = strip, + }), .use_llvm = use_llvm, .use_lld = use_llvm, - .strip = strip, }); tests.pie = pie; diff --git a/build.zig.version b/build.zig.version index 2e95286..0417964 100644 --- a/build.zig.version +++ b/build.zig.version @@ -1 +1 @@ -0.15.0-dev.1034+bd97b6618 +0.15.0-dev.1184+c41ac8f19 diff --git a/build.zig.zon b/build.zig.zon index 8547f3f..281b074 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -7,8 +7,8 @@ .dependencies = .{ .syntax = .{ .path = "src/syntax" }, .flags = .{ - .url = "https://github.com/n0s4/flags/archive/372501d1576b5723829bcba98e41361132c7b618.tar.gz", - .hash = "flags-0.8.0-AAAAAJV0AACuGBBnpUnHqZzAhoGTp4ibFROBQQQZGRqx", + .url = "git+https://github.com/neurocyte/flags?ref=main#984b27948da3e4e40a253f76c85b51ec1a9ada11", + .hash = "flags-0.10.0-a_9h3gB4AADAYn0XaZuUqH1jKRmy6dqvAIbomtTIF6V1", }, .dizzy = .{ .url = "https://github.com/neurocyte/dizzy/archive/c9219d23daccd9aa226cfde754fea278cb516459.tar.gz", @@ -27,18 +27,22 @@ .hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D", }, .vaxis = .{ - .url = "https://github.com/neurocyte/libvaxis/archive/2a4137dadbe560b13b712fd3aa8a1c313fdd8c6e.tar.gz", - .hash = "vaxis-0.1.0-BWNV_KMOCQAe8oPD6cCn62Rg7oIVgF8FEWLpcAi7xDZQ", + .url = "git+https://github.com/neurocyte/libvaxis?ref=zig-0.15.0#04f87f558102ce8424dbcb07c62bad9370dea6ea", + .hash = "vaxis-0.5.1-BWNV_McRCQCJb40sR8iP-OcFTZ1912DBcEyMeMAkLanL", }, .zeit = .{ - .url = "https://github.com/rockorager/zeit/archive/991f38266f86535e68431675e8feb84efa1f011b.tar.gz", - .hash = "zeit-0.6.0-5I6bk0t7AgCPM_cY1DoqJB2pnmG7MMtpdO5IxNpryJDy", + .url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#06ec40445cc477fea5a8369f1ba3881e2a3c00eb", + .hash = "zeit-0.6.0-5I6bkyJ8AgAS1_0NDvfxmFsBDTOxkZXtLUHrmPjcmt-K", }, .win32 = .{ .url = "https://github.com/marlersoft/zigwin32/archive/e8739b32a33ce48a3286aba31918b26a9dfc6ef0.tar.gz", .hash = "zigwin32-25.0.28-preview-AAAAAEEl_AMhnKSs-lgEyjmUX5JVTpNQewd8A2Bbekwc", .lazy = true, }, + .zig_tracy = .{ + .url = "git+https://github.com/neurocyte/zig-tracy?ref=master#67070c146104d93fd3bed5091738f22e33e13bce", + .hash = "zig_tracy-0.0.3-5-cp3Ht3AAAfHqShKfTK7waFK3Wjd3l2NheiqxvRRAdo", + }, }, .paths = .{ "include", diff --git a/src/list_languages.zig b/src/list_languages.zig index 6efbd10..376424c 100644 --- a/src/list_languages.zig +++ b/src/list_languages.zig @@ -10,7 +10,7 @@ const checkmark_width = if (builtin.os.tag != .windows) 2 else 3; const success_mark = if (builtin.os.tag != .windows) "✓ " else "[y]"; const fail_mark = if (builtin.os.tag != .windows) "✘ " else "[n]"; -pub fn list(allocator: std.mem.Allocator, writer: anytype, tty_config: std.io.tty.Config) !void { +pub fn list(allocator: std.mem.Allocator, writer: *std.io.Writer, tty_config: std.io.tty.Config) !void { var max_language_len: usize = 0; var max_langserver_len: usize = 0; var max_formatter_len: usize = 0; diff --git a/src/main.zig b/src/main.zig index 07e1cf5..086c40b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -121,32 +121,41 @@ pub fn main() anyerror!void { scratch: bool, new_file: bool, version: bool, + + positional: struct { + trailing: []const []const u8, + }, }; - var arg_iter = try std.process.argsWithAllocator(a); - defer arg_iter.deinit(); + const args_alloc = try std.process.argsAlloc(a); + defer std.process.argsFree(a, args_alloc); var diag: flags.Diagnostics = undefined; - var positional_args = std.ArrayList([]const u8).init(a); - defer positional_args.deinit(); - const args = flags.parse(&arg_iter, "flow", Flags, .{ + const args = flags.parse(args_alloc, "flow", Flags, .{ .diagnostics = &diag, - .trailing_list = &positional_args, }) catch |err| { if (err == error.PrintedHelp) exit(0); - diag.help.generated.render(std.io.getStdOut(), flags.ColorScheme.default) catch {}; + try diag.printUsage(&flags.ColorScheme.default); exit(1); return err; }; + var stdout_buf: [4096]u8 = undefined; + var stdout_file = std.fs.File.stdout().writer(&stdout_buf); + const stdout = &stdout_file.interface; + defer stdout.flush() catch {}; + var stderr_buf: [4096]u8 = undefined; + var stderr_file = std.fs.File.stderr().writer(&stderr_buf); + const stderr = &stderr_file.interface; + defer stderr.flush() catch {}; + if (args.version) - return std.io.getStdOut().writeAll(version_info); + return std.fs.File.stdout().writeAll(version_info); if (args.list_languages) { - const stdout = std.io.getStdOut(); - const tty_config = std.io.tty.detectConfig(stdout); - return list_languages.list(a, stdout.writer(), tty_config); + const tty_config = std.io.tty.detectConfig(std.fs.File.stdout()); + return list_languages.list(a, stdout, tty_config); } if (builtin.os.tag != .windows and @hasDecl(renderer, "install_crash_handler")) { @@ -157,11 +166,12 @@ pub fn main() anyerror!void { if (args.debug_wait) { std.debug.print("press return to start", .{}); var buf: [1]u8 = undefined; - _ = try std.io.getStdIn().read(&buf); + _ = try std.fs.File.stdin().read(&buf); } if (c.setlocale(c.LC_ALL, "") == null) { - try std.io.getStdErr().writer().print("Failed to set locale. Is your locale valid?\n", .{}); + try stderr.print("Failed to set locale. Is your locale valid?\n", .{}); + stderr.flush() catch {}; exit(1); } @@ -244,7 +254,7 @@ pub fn main() anyerror!void { defer links.deinit(); var prev: ?*file_link.Dest = null; var line_next: ?usize = null; - for (positional_args.items) |arg| { + for (args.positional.trailing.items) |arg| { if (arg.len == 0) continue; if (!args.literal and arg[0] == '+') { @@ -366,17 +376,17 @@ fn count_args() usize { return count; } -fn trace(m: thespian.message.c_buffer_type) callconv(.C) void { +fn trace(m: thespian.message.c_buffer_type) callconv(.c) void { thespian.message.from(m).to_json_cb(trace_json); } -fn trace_json(json: thespian.message.json_string_view) callconv(.C) void { +fn trace_json(json: thespian.message.json_string_view) callconv(.c) void { const callstack_depth = 10; ___tracy_emit_message(json.base, json.len, callstack_depth); } extern fn ___tracy_emit_message(txt: [*]const u8, size: usize, callstack: c_int) void; -fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.C) void { +fn trace_to_file(m: thespian.message.c_buffer_type) callconv(.c) void { const State = struct { file: std.fs.File, last_time: i64, diff --git a/src/renderer/vaxis/renderer.zig b/src/renderer/vaxis/renderer.zig index 44b121d..e5f91e9 100644 --- a/src/renderer/vaxis/renderer.zig +++ b/src/renderer/vaxis/renderer.zig @@ -156,7 +156,10 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque self.tty.deinit(); } if (builtin.os.tag == .linux and jit_debugger_enabled) { - handleSegfaultPosixNoAbort(sig, info, ctx_ptr); + var buf: [4096]u8 = undefined; + var stderr = std.fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + handleSegfaultPosixNoAbort(&stderr.interface, sig, info, ctx_ptr); @import("thespian").sighdl_debugger(sig, @ptrCast(@constCast(info)), ctx_ptr); std.posix.abort(); } else { @@ -165,7 +168,7 @@ fn handle_crash(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque unreachable; } -fn handleSegfaultPosixNoAbort(sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { +fn handleSegfaultPosixNoAbort(stderr: *std.io.Writer, sig: i32, info: *const std.posix.siginfo_t, ctx_ptr: ?*anyopaque) void { const debug = @import("std/debug.zig"); debug.resetSegfaultHandler(); const addr = switch (builtin.os.tag) { @@ -177,7 +180,7 @@ fn handleSegfaultPosixNoAbort(sig: i32, info: *const std.posix.siginfo_t, ctx_pt else => unreachable, }; const code = if (builtin.os.tag == .netbsd) info.info.code else info.code; - debug.dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + debug.dumpSegfaultInfoPosix(stderr, sig, code, addr, ctx_ptr); } pub fn run(self: *Self) Error!void { diff --git a/src/renderer/vaxis/std/debug.zig b/src/renderer/vaxis/std/debug.zig index b5f8697..d8289d6 100644 --- a/src/renderer/vaxis/std/debug.zig +++ b/src/renderer/vaxis/std/debug.zig @@ -384,16 +384,14 @@ pub inline fn getContext(context: *ThreadContext) bool { /// Tries to print the stack trace starting from the supplied base pointer to stderr, /// unbuffered, and ignores any error returned. /// TODO multithreaded awareness -pub fn dumpStackTraceFromBase(context: *ThreadContext) void { +pub fn dumpStackTraceFromBase(stderr: *io.Writer, context: *ThreadContext) void { nosuspend { if (builtin.target.cpu.arch.isWasm()) { if (native_os == .wasi) { - const stderr = io.getStdErr().writer(); stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return; } return; } - const stderr = io.getStdErr().writer(); if (builtin.strip_debug_info) { stderr.print("Unable to dump stack trace: debug info stripped\n", .{}) catch return; return; @@ -402,7 +400,7 @@ pub fn dumpStackTraceFromBase(context: *ThreadContext) void { stderr.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}) catch return; return; }; - const tty_config = io.tty.detectConfig(io.getStdErr()); + const tty_config = io.tty.detectConfig(fs.File.stderr()); if (native_os == .windows) { // On x86_64 and aarch64, the stack will be unwound using RtlVirtualUnwind using the context // provided by the exception handler. On x86, RtlVirtualUnwind doesn't exist. Instead, a new backtrace @@ -1425,14 +1423,22 @@ pub fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*an lockStdErr(); defer unlockStdErr(); - dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + var buf: [4096]u8 = undefined; + var stderr = fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + + dumpSegfaultInfoPosix(&stderr.interface, sig, code, addr, ctx_ptr); } waitForOtherThreadToFinishPanicking(); }, else => { + var buf: [4096]u8 = undefined; + var stderr = fs.File.stderr().writer(&buf); + defer stderr.interface.flush() catch {}; + // panic mutex already locked - dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr); + dumpSegfaultInfoPosix(&stderr.interface, sig, code, addr, ctx_ptr); }, }; @@ -1442,8 +1448,7 @@ pub fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*an posix.abort(); } -pub fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void { - const stderr = io.getStdErr().writer(); +pub fn dumpSegfaultInfoPosix(stderr: *io.Writer, sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopaque) void { _ = switch (sig) { posix.SIG.SEGV => if (native_arch == .x86_64 and native_os == .linux and code == 128) // SI_KERNEL // x86_64 doesn't have a full 64-bit virtual address space. @@ -1491,7 +1496,7 @@ pub fn dumpSegfaultInfoPosix(sig: i32, code: i32, addr: usize, ctx_ptr: ?*anyopa }, @ptrCast(ctx)).__mcontext_data; } relocateContext(&new_ctx); - dumpStackTraceFromBase(&new_ctx); + dumpStackTraceFromBase(stderr, &new_ctx); }, else => {}, }