Update to Zig 0.16.0 (#962)

Signed-off-by: AnErrupTion <anerruption@disroot.org>

## What are the changes about?

Ports the code base to Zig 0.16.0.

## What existing issue does this resolve?

N/A

## Pre-requisites

- [x] I have tested & confirmed the changes work locally
- [x] I have run `zig fmt` throughout my changes

Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/962
This commit is contained in:
AnErrupTion
2026-04-25 17:37:34 +02:00
committed by AnErrupTion
parent eec83179b9
commit 5edf5251f6
26 changed files with 751 additions and 587 deletions

View File

@@ -5,27 +5,27 @@ const LogFile = @This();
path: []const u8,
could_open_log_file: bool = undefined,
file: std.fs.File = undefined,
file: std.Io.File = undefined,
buffer: []u8,
file_writer: std.fs.File.Writer = undefined,
file_writer: std.Io.File.Writer = undefined,
pub fn init(path: []const u8, buffer: []u8) !LogFile {
pub fn init(io: std.Io, path: []const u8, buffer: []u8) !LogFile {
var log_file = LogFile{ .path = path, .buffer = buffer };
log_file.could_open_log_file = try openLogFile(path, &log_file);
log_file.could_open_log_file = try openLogFile(io, path, &log_file);
return log_file;
}
pub fn reinit(self: *LogFile) !void {
self.could_open_log_file = try openLogFile(self.path, self);
pub fn reinit(self: *LogFile, io: std.Io) !void {
self.could_open_log_file = try openLogFile(io, self.path, self);
}
pub fn deinit(self: *LogFile) void {
self.file.close();
pub fn deinit(self: *LogFile, io: std.Io) void {
self.file.close(io);
}
pub fn info(self: *LogFile, category: []const u8, comptime message: []const u8, args: anytype) !void {
pub fn info(self: *LogFile, io: std.Io, category: []const u8, comptime message: []const u8, args: anytype) !void {
var buffer: [128:0]u8 = undefined;
const time = interop.timeAsString(&buffer, "%Y-%m-%d %H:%M:%S");
const time = interop.timeAsString(io, &buffer, "%Y-%m-%d %H:%M:%S");
try self.file_writer.interface.print("{s} [info/{s}] ", .{ time, category });
try self.file_writer.interface.print(message, args);
@@ -33,9 +33,9 @@ pub fn info(self: *LogFile, category: []const u8, comptime message: []const u8,
try self.file_writer.interface.flush();
}
pub fn err(self: *LogFile, category: []const u8, comptime message: []const u8, args: anytype) !void {
pub fn err(self: *LogFile, io: std.Io, category: []const u8, comptime message: []const u8, args: anytype) !void {
var buffer: [128:0]u8 = undefined;
const time = interop.timeAsString(&buffer, "%Y-%m-%d %H:%M:%S");
const time = interop.timeAsString(io, &buffer, "%Y-%m-%d %H:%M:%S");
try self.file_writer.interface.print("{s} [err/{s}] ", .{ time, category });
try self.file_writer.interface.print(message, args);
@@ -43,10 +43,10 @@ pub fn err(self: *LogFile, category: []const u8, comptime message: []const u8, a
try self.file_writer.interface.flush();
}
fn openLogFile(path: []const u8, log_file: *LogFile) !bool {
fn openLogFile(io: std.Io, path: []const u8, log_file: *LogFile) !bool {
var could_open_log_file = true;
open_log_file: {
log_file.file = std.fs.cwd().openFile(path, .{ .mode = .write_only }) catch std.fs.cwd().createFile(path, .{ .mode = 0o666 }) catch {
log_file.file = std.Io.Dir.cwd().openFile(io, path, .{ .mode = .write_only }) catch std.Io.Dir.cwd().createFile(io, path, .{ .permissions = .fromMode(0o666) }) catch {
// If we could neither open an existing log file nor create a new
// one, abort.
could_open_log_file = false;
@@ -55,14 +55,14 @@ fn openLogFile(path: []const u8, log_file: *LogFile) !bool {
}
if (!could_open_log_file) {
log_file.file = try std.fs.openFileAbsolute("/dev/null", .{ .mode = .write_only });
log_file.file = try std.Io.Dir.openFileAbsolute(io, "/dev/null", .{ .mode = .write_only });
}
var log_file_writer = log_file.file.writer(log_file.buffer);
var log_file_writer = log_file.file.writer(io, log_file.buffer);
// Seek to the end of the log file
if (could_open_log_file) {
const stat = try log_file.file.stat();
const stat = try log_file.file.stat(io);
try log_file_writer.seekTo(stat.size);
}