From 0c65fe8122d7703ebafe30da0c680982a425b66e Mon Sep 17 00:00:00 2001 From: Tomasz Lisowski Date: Mon, 3 Apr 2023 18:39:08 +0200 Subject: [PATCH 1/2] Port to zig 0.11.0-dev.2317+46b2f1f70 --- build.zig | 21 ++++++++++++++++----- src/base32.zig | 6 +++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index 5b19c72..8f13706 100644 --- a/build.zig +++ b/build.zig @@ -1,16 +1,27 @@ const std = @import("std"); pub fn build(b: *std.build.Builder) void { - const mode = b.standardReleaseOptions(); + const optimize = b.standardOptimizeOption(.{}); + const target = b.standardTargetOptions(.{}); - const lib = b.addStaticLibrary("base32", "src/base32.zig"); - lib.setBuildMode(mode); + const lib = b.addStaticLibrary( + .{ + .name = "base32", + .root_source_file = .{ .path = "src/base32.zig" }, + .target = target, + .optimize = optimize, + }, + ); lib.install(); const coverage = b.option(bool, "coverage", "Generate test coverage") orelse false; - var main_tests = b.addTest("src/base32.zig"); - main_tests.setBuildMode(mode); + var main_tests = b.addTest( + .{ + .root_source_file = .{ .path = "src/base32.zig" }, + .optimize = optimize, + }, + ); if (coverage) { main_tests.setExecCmd(&[_]?[]const u8{ diff --git a/src/base32.zig b/src/base32.zig index 0e3db37..8b9df12 100644 --- a/src/base32.zig +++ b/src/base32.zig @@ -33,7 +33,7 @@ pub const Encoding = struct { }, .decode_map = blk: { var a = [_]u8{0xFF} ** 256; - for (encoder_string) |c, i| { + for (encoder_string, 0..) |c, i| { a[@intCast(usize, c)] = @intCast(u8, i); } break :blk a; @@ -203,7 +203,7 @@ pub const Encoding = struct { if (dbuf[j] == 0xFF) { const pos = olen - src.len - 1; log.warn("{} {}\n", .{ in, self.decode_map[in] }); - for (self.decode_map) |m, idx| { + for (self.decode_map, 0..) |m, idx| { log.warn("== {} ={x}\n", .{ idx, m }); } log.warn("incorrenct input at {}\n", .{pos}); @@ -367,4 +367,4 @@ test "Decoding no padding" { var result = try std_encoding_no_padding.decode(buf[0..size], encoded_no_pad); try testing.expectEqualSlices(u8, ts.decoded, result); } -} \ No newline at end of file +} From 4e545417cba02bfe4682161fda856ed1f65eb593 Mon Sep 17 00:00:00 2001 From: Tomasz Lisowski Date: Mon, 3 Apr 2023 23:23:00 +0200 Subject: [PATCH 2/2] Make sure that tests run when building the `test` target --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 8f13706..919148a 100644 --- a/build.zig +++ b/build.zig @@ -34,5 +34,5 @@ pub fn build(b: *std.build.Builder) void { } const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&main_tests.run().step); }