Skip to content

Commit d8990bd

Browse files
chrisbbreuerclaude
andcommitted
fix: use Zig 0.15.1 APIs for compatibility with pantry
Rewrite main.zig to use std.process.argsWithAllocator, std.fs.cwd(), std.process.Child.run instead of Zig 0.16 std.process.Init/std.Io APIs. Fix formatting in files.zig and test_version.zig. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2610610 commit d8990bd

3 files changed

Lines changed: 54 additions & 45 deletions

File tree

src/files.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const FileType = enum {
3838

3939
pub fn isTomlFile(self: FileType) bool {
4040
return self == .cargo_toml or self == .pyproject_toml or
41-
self == .ion_toml or self == .generic_toml;
41+
self == .ion_toml or self == .generic_toml;
4242
}
4343
};
4444

src/main.zig

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ fn exitCode(term: std.process.Child.Term) u8 {
2727
};
2828
}
2929

30-
pub fn main(init: std.process.Init) !void {
31-
const allocator = init.gpa;
32-
const io = init.io;
30+
pub fn main() !void {
31+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
32+
defer _ = gpa.deinit();
33+
const allocator = gpa.allocator();
3334

3435
var config = Config{};
3536
var release_type: ?[]const u8 = null;
3637

37-
// Parse command line args via std.process.Init
38-
var args = init.minimal.args.iterate();
38+
// Parse command line args
39+
var args = try std.process.argsWithAllocator(allocator);
40+
defer args.deinit();
3941
_ = args.skip(); // Skip program name
4042

4143
while (args.next()) |arg| {
@@ -90,7 +92,7 @@ pub fn main(init: std.process.Init) !void {
9092

9193
// If no release type provided, show interactive prompt
9294
const rel_type_owned = if (release_type == null) blk: {
93-
const content_peek = std.Io.Dir.cwd().readFileAlloc(io, "build.zig.zon", allocator, std.Io.Limit.limited(1024 * 1024)) catch {
95+
const content_peek = std.fs.cwd().readFileAlloc(allocator, "build.zig.zon", 1024 * 1024) catch {
9496
try printHelp();
9597
return;
9698
};
@@ -102,14 +104,14 @@ pub fn main(init: std.process.Init) !void {
102104
};
103105
defer allocator.free(current_ver);
104106

105-
break :blk try promptForVersion(allocator, io, current_ver);
107+
break :blk try promptForVersion(allocator, current_ver);
106108
} else null;
107109
defer if (rel_type_owned) |owned| allocator.free(owned);
108110

109111
const rel_type = rel_type_owned orelse release_type.?;
110112

111113
// Read build.zig.zon
112-
const content = try std.Io.Dir.cwd().readFileAlloc(io, "build.zig.zon", allocator, std.Io.Limit.limited(1024 * 1024));
114+
const content = try std.fs.cwd().readFileAlloc(allocator, "build.zig.zon", 1024 * 1024);
113115
defer allocator.free(content);
114116

115117
// Find current version
@@ -154,27 +156,27 @@ pub fn main(init: std.process.Init) !void {
154156
const new_content = try std.mem.replaceOwned(u8, allocator, content, old_needle, new_needle);
155157
defer allocator.free(new_content);
156158

157-
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = "build.zig.zon", .data = new_content });
159+
try std.fs.cwd().writeFile(.{ .sub_path = "build.zig.zon", .data = new_content });
158160

159161
// Git operations
160162
if (config.commit or config.tag or config.push) {
161-
if (!isGitRepository(allocator, io)) {
163+
if (!isGitRepository(allocator)) {
162164
std.debug.print("\nWarning: Not a git repository, skipping git operations\n", .{});
163165
} else {
164166
if (config.changelog) {
165167
std.debug.print("Generating changelog...\n", .{});
166-
generateChangelog(allocator, io, new_version) catch |err| {
168+
generateChangelog(allocator, new_version) catch |err| {
167169
std.debug.print("Warning: Failed to generate changelog: {any}\n", .{err});
168170
};
169171
}
170172

171-
try gitAdd(allocator, io, "build.zig.zon");
173+
try gitAdd(allocator, "build.zig.zon");
172174

173175
if (config.commit) {
174176
const commit_msg = try formatCommitMessage(allocator, new_version);
175177
defer allocator.free(commit_msg);
176178

177-
try gitCommit(allocator, io, commit_msg, config.sign, config.no_verify);
179+
try gitCommit(allocator, commit_msg, config.sign, config.no_verify);
178180
std.debug.print("Created git commit\n", .{});
179181
}
180182

@@ -185,15 +187,15 @@ pub fn main(init: std.process.Init) !void {
185187
const tag_msg = config.tag_message orelse try std.fmt.allocPrint(allocator, "Release {s}", .{tag_name});
186188
defer if (config.tag_message == null) allocator.free(tag_msg);
187189

188-
try gitTag(allocator, io, tag_name, tag_msg, config.sign);
190+
try gitTag(allocator, tag_name, tag_msg, config.sign);
189191
std.debug.print("Created git tag: {s}\n", .{tag_name});
190192
}
191193

192194
if (config.push) {
193-
if (!hasGitRemote(allocator, io)) {
195+
if (!hasGitRemote(allocator)) {
194196
std.debug.print("Warning: No git remote configured, skipping push\n", .{});
195197
} else {
196-
try gitPush(allocator, io, config.tag);
198+
try gitPush(allocator, config.tag);
197199
std.debug.print("Pushed to remote\n", .{});
198200
}
199201
}
@@ -240,8 +242,9 @@ fn bumpVersion(allocator: std.mem.Allocator, version: []const u8, release_type:
240242
}
241243

242244
// Changelog generation functions
243-
fn getCommitsSinceLastTag(allocator: std.mem.Allocator, io: std.Io) ![][]u8 {
244-
const result = try std.process.run(allocator, io, .{
245+
fn getCommitsSinceLastTag(allocator: std.mem.Allocator) ![][]u8 {
246+
const result = try std.process.Child.run(.{
247+
.allocator = allocator,
245248
.argv = &[_][]const u8{ "git", "describe", "--tags", "--abbrev=0" },
246249
});
247250

@@ -268,7 +271,8 @@ fn getCommitsSinceLastTag(allocator: std.mem.Allocator, io: std.Io) ![][]u8 {
268271
commits_argv[4] = "HEAD";
269272
}
270273

271-
const commits_result = try std.process.run(allocator, io, .{
274+
const commits_result = try std.process.Child.run(.{
275+
.allocator = allocator,
272276
.argv = commits_argv[0..5],
273277
});
274278

@@ -298,8 +302,8 @@ fn getCommitsSinceLastTag(allocator: std.mem.Allocator, io: std.Io) ![][]u8 {
298302
return try commits.toOwnedSlice(allocator);
299303
}
300304

301-
fn generateChangelog(allocator: std.mem.Allocator, io: std.Io, version: []const u8) !void {
302-
const commits = try getCommitsSinceLastTag(allocator, io);
305+
fn generateChangelog(allocator: std.mem.Allocator, version: []const u8) !void {
306+
const commits = try getCommitsSinceLastTag(allocator);
303307
defer {
304308
for (commits) |commit| {
305309
allocator.free(commit);
@@ -313,7 +317,7 @@ fn generateChangelog(allocator: std.mem.Allocator, io: std.Io, version: []const
313317
}
314318

315319
const changelog_path = "CHANGELOG.md";
316-
const existing_content = std.Io.Dir.cwd().readFileAlloc(io, changelog_path, allocator, std.Io.Limit.limited(1024 * 1024 * 10)) catch |err| blk: {
320+
const existing_content = std.fs.cwd().readFileAlloc(allocator, changelog_path, 1024 * 1024 * 10) catch |err| blk: {
317321
if (err == error.FileNotFound) {
318322
break :blk try allocator.dupe(u8, "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\n");
319323
}
@@ -367,16 +371,17 @@ fn generateChangelog(allocator: std.mem.Allocator, io: std.Io, version: []const
367371
);
368372
defer allocator.free(final_content);
369373

370-
const file = try std.Io.Dir.cwd().createFile(io, changelog_path, .{});
371-
defer file.close(io);
372-
try file.writeStreamingAll(io, final_content);
374+
const file = try std.fs.cwd().createFile(changelog_path, .{});
375+
defer file.close();
376+
try file.writeAll(final_content);
373377

374378
std.debug.print("Generated changelog with {d} commit(s)\n", .{commits.len});
375379
}
376380

377381
// Git helper functions
378-
fn isGitRepository(allocator: std.mem.Allocator, io: std.Io) bool {
379-
const result = std.process.run(allocator, io, .{
382+
fn isGitRepository(allocator: std.mem.Allocator) bool {
383+
const result = std.process.Child.run(.{
384+
.allocator = allocator,
380385
.argv = &[_][]const u8{ "git", "rev-parse", "--git-dir" },
381386
}) catch return false;
382387

@@ -386,8 +391,9 @@ fn isGitRepository(allocator: std.mem.Allocator, io: std.Io) bool {
386391
return exitedSuccessfully(result.term);
387392
}
388393

389-
fn hasGitRemote(allocator: std.mem.Allocator, io: std.Io) bool {
390-
const result = std.process.run(allocator, io, .{
394+
fn hasGitRemote(allocator: std.mem.Allocator) bool {
395+
const result = std.process.Child.run(.{
396+
.allocator = allocator,
391397
.argv = &[_][]const u8{ "git", "remote" },
392398
}) catch return false;
393399

@@ -397,8 +403,9 @@ fn hasGitRemote(allocator: std.mem.Allocator, io: std.Io) bool {
397403
return exitedSuccessfully(result.term) and result.stdout.len > 0;
398404
}
399405

400-
fn gitAdd(allocator: std.mem.Allocator, io: std.Io, file_path: []const u8) !void {
401-
const result = try std.process.run(allocator, io, .{
406+
fn gitAdd(allocator: std.mem.Allocator, file_path: []const u8) !void {
407+
const result = try std.process.Child.run(.{
408+
.allocator = allocator,
402409
.argv = &[_][]const u8{ "git", "add", file_path },
403410
});
404411

@@ -411,7 +418,7 @@ fn gitAdd(allocator: std.mem.Allocator, io: std.Io, file_path: []const u8) !void
411418
}
412419
}
413420

414-
fn gitCommit(allocator: std.mem.Allocator, io: std.Io, message: []const u8, sign: bool, no_verify: bool) !void {
421+
fn gitCommit(allocator: std.mem.Allocator, message: []const u8, sign: bool, no_verify: bool) !void {
415422
var argv_list = std.ArrayList([]const u8){};
416423
defer argv_list.deinit(allocator);
417424

@@ -423,7 +430,8 @@ fn gitCommit(allocator: std.mem.Allocator, io: std.Io, message: []const u8, sign
423430
if (sign) try argv_list.append(allocator, "--signoff");
424431
if (no_verify) try argv_list.append(allocator, "--no-verify");
425432

426-
const result = try std.process.run(allocator, io, .{
433+
const result = try std.process.Child.run(.{
434+
.allocator = allocator,
427435
.argv = argv_list.items,
428436
});
429437

@@ -436,7 +444,7 @@ fn gitCommit(allocator: std.mem.Allocator, io: std.Io, message: []const u8, sign
436444
}
437445
}
438446

439-
fn gitTag(allocator: std.mem.Allocator, io: std.Io, tag_name: []const u8, message: []const u8, sign: bool) !void {
447+
fn gitTag(allocator: std.mem.Allocator, tag_name: []const u8, message: []const u8, sign: bool) !void {
440448
var argv_list = std.ArrayList([]const u8){};
441449
defer argv_list.deinit(allocator);
442450

@@ -449,7 +457,8 @@ fn gitTag(allocator: std.mem.Allocator, io: std.Io, tag_name: []const u8, messag
449457

450458
if (sign) try argv_list.append(allocator, "--sign");
451459

452-
const result = try std.process.run(allocator, io, .{
460+
const result = try std.process.Child.run(.{
461+
.allocator = allocator,
453462
.argv = argv_list.items,
454463
});
455464

@@ -462,7 +471,7 @@ fn gitTag(allocator: std.mem.Allocator, io: std.Io, tag_name: []const u8, messag
462471
}
463472
}
464473

465-
fn gitPush(allocator: std.mem.Allocator, io: std.Io, follow_tags: bool) !void {
474+
fn gitPush(allocator: std.mem.Allocator, follow_tags: bool) !void {
466475
var argv_list = std.ArrayList([]const u8){};
467476
defer argv_list.deinit(allocator);
468477

@@ -471,7 +480,8 @@ fn gitPush(allocator: std.mem.Allocator, io: std.Io, follow_tags: bool) !void {
471480

472481
if (follow_tags) try argv_list.append(allocator, "--follow-tags");
473482

474-
const result = try std.process.run(allocator, io, .{
483+
const result = try std.process.Child.run(.{
484+
.allocator = allocator,
475485
.argv = argv_list.items,
476486
});
477487

@@ -492,7 +502,7 @@ fn formatCommitMessage(allocator: std.mem.Allocator, version: []const u8) ![]u8
492502
, .{version});
493503
}
494504

495-
fn promptForVersion(allocator: std.mem.Allocator, io: std.Io, current_version: []const u8) ![]const u8 {
505+
fn promptForVersion(allocator: std.mem.Allocator, current_version: []const u8) ![]const u8 {
496506
const major_next = try bumpVersion(allocator, current_version, "major");
497507
defer allocator.free(major_next);
498508

@@ -511,13 +521,12 @@ fn promptForVersion(allocator: std.mem.Allocator, io: std.Io, current_version: [
511521
std.debug.print("\n", .{});
512522
std.debug.print("Enter selection (1-3): ", .{});
513523

514-
const stdin_file = std.Io.File.stdin();
515-
524+
const stdin = std.io.getStdIn().reader();
516525
var buf: [100]u8 = undefined;
517-
const len = try stdin_file.readStreaming(io, &.{&buf});
518-
const input = buf[0..len];
526+
const input = try stdin.readUntilDelimiterOrEof(&buf, '\n');
519527

520-
const trimmed = std.mem.trim(u8, input, &std.ascii.whitespace);
528+
const line = input orelse return error.InvalidSelection;
529+
const trimmed = std.mem.trim(u8, line, &std.ascii.whitespace);
521530

522531
if (std.mem.eql(u8, trimmed, "1")) {
523532
return try allocator.dupe(u8, "patch");

src/test_version.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn bumpVersion(allocator: std.mem.Allocator, version: []const u8, release_type:
2525
return error.InvalidReleaseType;
2626
}
2727

28-
return try std.fmt.allocPrint(allocator, "{d}.{d}.{d}", .{parts[0], parts[1], parts[2]});
28+
return try std.fmt.allocPrint(allocator, "{d}.{d}.{d}", .{ parts[0], parts[1], parts[2] });
2929
}
3030

3131
fn findVersion(allocator: std.mem.Allocator, content: []const u8) !?[]u8 {

0 commit comments

Comments
 (0)