From 08ddfb17a9e48576581de2c8acb1f231731f8f57 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Tue, 18 Aug 2026 01:09:08 -0700 Subject: [PATCH] Maker: Fix fetch-generated build.zig.zon location when build_root is not cwd This fixes what was previously a guaranteed PathAlreadyExists error when LoadManifestOptions.dir (the build_root) was not equal to CWD, since the file would always get written to the CWD but then looked for in the build root, so after creation the retry would fail and then the re-creation would fail since it's created with an exclusive lock. --- lib/compiler/Maker.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index be6a975a253d80cccee19558e0e2fa71b9b776ff..92db208cbc7e299ee0282a504ca1dd372f83a604 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -2017,7 +2017,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { return process.cleanExit(io); }, .minimal => { - Templates.writeSimpleFile(io, Package.Manifest.basename, + Templates.writeSimpleFile(io, Io.Dir.cwd(), Package.Manifest.basename, \\.{{ \\ .name = .{s}, \\ .version = "0.0.1", @@ -2034,7 +2034,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }), error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}), }; - Templates.writeSimpleFile(io, default_build_zig_basename, + Templates.writeSimpleFile(io, Io.Dir.cwd(), default_build_zig_basename, \\const std = @import("std"); \\ \\pub fn build(b: *std.Build) void {{ @@ -3840,7 +3840,7 @@ fn loadManifest( 0, ) catch |err| switch (err) { error.FileNotFound => { - Templates.writeSimpleFile(io, Package.Manifest.basename, + Templates.writeSimpleFile(io, options.dir, Package.Manifest.basename, \\.{{ \\ .name = .{s}, \\ .version = "0.0.1", @@ -4002,8 +4002,8 @@ const Templates = struct { }; } - fn writeSimpleFile(io: Io, file_name: []const u8, comptime format: []const u8, args: anytype) !void { - const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true }); + fn writeSimpleFile(io: Io, dir: Io.Dir, file_name: []const u8, comptime format: []const u8, args: anytype) !void { + const f = try dir.createFile(io, file_name, .{ .exclusive = true }); defer f.close(io); var buf: [4096]u8 = undefined; var fw = f.writer(io, &buf); -- 2.54.0