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 @@...@@ -1,12 +1,12 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn build(b: *std.build.Builder) void {3pub fn build(b: *std.Build) void {
4 const target = b.standardTargetOptions(.{});4 const target = b.standardTargetOptions(.{});
5 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;5 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
66
7 _ = b.addModule(7 _ = b.addModule(
8 "extras",8 "extras",
9 .{ .source_file = .{ .path = "src/lib.zig" } },9 .{ .root_source_file = .{ .path = "src/lib.zig" } },
10 );10 );
1111
12 const exe_unit_tests = b.addTest(.{12 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 {...@@ -27,20 +27,20 @@ pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type {
2727
28test {28test {
29 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);29 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
30 const bindex = BufIndexer(u64, .Big).init(&bytes, 1);30 const bindex = BufIndexer(u64, .big).init(&bytes, 1);
31 try std.testing.expect(bindex.at(0) == 0x4e5a7da9f3f1d132);31 try std.testing.expect(bindex.at(0) == 0x4e5a7da9f3f1d132);
32}32}
3333
34test {34test {
35 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);35 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
36 const bindex = BufIndexer(u32, .Big).init(&bytes, 2);36 const bindex = BufIndexer(u32, .big).init(&bytes, 2);
37 try std.testing.expect(bindex.at(0) == 0x4e5a7da9);37 try std.testing.expect(bindex.at(0) == 0x4e5a7da9);
38 try std.testing.expect(bindex.at(1) == 0xf3f1d132);38 try std.testing.expect(bindex.at(1) == 0xf3f1d132);
39}39}
4040
41test {41test {
42 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);42 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
43 const bindex = BufIndexer(u16, .Big).init(&bytes, 4);43 const bindex = BufIndexer(u16, .big).init(&bytes, 4);
44 try std.testing.expect(bindex.at(0) == 0x4e5a);44 try std.testing.expect(bindex.at(0) == 0x4e5a);
45 try std.testing.expect(bindex.at(1) == 0x7da9);45 try std.testing.expect(bindex.at(1) == 0x7da9);
46 try std.testing.expect(bindex.at(2) == 0xf3f1);46 try std.testing.expect(bindex.at(2) == 0xf3f1);
...@@ -49,7 +49,7 @@ test {...@@ -49,7 +49,7 @@ test {
4949
50test {50test {
51 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);51 const bytes = rawIntBytes(u64, 0x4e5a7da9f3f1d132);
52 const bindex = BufIndexer(u8, .Big).init(&bytes, 8);52 const bindex = BufIndexer(u8, .big).init(&bytes, 8);
53 try std.testing.expect(bindex.at(0) == 0x4e);53 try std.testing.expect(bindex.at(0) == 0x4e);
54 try std.testing.expect(bindex.at(1) == 0x5a);54 try std.testing.expect(bindex.at(1) == 0x5a);
55 try std.testing.expect(bindex.at(2) == 0x7d);55 try std.testing.expect(bindex.at(2) == 0x7d);
src/FieldUnion.zig+1-1
...@@ -15,7 +15,7 @@ pub fn FieldUnion(comptime T: type) type {...@@ -15,7 +15,7 @@ pub fn FieldUnion(comptime T: type) type {
15 };15 };
16 }16 }
17 return @Type(std.builtin.Type{ .Union = .{17 return @Type(std.builtin.Type{ .Union = .{
18 .layout = .Auto,18 .layout = .auto,
19 .tag_type = std.meta.FieldEnum(T),19 .tag_type = std.meta.FieldEnum(T),
20 .fields = &fields,20 .fields = &fields,
21 .decls = &.{},21 .decls = &.{},
src/Partial.zig+1-1
...@@ -18,7 +18,7 @@ pub fn Partial(comptime T: type) type {...@@ -18,7 +18,7 @@ pub fn Partial(comptime T: type) type {
18 };18 };
19 }19 }
20 return @Type(@unionInit(std.builtin.Type, "Struct", .{20 return @Type(@unionInit(std.builtin.Type, "Struct", .{
21 .layout = .Auto,21 .layout = .auto,
22 .backing_integer = null,22 .backing_integer = null,
23 .fields = &fields_after,23 .fields = &fields_after,
24 .decls = &.{},24 .decls = &.{},
src/base64DecodeAlloc.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5pub fn base64DecodeAlloc(alloc: std.mem.Allocator, input: string) !string {5pub fn base64DecodeAlloc(alloc: std.mem.Allocator, input: string) !string {
6 const base64 = std.base64.standard.Decoder;6 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));
8 try base64.decode(buf, input);8 try base64.decode(buf, input);
9 return buf;9 return buf;
10}10}
src/base64EncodeAlloc.zig+1-1
...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");...@@ -4,7 +4,7 @@ const extras = @import("./lib.zig");
44
5pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {5pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string {
6 const base64 = std.base64.standard.Encoder;6 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));
8 return base64.encode(buf, input);8 return base64.encode(buf, input);
9}9}
1010
src/dirSize.zig+2-2
...@@ -3,14 +3,14 @@ const string = []const u8;...@@ -3,14 +3,14 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
4const fileSize = extras.fileSize;4const 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 {
7 var res: u64 = 0;7 var res: u64 = 0;
88
9 var walk = try dir.walk(alloc);9 var walk = try dir.walk(alloc);
10 defer walk.deinit();10 defer walk.deinit();
11 while (try walk.next()) |entry| {11 while (try walk.next()) |entry| {
12 if (entry.kind != .file) continue;12 if (entry.kind != .file) continue;
13 res += try fileSize(dir.dir, entry.path);13 res += try fileSize(dir, entry.path);
14 }14 }
15 return res;15 return res;
16}16}
src/fileList.zig+1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("./lib.zig");3const 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 {
6 var list = std.ArrayList(string).init(alloc);6 var list = std.ArrayList(string).init(alloc);
7 defer list.deinit();7 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...@@ -14,11 +14,11 @@ pub fn indexBufferT(bytes: [*]const u8, comptime T: type, endian: std.builtin.En
1414
15test {15test {
16 const bytes = rawIntBytes(u32, 0x4e5a7da9);16 const bytes = rawIntBytes(u32, 0x4e5a7da9);
17 try std.testing.expect(indexBufferT(&bytes, u16, .Big, 0, 2) == 0x4e5a);17 try std.testing.expect(indexBufferT(&bytes, u16, .big, 0, 2) == 0x4e5a);
18 try std.testing.expect(indexBufferT(&bytes, u16, .Big, 1, 2) == 0x7da9);18 try std.testing.expect(indexBufferT(&bytes, u16, .big, 1, 2) == 0x7da9);
19}19}
20test {20test {
21 const bytes = rawIntBytes(u32, 0x4e5a7da9);21 const bytes = rawIntBytes(u32, 0x4e5a7da9);
22 try std.testing.expect(indexBufferT(&bytes, u16, .Little, 0, 2) == 0x5a4e);22 try std.testing.expect(indexBufferT(&bytes, u16, .little, 0, 2) == 0x5a4e);
23 try std.testing.expect(indexBufferT(&bytes, u16, .Little, 1, 2) == 0xa97d);23 try std.testing.expect(indexBufferT(&bytes, u16, .little, 1, 2) == 0xa97d);
24}24}
src/isArrayOf.zig+1-1
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {5pub fn isArrayOf(comptime T: type) fn (type) bool {
6 const Closure = struct {6 const Closure = struct {
7 pub fn trait(comptime C: type) bool {7 pub fn trait(comptime C: type) bool {
8 return switch (@typeInfo(C)) {8 return switch (@typeInfo(C)) {
src/lessThanSlice.zig-1
...@@ -3,7 +3,6 @@ const string = []const u8;...@@ -3,7 +3,6 @@ const string = []const u8;
3const extras = @import("./lib.zig");3const extras = @import("./lib.zig");
44
5pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool {5pub fn lessThanSlice(comptime T: type) fn (void, T, T) bool {
6 comptime std.debug.assert(std.meta.trait.isSlice(T));
7 return struct {6 return struct {
8 fn f(_: void, lhs: T, rhs: T) bool {7 fn f(_: void, lhs: T, rhs: T) bool {
9 const result = for (0..@min(lhs.len, rhs.len)) |i| {8 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();...@@ -7,8 +7,8 @@ const native_endian = builtin.target.cpu.arch.endian();
7pub fn rawInt(comptime T: type, comptime literal: comptime_int) T {7pub fn rawInt(comptime T: type, comptime literal: comptime_int) T {
8 comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0);8 comptime std.debug.assert(@typeInfo(T).Int.bits % 8 == 0);
9 return switch (native_endian) {9 return switch (native_endian) {
10 .Little => @byteSwap(@as(T, literal)),10 .little => @byteSwap(@as(T, literal)),
11 .Big => @compileError("unreachable"),11 .big => @compileError("unreachable"),
12 };12 };
13}13}
1414
src/readType.zig+5-5
...@@ -10,14 +10,14 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !...@@ -10,14 +10,14 @@ pub fn readType(reader: anytype, comptime T: type, endian: std.builtin.Endian) !
10 return switch (@typeInfo(T)) {10 return switch (@typeInfo(T)) {
11 .Struct => |t| {11 .Struct => |t| {
12 switch (t.layout) {12 switch (t.layout) {
13 .Auto, .Extern => {13 .auto, .@"extern" => {
14 var s: T = undefined;14 var s: T = undefined;
15 inline for (std.meta.fields(T)) |field| {15 inline for (std.meta.fields(T)) |field| {
16 @field(s, field.name) = try readType(reader, field.type, endian);16 @field(s, field.name) = try readType(reader, field.type, endian);
17 }17 }
18 return s;18 return s;
19 },19 },
20 .Packed => return @bitCast(try readType(reader, t.backing_integer.?, endian)),20 .@"packed" => return @bitCast(try readType(reader, t.backing_integer.?, endian)),
21 }21 }
22 },22 },
23 .Array => |t| {23 .Array => |t| {
...@@ -63,7 +63,7 @@ test {...@@ -63,7 +63,7 @@ test {
63 b: u8,63 b: u8,
64 c: u8,64 c: u8,
65 };65 };
66 const s = try readType(fba.reader(), S, .Big);66 const s = try readType(fba.reader(), S, .big);
67 try std.testing.expect(s.a == 0x4e5a);67 try std.testing.expect(s.a == 0x4e5a);
68 try std.testing.expect(s.b == 0x7d);68 try std.testing.expect(s.b == 0x7d);
69 try std.testing.expect(s.c == 0xa9);69 try std.testing.expect(s.c == 0xa9);
...@@ -73,7 +73,7 @@ test {...@@ -73,7 +73,7 @@ test {
73 const bytes = rawIntBytes(u32, 0x4e5a7da9);73 const bytes = rawIntBytes(u32, 0x4e5a7da9);
74 var fba = std.io.fixedBufferStream(&bytes);74 var fba = std.io.fixedBufferStream(&bytes);
75 const A = [2]u16;75 const A = [2]u16;
76 const a = try readType(fba.reader(), A, .Big);76 const a = try readType(fba.reader(), A, .big);
77 try std.testing.expect(a[0] == 0x4e5a);77 try std.testing.expect(a[0] == 0x4e5a);
78 try std.testing.expect(a[1] == 0x7da9);78 try std.testing.expect(a[1] == 0x7da9);
79}79}
...@@ -87,7 +87,7 @@ test {...@@ -87,7 +87,7 @@ test {
87 c: u4,87 c: u4,
88 d: u8,88 d: u8,
89 };89 };
90 const s = try readType(fba.reader(), S, .Big);90 const s = try readType(fba.reader(), S, .big);
91 try std.testing.expect(s.a == 0x7da9);91 try std.testing.expect(s.a == 0x7da9);
92 try std.testing.expect(s.b == 0xa);92 try std.testing.expect(s.b == 0xa);
93 try std.testing.expect(s.c == 0x5);93 try std.testing.expect(s.c == 0x5);