From c06ae87cbceec8cc3c2e263eedbc2495b60bfe3a Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Tue, 6 Jan 2026 07:46:53 +0200 Subject: [PATCH] Update to zig 0.15 --- build.zig | 4 +--- build.zig.zon | 4 ++-- flake.lock | 6 +++--- src/args/args.zig | 20 ++++++++++---------- src/log/logging.zig | 37 +++++++++++++++++++------------------ src/util/niceTypeName.zig | 2 +- src/util/queue.zig | 16 ++++++++-------- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/build.zig b/build.zig index 402e1d5..c906ded 100644 --- a/build.zig +++ b/build.zig @@ -18,9 +18,7 @@ pub fn build(b: *std.Build) void { module.addImport("chameleon", chameleon.module("chameleon")); const libTests = b.addTest(.{ - .root_source_file = libRoot, - .target = target, - .optimize = optimize, + .root_module = module, }); libTests.root_module.addImport("chameleon", chameleon.module("chameleon")); diff --git a/build.zig.zon b/build.zig.zon index d4c7180..450c951 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -5,8 +5,8 @@ .dependencies = .{ .chameleon = .{ - .url = "git+https://github.com/tr1ckydev/chameleon#ae88d41f061adbf3d8bb569519cb065aad65db06", - .hash = "chameleon-2.0.1-ZOxajfpzAADVWecH5mnE4qGV7vO3aMfLPvFUzvQbMqdg", + .url = "git+https://github.com/tr1ckydev/chameleon#414169dede742d9ac8261d31b9fca6e31a1d7246", + .hash = "chameleon-2.0.1-ZOxajZ17AADmYCpHFqqoGfaXQiRkXM8B5lYJfir9tqsz", }, }, .paths = .{ diff --git a/flake.lock b/flake.lock index f12816a..11e1269 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1746064326, - "narHash": "sha256-r7IZkN9NhK/IO9/J6D9ih2P1OXb67nr5HaQ1YAte18w=", + "lastModified": 1767379071, + "narHash": "sha256-EgE0pxsrW9jp9YFMkHL9JMXxcqi/OoumPJYwf+Okucw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "91bf6dffa21c7709607c9fdbf9a6acb44e7a0a5d", + "rev": "fb7944c166a3b630f177938e478f0378e64ce108", "type": "github" }, "original": { diff --git a/src/args/args.zig b/src/args/args.zig index c364252..c864ce0 100644 --- a/src/args/args.zig +++ b/src/args/args.zig @@ -67,8 +67,8 @@ pub fn parseArgs(comptime T: type, allocator: Allocator) !T { /// /// Parsing order of arguments is based on the order they are declared in `T`. pub fn parseArgsFromSlice(comptime T: type, allocator: Allocator, args: [][]const u8) !T { - var flags = std.ArrayList(Arg).init(allocator); - defer flags.deinit(); + var flags = try std.ArrayList(Arg).initCapacity(allocator, 4); + defer flags.deinit(allocator); if (args.len == 0) { return error.NoArguments; @@ -80,7 +80,7 @@ pub fn parseArgsFromSlice(comptime T: type, allocator: Allocator, args: [][]cons const argument = try Arg.parseArg(arg); - try flags.append(argument); + try flags.append(allocator, argument); } var i: usize = 0; @@ -289,8 +289,8 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T { return error.CouldNotFindFlag; }, .Remainder => { - var not_consumed = std.ArrayList([]const u8).init(result.allocator); - errdefer not_consumed.deinit(); + var not_consumed = try std.ArrayList([]const u8).initCapacity(result.allocator, 8); + errdefer not_consumed.deinit(result.allocator); for (flags) |*flag| { if (flag.isConsumed()) continue; @@ -311,14 +311,14 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T { defer result.allocator.free(flagText); if (f.short) { - try not_consumed.append(try std.fmt.allocPrint(result.allocator, "-{s}", .{flagText})); + try not_consumed.append(result.allocator, try std.fmt.allocPrint(result.allocator, "-{s}", .{flagText})); } else { - try not_consumed.append(try std.fmt.allocPrint(result.allocator, "--{s}", .{flagText})); + try not_consumed.append(result.allocator, try std.fmt.allocPrint(result.allocator, "--{s}", .{flagText})); } }, .Positional => |p| { flag.setConsumed(); - try not_consumed.append(try result.allocator.dupe(u8, p.value)); + try not_consumed.append(result.allocator, try result.allocator.dupe(u8, p.value)); }, } } @@ -706,7 +706,7 @@ test "remainder has value" { for (self.remainder.value.items) |item| { self.allocator.free(item); } - self.remainder.value.deinit(); + self.remainder.value.deinit(self.allocator); self.* = undefined; } @@ -744,7 +744,7 @@ test "sub command from remainder" { for (self.remainder.value.items) |item| { self.allocator.free(item); } - self.remainder.value.deinit(); + self.remainder.value.deinit(self.allocator); self.* = undefined; } diff --git a/src/log/logging.zig b/src/log/logging.zig index 880708b..3678276 100644 --- a/src/log/logging.zig +++ b/src/log/logging.zig @@ -51,7 +51,7 @@ const Globals = struct { .enable_file_output = false, .output_file = null, - .additional_scopes = std.ArrayList(ScopeModifier).init(allocator), + .additional_scopes = try std.ArrayList(ScopeModifier).initCapacity(allocator, 0), }; } @@ -67,7 +67,7 @@ const Globals = struct { modifier.*.scope.deinit(); } - self.additional_scopes.deinit(); + self.additional_scopes.deinit(self.allocator); self.* = undefined; } @@ -110,7 +110,7 @@ pub const config = struct { pub fn addScope(modifier: ScopeModifier) !void { if (core) |*globals| { - try globals.additional_scopes.append(modifier); + try globals.additional_scopes.append(globals.allocator, modifier); } else { unreachable; // logging is not initialized } @@ -164,12 +164,12 @@ fn prep(name: []const u8, modifier: ?*const ScopeModifier, allocator: Allocator) var chunks = std.mem.tokenizeScalar(u8, name, '_'); - var output = std.ArrayList(u8).init(allocator); + var output = try std.ArrayList(u8).initCapacity(allocator, 2048); var isFirst = true; while (chunks.next()) |chunk| { if (!isFirst) { - _ = try output.writer().write("::"); + _ = try output.print(allocator, "::", .{}); } else { isFirst = false; } @@ -177,24 +177,24 @@ fn prep(name: []const u8, modifier: ?*const ScopeModifier, allocator: Allocator) if (modifier) |mod| { if (mod.color) |color| { _ = switch (color) { - .default => try output.writer().write(chunk), - .blue => try output.writer().write(try c.blue().fmt("{s}", .{chunk})), - .green => try output.writer().write(try c.green().fmt("{s}", .{chunk})), - .red => try output.writer().write(try c.red().fmt("{s}", .{chunk})), - .white => try output.writer().write(try c.white().fmt("{s}", .{chunk})), - .yellow => try output.writer().write(try c.yellow().fmt("{s}", .{chunk})), - .magenta => try output.writer().write(try c.magenta().fmt("{s}", .{chunk})), - .cyan => try output.writer().write(try c.cyan().fmt("{s}", .{chunk})), + .default => try output.print(allocator, "{s}", .{chunk}), + .blue => try output.print(allocator, "{s}", .{try c.blue().fmt("{s}", .{chunk})}), + .green => try output.print(allocator, "{s}", .{try c.green().fmt("{s}", .{chunk})}), + .red => try output.print(allocator, "{s}", .{try c.red().fmt("{s}", .{chunk})}), + .white => try output.print(allocator, "{s}", .{try c.white().fmt("{s}", .{chunk})}), + .yellow => try output.print(allocator, "{s}", .{try c.yellow().fmt("{s}", .{chunk})}), + .magenta => try output.print(allocator, "{s}", .{try c.magenta().fmt("{s}", .{chunk})}), + .cyan => try output.print(allocator, "{s}", .{try c.cyan().fmt("{s}", .{chunk})}), }; } else { - _ = try output.writer().write(chunk); + _ = try output.print(allocator, "{s}", .{chunk}); } } else { - _ = try output.writer().write(chunk); + _ = try output.print(allocator, "{s}", .{chunk}); } } - return try output.toOwnedSlice(); + return try output.toOwnedSlice(allocator); } fn logFnImpl(comptime level: Level, comptime scope: Scope, comptime format: []const u8, args: anytype) !void { @@ -268,9 +268,10 @@ fn logFnImpl(comptime level: Level, comptime scope: Scope, comptime format: []co if (globals.enable_file_output and globals.output_file != null) { var file = try globals.initOrGetFile(); - var writer = file.writer().any(); + var buf: [0]u8 = undefined; + var writer = file.writer(&buf); - nosuspend try writer.print("{s} {s}\n", .{ + nosuspend try writer.interface.print("{s} {s}\n", .{ prefix, message, }); diff --git a/src/util/niceTypeName.zig b/src/util/niceTypeName.zig index 4e349c7..1d2fbb5 100644 --- a/src/util/niceTypeName.zig +++ b/src/util/niceTypeName.zig @@ -7,7 +7,7 @@ pub fn niceTypeName(comptime T: type) []const u8 { const name = @typeName(T); - if (std.mem.startsWith(u8, name, "array_list.ArrayListAligned")) { + if (std.mem.startsWith(u8, name, "array_list.Aligned")) { return "array"; } diff --git a/src/util/queue.zig b/src/util/queue.zig index 4e1e7fc..87a1476 100644 --- a/src/util/queue.zig +++ b/src/util/queue.zig @@ -3,16 +3,16 @@ const Atomic = std.atomic.Value; pub fn MPSCQueue(comptime T: type) type { return struct { - const Self = @This(); - buffer: std.ArrayList(T), head: Atomic(usize), tail: Atomic(usize), allocator: std.mem.Allocator, - pub fn init(allocator: std.mem.Allocator) Self { + const Self = @This(); + + pub fn init(allocator: std.mem.Allocator) !Self { return .{ - .buffer = std.ArrayList(T).init(allocator), + .buffer = try std.ArrayList(T).initCapacity(allocator, 0), .head = Atomic(usize).init(0), .tail = Atomic(usize).init(0), .allocator = allocator, @@ -20,7 +20,7 @@ pub fn MPSCQueue(comptime T: type) type { } pub fn deinit(self: *Self) void { - self.buffer.deinit(); + self.buffer.deinit(self.allocator); } pub fn push(self: *Self, item: T) !void { @@ -29,7 +29,7 @@ pub fn MPSCQueue(comptime T: type) type { // Ensure capacity if (tail >= self.buffer.items.len) { const new_capacity = if (self.buffer.items.len == 0) 8 else self.buffer.items.len * 2; - try self.buffer.resize(new_capacity); + try self.buffer.resize(self.allocator, new_capacity); } // Store item and update tail @@ -67,7 +67,7 @@ pub fn MPSCQueue(comptime T: type) type { const t = std.testing; test "MPSC Queue basic operations" { - var queue = MPSCQueue(i32).init(t.allocator); + var queue = try MPSCQueue(i32).init(t.allocator); defer queue.deinit(); try queue.push(1); @@ -98,7 +98,7 @@ fn threadTwo(queue: *MPSCQueue(i32)) !void { test "MPSC Threaded" { const Thread = std.Thread; - var q = MPSCQueue(i32).init(t.allocator); + var q = try MPSCQueue(i32).init(t.allocator); defer q.deinit(); const t1 = try Thread.spawn(.{ .allocator = t.allocator }, threadOne, .{&q});