authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-01 01:24:06 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-01 01:24:06 -08:00
log36bd8b373cad3217e0cc4dce2d1e3e4b3887947d
tree8bea73f03ad1871240773674f262437125756db1
parent75f152bc3877c50808405f04cdc1a9dea8ea118c

cmd/init: ask if zigmod should write a build.zig


1 files changed, 63 insertions(+), 0 deletions(-)

src/cmd/init.zig+63
...@@ -171,6 +171,69 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -171,6 +171,69 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
171 try w.writeAll("zigmod.* text eol=lf\n");171 try w.writeAll("zigmod.* text eol=lf\n");
172 }172 }
173 }173 }
174
175 // ask about build.zig
176 if (!try extras.doesFileExist(null, "build.zig")) {
177 const do = try inquirer.forConfirm(stdout, stdin, "It looks like there's no build.zig. Do you want Zigmod to generate one for you?", gpa);
178 if (do) {
179 const file = try cwd.createFile("build.zig", .{});
180 defer file.close();
181 const w = file.writer();
182 switch (ptype) {
183 .exe => {
184 try w.writeAll(
185 \\const std = @import("std");
186 \\const deps = @import("./deps.zig");
187 \\
188 \\pub fn build(b: *std.Build) void {
189 \\ const target = b.standardTargetOptions(.{});
190 \\ const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
191 \\
192 \\ const exe = b.addExecutable(.{
193 \\ .root_source_file = b.path("main.zig"),
194 \\ .target = target,
195 \\ .optimize = mode,
196 \\ });
197 \\ deps.addAllTo(tests);
198 \\ b.installArtifact(exe);
199 \\
200 \\ const run_step = b.step("run", "Run the app");
201 \\ const run_cmd = b.addRunArtifact(exe);
202 \\ run_cmd.step.dependOn(b.getInstallStep());
203 \\ if (b.args) |args| run_cmd.addArgs(args);
204 \\ run_step.dependOn(&run_cmd.step);
205 \\}
206 \\
207 );
208 },
209 .lib => {
210 try w.writeAll(
211 \\const std = @import("std");
212 \\const deps = @import("./deps.zig");
213 \\
214 \\pub fn build(b: *std.Build) void {
215 \\ const target = b.standardTargetOptions(.{});
216 \\ const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
217 \\
218 \\ const tests = b.addTest(.{
219 \\ .root_source_file = b.path("test.zig"),
220 \\ .target = target,
221 \\ .optimize = mode,
222 \\ });
223 \\ deps.addAllTo(tests);
224 \\
225 \\ const test_step = b.step("test", "Run all library tests");
226 \\ const tests_run = b.addRunArtifact(tests);
227 \\ tests_run.setCwd(b.path("."));
228 \\ tests_run.has_side_effects = true;
229 \\ test_step.dependOn(&tests_run.step);
230 \\}
231 \\
232 );
233 },
234 }
235 }
236 }
174}237}
175238
176pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {239pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {