Skip to content

Commit 111ce03

Browse files
Peter Murrayclaude
andcommitted
Update for Zig 0.15 API changes
- build.zig: Use createModule/addLibrary instead of deprecated addStaticLibrary - build.zig.zon: Add required fingerprint field - BlowfishWriter.zig: Update ArrayList API (use .empty, pass allocator to methods) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 32deafc commit 111ce03

File tree

3 files changed

+44
-38
lines changed

3 files changed

+44
-38
lines changed

build.zig

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,42 @@ pub fn build(b: *std.Build) void {
2121
.optimize = optimize,
2222
});
2323

24-
const lib = b.addStaticLibrary(.{
25-
.name = "blowfish",
26-
// In this case the main source file is merely a path, however, in more
27-
// complicated build scripts, this could be a generated file.
24+
const lib_mod = b.createModule(.{
2825
.root_source_file = b.path("src/root.zig"),
2926
.target = target,
3027
.optimize = optimize,
3128
});
3229

30+
const lib = b.addLibrary(.{
31+
.linkage = .static,
32+
.name = "blowfish",
33+
.root_module = lib_mod,
34+
});
35+
3336
// This declares intent for the library to be installed into the standard
3437
// location when the user invokes the "install" step (the default step when
3538
// running `zig build`).
3639
b.installArtifact(lib);
3740

38-
const exe = b.addExecutable(.{
39-
.name = "blowfish",
40-
.root_source_file = b.path("src/main.zig"),
41+
const flags = b.dependency("flags", .{
4142
.target = target,
4243
.optimize = optimize,
4344
});
4445

45-
const flags = b.dependency("flags", .{
46+
const exe_mod = b.createModule(.{
47+
.root_source_file = b.path("src/main.zig"),
4648
.target = target,
4749
.optimize = optimize,
50+
.imports = &.{
51+
.{ .name = "flags", .module = flags.module("flags") },
52+
},
53+
});
54+
55+
const exe = b.addExecutable(.{
56+
.name = "blowfish",
57+
.root_module = exe_mod,
4858
});
4959

50-
exe.root_module.addImport("flags", flags.module("flags"));
5160
// This declares intent for the executable to be installed into the
5261
// standard location when the user invokes the "install" step (the default
5362
// step when running `zig build`).
@@ -79,17 +88,13 @@ pub fn build(b: *std.Build) void {
7988
// Creates a step for unit testing. This only builds the test executable
8089
// but does not run it.
8190
const lib_unit_tests = b.addTest(.{
82-
.root_source_file = b.path("src/root.zig"),
83-
.target = target,
84-
.optimize = optimize,
91+
.root_module = lib_mod,
8592
});
8693

8794
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
8895

8996
const exe_unit_tests = b.addTest(.{
90-
.root_source_file = b.path("src/main.zig"),
91-
.target = target,
92-
.optimize = optimize,
97+
.root_module = exe_mod,
9398
});
9499

95100
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

build.zig.zon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.{
2+
.fingerprint = 0x179a4441e94ad6d1,
23
// This is the default name used by packages depending on this one. For
34
// example, when a user runs `zig fetch --save <url>`, this field is used
45
// as the key in the `dependencies` table. Although the user can choose a

src/BlowfishWriter.zig

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ pub fn blowfishWriter(key: []const u8, underlying_stream: anytype) BlowfishWrite
8686

8787
test "writer" {
8888
const alloc = std.testing.allocator;
89-
var buffer = std.ArrayList(u8).init(alloc);
90-
defer buffer.deinit();
91-
var writer = blowfishWriter("TESTKEY", buffer.writer());
89+
var buffer: std.ArrayList(u8) = .empty;
90+
defer buffer.deinit(alloc);
91+
var bfwriter = blowfishWriter("TESTKEY", buffer.writer(alloc));
9292

9393
const unencrypted: [8]u8 = .{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02 };
94-
const wrote = try writer.write(&unencrypted);
95-
try writer.flush();
94+
const wrote = try bfwriter.write(&unencrypted);
95+
try bfwriter.flush();
9696

9797
try std.testing.expectEqual(wrote, 8);
9898
const encrypted: [8]u8 = .{ 0xDF, 0x33, 0x3F, 0xD2, 0x30, 0xA7, 0x1B, 0xB4 };
@@ -101,14 +101,14 @@ test "writer" {
101101

102102
test "weird buffer lengths" {
103103
const alloc = std.testing.allocator;
104-
var buffer = std.ArrayList(u8).init(alloc);
105-
defer buffer.deinit();
106-
var writer = blowfishWriter("TESTKEY", buffer.writer());
104+
var buffer: std.ArrayList(u8) = .empty;
105+
defer buffer.deinit(alloc);
106+
var bfwriter = blowfishWriter("TESTKEY", buffer.writer(alloc));
107107

108108
const unencrypted: [8]u8 = .{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02 };
109-
var wrote = try writer.write(unencrypted[0..3]);
110-
wrote += try writer.write(unencrypted[3..]);
111-
try writer.flush();
109+
var wrote = try bfwriter.write(unencrypted[0..3]);
110+
wrote += try bfwriter.write(unencrypted[3..]);
111+
try bfwriter.flush();
112112

113113
try std.testing.expectEqual(wrote, 8);
114114
const encrypted: [8]u8 = .{ 0xDF, 0x33, 0x3F, 0xD2, 0x30, 0xA7, 0x1B, 0xB4 };
@@ -117,18 +117,18 @@ test "weird buffer lengths" {
117117

118118
test "more weird buffer lengths" {
119119
const alloc = std.testing.allocator;
120-
var buffer = std.ArrayList(u8).init(alloc);
121-
defer buffer.deinit();
122-
var writer = blowfishWriter("TESTKEY", buffer.writer());
120+
var buffer: std.ArrayList(u8) = .empty;
121+
defer buffer.deinit(alloc);
122+
var bfwriter = blowfishWriter("TESTKEY", buffer.writer(alloc));
123123

124124
const unencrypted: [16]u8 = .{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02 };
125-
var wrote = try writer.write(unencrypted[0..3]);
125+
var wrote = try bfwriter.write(unencrypted[0..3]);
126126
try std.testing.expectEqual(0, buffer.items.len);
127-
wrote += try writer.write(unencrypted[3..10]);
127+
wrote += try bfwriter.write(unencrypted[3..10]);
128128
try std.testing.expectEqual(8, buffer.items.len);
129-
wrote += try writer.write(unencrypted[10..]);
129+
wrote += try bfwriter.write(unencrypted[10..]);
130130
try std.testing.expectEqual(16, buffer.items.len);
131-
try writer.flush();
131+
try bfwriter.flush();
132132

133133
try std.testing.expectEqual(wrote, 16);
134134
const encrypted: [16]u8 = .{ 0xDF, 0x33, 0x3F, 0xD2, 0x30, 0xA7, 0x1B, 0xB4, 0xDF, 0x33, 0x3F, 0xD2, 0x30, 0xA7, 0x1B, 0xB4 };
@@ -137,15 +137,15 @@ test "more weird buffer lengths" {
137137

138138
test "padding" {
139139
const alloc = std.testing.allocator;
140-
var buffer = std.ArrayList(u8).init(alloc);
141-
defer buffer.deinit();
142-
var writer = blowfishWriter("TESTKEY", buffer.writer());
140+
var buffer: std.ArrayList(u8) = .empty;
141+
defer buffer.deinit(alloc);
142+
var bfwriter = blowfishWriter("TESTKEY", buffer.writer(alloc));
143143

144144
const unencrypted: [5]u8 = .{ 0x00, 0x00, 0x00, 0x01, 0x00 };
145-
const wrote = try writer.write(&unencrypted);
145+
const wrote = try bfwriter.write(&unencrypted);
146146
try std.testing.expectEqual(wrote, 5);
147147
try std.testing.expectEqual(0, buffer.items.len);
148-
try writer.flush();
148+
try bfwriter.flush();
149149
try std.testing.expectEqual(8, buffer.items.len);
150150

151151
const encrypted: [8]u8 = .{ 0x6c, 0x44, 0xdc, 0xed, 0x6c, 0xa6, 0x34, 0x79 };

0 commit comments

Comments
 (0)