Update to zig 0.15

This commit is contained in:
Lyssieth 2026-01-06 07:46:53 +02:00
parent 50d8cc92bd
commit c06ae87cbc
Signed by untrusted user who does not match committer: lyssieth
GPG key ID: 6EE87E973D3AA8F2
7 changed files with 44 additions and 45 deletions

View file

@ -18,9 +18,7 @@ pub fn build(b: *std.Build) void {
module.addImport("chameleon", chameleon.module("chameleon")); module.addImport("chameleon", chameleon.module("chameleon"));
const libTests = b.addTest(.{ const libTests = b.addTest(.{
.root_source_file = libRoot, .root_module = module,
.target = target,
.optimize = optimize,
}); });
libTests.root_module.addImport("chameleon", chameleon.module("chameleon")); libTests.root_module.addImport("chameleon", chameleon.module("chameleon"));

View file

@ -5,8 +5,8 @@
.dependencies = .{ .dependencies = .{
.chameleon = .{ .chameleon = .{
.url = "git+https://github.com/tr1ckydev/chameleon#ae88d41f061adbf3d8bb569519cb065aad65db06", .url = "git+https://github.com/tr1ckydev/chameleon#414169dede742d9ac8261d31b9fca6e31a1d7246",
.hash = "chameleon-2.0.1-ZOxajfpzAADVWecH5mnE4qGV7vO3aMfLPvFUzvQbMqdg", .hash = "chameleon-2.0.1-ZOxajZ17AADmYCpHFqqoGfaXQiRkXM8B5lYJfir9tqsz",
}, },
}, },
.paths = .{ .paths = .{

View file

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1746064326, "lastModified": 1767379071,
"narHash": "sha256-r7IZkN9NhK/IO9/J6D9ih2P1OXb67nr5HaQ1YAte18w=", "narHash": "sha256-EgE0pxsrW9jp9YFMkHL9JMXxcqi/OoumPJYwf+Okucw=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "91bf6dffa21c7709607c9fdbf9a6acb44e7a0a5d", "rev": "fb7944c166a3b630f177938e478f0378e64ce108",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -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`. /// 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 { pub fn parseArgsFromSlice(comptime T: type, allocator: Allocator, args: [][]const u8) !T {
var flags = std.ArrayList(Arg).init(allocator); var flags = try std.ArrayList(Arg).initCapacity(allocator, 4);
defer flags.deinit(); defer flags.deinit(allocator);
if (args.len == 0) { if (args.len == 0) {
return error.NoArguments; return error.NoArguments;
@ -80,7 +80,7 @@ pub fn parseArgsFromSlice(comptime T: type, allocator: Allocator, args: [][]cons
const argument = try Arg.parseArg(arg); const argument = try Arg.parseArg(arg);
try flags.append(argument); try flags.append(allocator, argument);
} }
var i: usize = 0; var i: usize = 0;
@ -289,8 +289,8 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T {
return error.CouldNotFindFlag; return error.CouldNotFindFlag;
}, },
.Remainder => { .Remainder => {
var not_consumed = std.ArrayList([]const u8).init(result.allocator); var not_consumed = try std.ArrayList([]const u8).initCapacity(result.allocator, 8);
errdefer not_consumed.deinit(); errdefer not_consumed.deinit(result.allocator);
for (flags) |*flag| { for (flags) |*flag| {
if (flag.isConsumed()) continue; if (flag.isConsumed()) continue;
@ -311,14 +311,14 @@ fn initFromParsed(comptime T: type, allocator: Allocator, flags: []Arg) !T {
defer result.allocator.free(flagText); defer result.allocator.free(flagText);
if (f.short) { 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 { } 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| { .Positional => |p| {
flag.setConsumed(); 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| { for (self.remainder.value.items) |item| {
self.allocator.free(item); self.allocator.free(item);
} }
self.remainder.value.deinit(); self.remainder.value.deinit(self.allocator);
self.* = undefined; self.* = undefined;
} }
@ -744,7 +744,7 @@ test "sub command from remainder" {
for (self.remainder.value.items) |item| { for (self.remainder.value.items) |item| {
self.allocator.free(item); self.allocator.free(item);
} }
self.remainder.value.deinit(); self.remainder.value.deinit(self.allocator);
self.* = undefined; self.* = undefined;
} }

View file

@ -51,7 +51,7 @@ const Globals = struct {
.enable_file_output = false, .enable_file_output = false,
.output_file = null, .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(); modifier.*.scope.deinit();
} }
self.additional_scopes.deinit(); self.additional_scopes.deinit(self.allocator);
self.* = undefined; self.* = undefined;
} }
@ -110,7 +110,7 @@ pub const config = struct {
pub fn addScope(modifier: ScopeModifier) !void { pub fn addScope(modifier: ScopeModifier) !void {
if (core) |*globals| { if (core) |*globals| {
try globals.additional_scopes.append(modifier); try globals.additional_scopes.append(globals.allocator, modifier);
} else { } else {
unreachable; // logging is not initialized 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 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; var isFirst = true;
while (chunks.next()) |chunk| { while (chunks.next()) |chunk| {
if (!isFirst) { if (!isFirst) {
_ = try output.writer().write("::"); _ = try output.print(allocator, "::", .{});
} else { } else {
isFirst = false; isFirst = false;
} }
@ -177,24 +177,24 @@ fn prep(name: []const u8, modifier: ?*const ScopeModifier, allocator: Allocator)
if (modifier) |mod| { if (modifier) |mod| {
if (mod.color) |color| { if (mod.color) |color| {
_ = switch (color) { _ = switch (color) {
.default => try output.writer().write(chunk), .default => try output.print(allocator, "{s}", .{chunk}),
.blue => try output.writer().write(try c.blue().fmt("{s}", .{chunk})), .blue => try output.print(allocator, "{s}", .{try c.blue().fmt("{s}", .{chunk})}),
.green => try output.writer().write(try c.green().fmt("{s}", .{chunk})), .green => try output.print(allocator, "{s}", .{try c.green().fmt("{s}", .{chunk})}),
.red => try output.writer().write(try c.red().fmt("{s}", .{chunk})), .red => try output.print(allocator, "{s}", .{try c.red().fmt("{s}", .{chunk})}),
.white => try output.writer().write(try c.white().fmt("{s}", .{chunk})), .white => try output.print(allocator, "{s}", .{try c.white().fmt("{s}", .{chunk})}),
.yellow => try output.writer().write(try c.yellow().fmt("{s}", .{chunk})), .yellow => try output.print(allocator, "{s}", .{try c.yellow().fmt("{s}", .{chunk})}),
.magenta => try output.writer().write(try c.magenta().fmt("{s}", .{chunk})), .magenta => try output.print(allocator, "{s}", .{try c.magenta().fmt("{s}", .{chunk})}),
.cyan => try output.writer().write(try c.cyan().fmt("{s}", .{chunk})), .cyan => try output.print(allocator, "{s}", .{try c.cyan().fmt("{s}", .{chunk})}),
}; };
} else { } else {
_ = try output.writer().write(chunk); _ = try output.print(allocator, "{s}", .{chunk});
} }
} else { } 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 { 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) { if (globals.enable_file_output and globals.output_file != null) {
var file = try globals.initOrGetFile(); 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, prefix,
message, message,
}); });

View file

@ -7,7 +7,7 @@ pub fn niceTypeName(comptime T: type) []const u8 {
const name = @typeName(T); const name = @typeName(T);
if (std.mem.startsWith(u8, name, "array_list.ArrayListAligned")) { if (std.mem.startsWith(u8, name, "array_list.Aligned")) {
return "array"; return "array";
} }

View file

@ -3,16 +3,16 @@ const Atomic = std.atomic.Value;
pub fn MPSCQueue(comptime T: type) type { pub fn MPSCQueue(comptime T: type) type {
return struct { return struct {
const Self = @This();
buffer: std.ArrayList(T), buffer: std.ArrayList(T),
head: Atomic(usize), head: Atomic(usize),
tail: Atomic(usize), tail: Atomic(usize),
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
pub fn init(allocator: std.mem.Allocator) Self { const Self = @This();
pub fn init(allocator: std.mem.Allocator) !Self {
return .{ return .{
.buffer = std.ArrayList(T).init(allocator), .buffer = try std.ArrayList(T).initCapacity(allocator, 0),
.head = Atomic(usize).init(0), .head = Atomic(usize).init(0),
.tail = Atomic(usize).init(0), .tail = Atomic(usize).init(0),
.allocator = allocator, .allocator = allocator,
@ -20,7 +20,7 @@ pub fn MPSCQueue(comptime T: type) type {
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {
self.buffer.deinit(); self.buffer.deinit(self.allocator);
} }
pub fn push(self: *Self, item: T) !void { pub fn push(self: *Self, item: T) !void {
@ -29,7 +29,7 @@ pub fn MPSCQueue(comptime T: type) type {
// Ensure capacity // Ensure capacity
if (tail >= self.buffer.items.len) { if (tail >= self.buffer.items.len) {
const new_capacity = if (self.buffer.items.len == 0) 8 else self.buffer.items.len * 2; 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 // Store item and update tail
@ -67,7 +67,7 @@ pub fn MPSCQueue(comptime T: type) type {
const t = std.testing; const t = std.testing;
test "MPSC Queue basic operations" { test "MPSC Queue basic operations" {
var queue = MPSCQueue(i32).init(t.allocator); var queue = try MPSCQueue(i32).init(t.allocator);
defer queue.deinit(); defer queue.deinit();
try queue.push(1); try queue.push(1);
@ -98,7 +98,7 @@ fn threadTwo(queue: *MPSCQueue(i32)) !void {
test "MPSC Threaded" { test "MPSC Threaded" {
const Thread = std.Thread; const Thread = std.Thread;
var q = MPSCQueue(i32).init(t.allocator); var q = try MPSCQueue(i32).init(t.allocator);
defer q.deinit(); defer q.deinit();
const t1 = try Thread.spawn(.{ .allocator = t.allocator }, threadOne, .{&q}); const t1 = try Thread.spawn(.{ .allocator = t.allocator }, threadOne, .{&q});