authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-05-09 02:47:50 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-05-09 02:47:50 -07:00
log3dcc531937b58d787e183c25bad535c91bab1f7d
treef1cdef2dae2fc1d9035a019e70f6cb21123a4015
parent0332280cf015fe079b771cd3f29a7408c1f1e71f

upgrade to zig 0.12


13 files changed, 25 insertions(+), 26 deletions(-)

build.zig+2-2
......@@ -1,12 +1,12 @@
11const std = @import("std");
22
3pub fn build(b: *std.build.Builder) void {
3pub fn build(b: *std.Build) void {
44 const target = b.standardTargetOptions(.{});
55 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
66
77 _ = b.addModule(
88 "extras",
9 .{ .source_file = .{ .path = "src/lib.zig" } },
9 .{ .root_source_file = .{ .path = "src/lib.zig" } },
1010 );
1111
1212 const exe_unit_tests = b.addTest(.{
src/BufIndexer.zig+4-4
......@@ -27,20 +27,20 @@ pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type {
2727
2828test {
2929 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
30 const bindex = BufIndexer(u64, .Big).init(&bytes, 1);
30 const bindex = BufIndexer(u64, .big).init(&bytes, 1);
3131 try std.testing.expect(bindex.at(0) == 0x4e5a7da9f3f1d132);
3232}
3333
3434test {
3535 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
36 const bindex = BufIndexer(u32, .Big).init(&bytes, 2);
36 const bindex = BufIndexer(u32, .big).init(&bytes, 2);
3737 try std.testing.expect(bindex.at(0) == 0x4e5a7da9);
3838 try std.testing.expect(bindex.at(1) == 0xf3f1d132);
3939}
4040
4141test {
4242 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
43 const bindex = BufIndexer(u16, .Big).init(&bytes, 4);
43 const bindex = BufIndexer(u16, .big).init(&bytes, 4);
4444 try std.testing.expect(bindex.at(0) == 0x4e5a);
4545 try std.testing.expect(bindex.at(1) == 0x7da9);
4646 try std.testing.expect(bindex.at(2) == 0xf3f1);
......@@ -49,7 +49,7 @@ test {
4949
5050test {
5151 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
52 const bindex = BufIndexer(u8, .Big).init(&bytes, 8);
52 const bindex = BufIndexer(u8, .big).init(&bytes, 8);
5353 try std.testing.expect(bindex.at(0) == 0x4e);
5454 try std.testing.expect(bindex.at(1) == 0x5a);
5555 try std.testing.expect(bindex.at(2) == 0x7d);
src/FieldUnion.zig+1-1
......@@ -15,7 +15,7 @@ pub fn FieldUnion(comptime T: type) type {
1515 };
1616 }
1717 return @Type(std.builtin.Type{ .Union = .{
18 .layout = .Auto,
18 .layout = .auto,
1919 .tag_type = std.meta.FieldEnum(T),
2020 .fields = &fields,
2121 .decls = &.{},
src/Partial.zig+1-1
......@@ -18,7 +18,7 @@ pub fn Partial(comptime T: type) type {
1818 };
1919 }
2020 return @Type(@unionInit(std.builtin.Type, "Struct", .{
21 .layout = .Auto,
21 .layout = .auto,
2222 .backing_integer = null,
2323 .fields = &fields_after,
2424 .decls = &.{},
src/base64DecodeAlloc.zig+1-1
......@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
55pub fn base64DecodeAlloc(alloc: std.mem.Allocator, input: string) !string {
66 const base64 = std.base64.standard.Decoder;
7 var buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input));
7 const buf = try alloc.alloc(u8, try base64.calcSizeForSlice(input));
88 try base64.decode(buf, input);
99 return buf;
1010}
src/base64EncodeAlloc.zig+1-1
......@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
55pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {
66 const base64 = std.base64.standard.Encoder;
7 var buf = try alloc.alloc(u8, base64.calcSize(input.len));
7 const buf = try alloc.alloc(u8, base64.calcSize(input.len));
88 return base64.encode(buf, input);
99}
1010
src/dirSize.zig+2-2
......@@ -3,14 +3,14 @@ const string = []const u8;
33const extras = @import("./lib.zig");
44const fileSize = extras.fileSize;
55
6pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.IterableDir) !u64 {
6pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !u64 {
77 var res: u64 = 0;
88
99 var walk = try dir.walk(alloc);
1010 defer walk.deinit();
1111 while (try walk.next()) |entry| {
1212 if (entry.kind != .file) continue;
13 res += try fileSize(dir.dir, entry.path);
13 res += try fileSize(dir, entry.path);
1414 }
1515 return res;
1616}
src/fileList.zig+1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const extras = @import("./lib.zig");
44
5pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.IterableDir) ![]string {
5pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string {
66 var list = std.ArrayList(string).init(alloc);
77 defer list.deinit();
88
src/indexBufferT.zig+4-4
......@@ -14,11 +14,11 @@ pub fn indexBufferT(bytes: [*]const u8, comptime T: type, endian: std.builtin.En
1414
1515test {
1616 const bytes = rawIntBytes(u32, 0x4e5a7da9);
17 try std.testing.expect(indexBufferT(&bytes, u16, .Big, 0, 2) == 0x4e5a);
18 try std.testing.expect(indexBufferT(&bytes, u16, .Big, 1, 2) == 0x7da9);
17 try std.testing.expect(indexBufferT(&bytes, u16, .big, 0, 2) == 0x4e5a);
18 try std.testing.expect(indexBufferT(&bytes, u16, .big, 1, 2) == 0x7da9);
1919}
2020test {
2121 const bytes = rawIntBytes(u32, 0x4e5a7da9);
22 try std.testing.expect(indexBufferT(&bytes, u16, .Little, 0, 2) == 0x5a4e);
23 try std.testing.expect(indexBufferT(&bytes, u16, .Little, 1, 2) == 0xa97d);
22 try std.testing.expect(indexBufferT(&bytes, u16, .little, 0, 2) == 0x5a4e);
23 try std.testing.expect(indexBufferT(&bytes, u16, .little, 1, 2) == 0xa97d);
2424}
src/isArrayOf.zig+1-1
......@@ -2,7 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const extras = @import("./lib.zig");
44
5pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {
5pub fn isArrayOf(comptime T: type) fn (type) bool {
66 const Closure = struct {
77 pub fn trait(comptime C: type) bool {
88 return switch (@typeInfo(C)) {
src/lessThanSlice.zig-1
......@@ -3,7 +3,6 @@ const string = []const u8;
33const extras = @import("./lib.zig");
44
55pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool {
6 comptime std.debug.assert(std.meta.trait.isSlice(T));
76 return struct {
87 fn f(_: void, lhs: T, rhs: T) bool {
98 const result = for (0..@min(lhs.len, rhs.len)) |i| {
src/rawInt.zig+2-2
......@@ -7,8 +7,8 @@ const native_endian = builtin.target.cpu.arch.endian();
77pub fn rawInt(comptime T: type, comptime literal: comptime_int) T {
88 comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0);
99 return switch (native_endian) {
10 .Little => @byteSwap(@as(T, literal)),
11 .Big => @compileError("unreachable"),
10 .little => @byteSwap(@as(T, literal)),
11 .big => @compileError("unreachable"),
1212 };
1313}
1414
src/readType.zig+5-5
......@@ -10,14 +10,14 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
1010 return switch (@typeInfo(T)) {
1111 .Struct => |t| {
1212 switch (t.layout) {
13 .Auto, .Extern => {
13 .auto, .@"extern" => {
1414 var s: T = undefined;
1515 inline for (std.meta.fields(T)) |field| {
1616 @field(s, field.name) = try readType(reader, field.type, endian);
1717 }
1818 return s;
1919 },
20 .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
20 .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
2121 }
2222 },
2323 .Array => |t| {
......@@ -63,7 +63,7 @@ test {
6363 b: u8,
6464 c: u8,
6565 };
66 const s = try readType(fba.reader(), S, .Big);
66 const s = try readType(fba.reader(), S, .big);
6767 try std.testing.expect(s.a == 0x4e5a);
6868 try std.testing.expect(s.b == 0x7d);
6969 try std.testing.expect(s.c == 0xa9);
......@@ -73,7 +73,7 @@ test {
7373 const bytes = rawIntBytes(u32, 0x4e5a7da9);
7474 var fba = std.io.fixedBufferStream(&bytes);
7575 const A = [2]u16;
76 const a = try readType(fba.reader(), A, .Big);
76 const a = try readType(fba.reader(), A, .big);
7777 try std.testing.expect(a[0] == 0x4e5a);
7878 try std.testing.expect(a[1] == 0x7da9);
7979}
......@@ -87,7 +87,7 @@ test {
8787 c: u4,
8888 d: u8,
8989 };
90 const s = try readType(fba.reader(), S, .Big);
90 const s = try readType(fba.reader(), S, .big);
9191 try std.testing.expect(s.a == 0x7da9);
9292 try std.testing.expect(s.b == 0xa);
9393 try std.testing.expect(s.c == 0x5);