Skip to content

Commit 56a58e1

Browse files
committed
chore(zig): migrate to Zig 0.15.2
Update from Zig 0.14.0 to support latest stable release. - build.zig.zon: use enum literal syntax for package name - build.zig: adopt new root_module API with createModule() - format(): update to new single-writer signature - hex formatting: replace fmtSliceHexLower() with {x} specifier - ArrayList: switch to AlignedManaged for explicit memory management - ci: update workflow to Zig 0.15.2
1 parent 5203ccf commit 56a58e1

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup Zig
1717
uses: mlugg/setup-zig@v1
1818
with:
19-
version: "0.14.0"
19+
version: "0.15.2"
2020

2121
- name: Check formatting
2222
run: zig fmt --check .

build.zig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ pub fn build(b: *std.Build) void {
88

99
const test_step = b.step("test", "Run library tests");
1010
const tests = b.addTest(.{
11-
.root_source_file = b.path("src/typeid.zig"),
12-
.target = target,
13-
.optimize = optimize,
11+
.root_module = b.createModule(.{
12+
.root_source_file = b.path("src/typeid.zig"),
13+
.target = target,
14+
.optimize = optimize,
15+
}),
1416
});
1517
const run_tests = b.addRunArtifact(tests);
1618
test_step.dependOn(&run_tests.step);
1719

1820
// Benchmark for UUID generation (demonstrates per-generator mutex performance)
1921
const bench_uuid = b.addExecutable(.{
2022
.name = "bench_uuid_contention",
21-
.root_source_file = b.path("src/bench_uuid_contention.zig"),
22-
.target = target,
23-
.optimize = optimize,
23+
.root_module = b.createModule(.{
24+
.root_source_file = b.path("src/bench_uuid_contention.zig"),
25+
.target = target,
26+
.optimize = optimize,
27+
}),
2428
});
2529
const bench_uuid_step = b.step("bench-uuid", "Run UUID generation benchmark");
2630
const run_bench_uuid = b.addRunArtifact(bench_uuid);

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.{
2-
.name = "typeid",
2+
.name = .typeid,
33
.version = "0.2.1",
44
.fingerprint = 0xe70b032c62449aa,
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.15.2",
66
.paths = .{
77
"src",
88
"build.zig",

src/typeid.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ pub const TypeID = struct {
238238
/// Provides debug formatting for TypeID
239239
pub fn format(
240240
self: Self,
241-
comptime _: []const u8,
242-
_: std.fmt.FormatOptions,
243241
writer: anytype,
244242
) !void {
245243
if (self.prefix_len > 0) {
@@ -433,7 +431,7 @@ test "String formatting" {
433431

434432
var buf: [100]u8 = undefined;
435433
var fbs = std.io.fixedBufferStream(&buf);
436-
try std.fmt.format(fbs.writer(), "TypeID: {s}", .{tid});
434+
try std.fmt.format(fbs.writer(), "TypeID: {f}", .{tid});
437435

438436
var expected_buf: StringBuf = undefined;
439437
const expected = tid.toString(&expected_buf);

src/uuid/uuid.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ pub fn initSecure() Generator {
8686
}
8787

8888
/// Convert UUID to canonical string format with hyphens (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
89-
pub fn format(uuid: Uuid, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) (@TypeOf(writer).Error)!void {
89+
pub fn format(uuid: Uuid, writer: anytype) (@TypeOf(writer).Error)!void {
9090
var bytes: [16]u8 = undefined;
9191
std.mem.writeInt(u128, &bytes, uuid, .big);
9292

93-
try std.fmt.format(writer, "{}-{}-{}-{}-{}", .{
94-
std.fmt.fmtSliceHexLower(bytes[0..4]),
95-
std.fmt.fmtSliceHexLower(bytes[4..6]),
96-
std.fmt.fmtSliceHexLower(bytes[6..8]),
97-
std.fmt.fmtSliceHexLower(bytes[8..10]),
98-
std.fmt.fmtSliceHexLower(bytes[10..16]),
93+
try std.fmt.format(writer, "{x}-{x}-{x}-{x}-{x}", .{
94+
bytes[0..4].*,
95+
bytes[4..6].*,
96+
bytes[6..8].*,
97+
bytes[8..10].*,
98+
bytes[10..16].*,
9999
});
100100
}
101101

102102
/// Convert UUID to string using a fixed buffer
103103
pub fn toString(uuid: Uuid, buf: *[36]u8) []const u8 {
104104
var fbs = std.io.fixedBufferStream(buf);
105-
format(uuid, "", .{}, fbs.writer()) catch unreachable;
105+
format(uuid, fbs.writer()) catch unreachable;
106106
return fbs.getWritten();
107107
}
108108

@@ -224,7 +224,7 @@ test "collision safety - multiple generators produce different UUIDs" {
224224
test "collision safety - multi-threaded generation" {
225225
const ThreadContext = struct {
226226
gen: Generator,
227-
ids: std.ArrayList(Uuid),
227+
ids: std.array_list.AlignedManaged(Uuid, null),
228228

229229
fn worker(ctx: *@This()) !void {
230230
for (0..1000) |_| {
@@ -242,7 +242,7 @@ test "collision safety - multi-threaded generation" {
242242
for (0..num_threads) |i| {
243243
contexts[i] = .{
244244
.gen = initSecure(),
245-
.ids = std.ArrayList(Uuid).init(std.testing.allocator),
245+
.ids = std.array_list.AlignedManaged(Uuid, null).init(std.testing.allocator),
246246
};
247247
}
248248
defer {

0 commit comments

Comments
 (0)