+16
-15
Diff
round #0
+16
-15
build.zig
+16
-15
build.zig
···
5
5
const zon_path = std.fs.path.join(b.allocator, &.{ project_root, "build.zig.zon" }) catch @panic("OOM");
6
6
defer b.allocator.free(zon_path);
7
7
8
-
const zon_file = std.fs.openFileAbsolute(zon_path, .{}) catch @panic("Failed to open build.zig.zon");
9
-
defer zon_file.close();
10
-
11
-
const zon_content = zon_file.readToEndAlloc(b.allocator, std.math.maxInt(usize)) catch @panic("Failed to read build.zig.zon");
8
+
const zon_content = std.Io.Dir.cwd().readFileAlloc(b.graph.io, zon_path, b.allocator, .unlimited) catch @panic("Failed to read build.zig.zon");
12
9
defer b.allocator.free(zon_content);
13
10
14
11
var version: []const u8 = "0.0.0";
···
32
29
const target = b.standardTargetOptions(.{});
33
30
const optimize = b.standardOptimizeOption(.{});
34
31
32
+
const flags = b.dependency("flags", .{});
33
+
const version_module = b.createModule(.{
34
+
.root_source_file = generate_version(b),
35
+
});
36
+
35
37
const exe = b.addExecutable(.{
36
38
.name = "tip",
37
39
.root_module = b.createModule(.{
···
41
43
}),
42
44
});
43
45
44
-
const flags = b.dependency("flags", .{});
45
46
exe.root_module.addImport("flags", flags.module("flags"));
46
-
exe.root_module.addImport("version", b.createModule(.{
47
-
.root_source_file = generate_version(b),
48
-
}));
47
+
exe.root_module.addImport("version", version_module);
49
48
50
49
b.installArtifact(exe);
51
50
···
69
68
.optimize = optimize,
70
69
}),
71
70
});
71
+
all_tests.root_module.addImport("flags", flags.module("flags"));
72
+
all_tests.root_module.addImport("version", version_module);
72
73
b.step("test", "Run all tests").dependOn(&b.addRunArtifact(all_tests).step);
73
74
}
74
75
···
76
77
fn generate_test_runner(b: *std.Build, src_dir: []const u8) !std.Build.LazyPath {
77
78
const files = try collect_files(b, src_dir);
78
79
79
-
var content: std.ArrayList(u8) = .empty;
80
-
defer content.deinit(b.allocator);
80
+
var aw = std.Io.Writer.Allocating.init(b.allocator);
81
+
defer aw.deinit();
81
82
82
-
const w = content.writer(b.allocator);
83
+
const w = &aw.writer;
83
84
try w.writeAll("// Auto-generated - do not edit\ntest {\n");
84
85
for (files) |f| {
85
86
try w.print(" _ = @import(\"{s}\");\n", .{f});
···
88
89
89
90
const wf = b.addWriteFiles();
90
91
_ = wf.addCopyDirectory(b.path(src_dir), src_dir, .{});
91
-
return wf.add("auto_test_runner.zig", content.items);
92
+
return wf.add("auto_test_runner.zig", aw.written());
92
93
}
93
94
94
95
fn collect_files(b: *std.Build, dir: []const u8) ![]const []const u8 {
···
105
106
const full = try std.fs.path.join(gpa, &.{ root, current });
106
107
defer gpa.free(full);
107
108
108
-
var d = std.fs.openDirAbsolute(full, .{ .iterate = true }) catch |e| {
109
+
var d = std.Io.Dir.openDirAbsolute(b.graph.io, full, .{ .iterate = true }) catch |e| {
109
110
switch (e) {
110
111
error.FileNotFound => continue,
111
112
else => return e,
112
113
}
113
114
};
114
-
defer d.close();
115
+
defer d.close(b.graph.io);
115
116
116
117
var it = d.iterate();
117
-
while (try it.next()) |e| {
118
+
while (try it.next(b.graph.io)) |e| {
118
119
if (e.name[0] == '.') continue;
119
120
if (e.kind == .file and std.mem.endsWith(u8, e.name, ".zig")) {
120
121
try files.append(gpa, try std.fs.path.join(gpa, &.{ current, e.name }));
History
1 round
0 comments
bnjox.bsky.social
submitted
#0
1 commit
expand
collapse
update tests
merge conflicts detected
expand
collapse
expand
collapse
- build.zig:5