Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to zig 0.11.0-dev.2317+46b2f1f70 #6

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -23,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);
}
6 changes: 3 additions & 3 deletions src/base32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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});
Expand Down Expand Up @@ -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);
}
}
}