aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/build.zig
diff options
context:
space:
mode:
authorManlio Perillo <manlio.perillo@gmail.com>2023-04-02 14:59:22 +0200
committerManlio Perillo <manlio.perillo@gmail.com>2023-04-02 15:09:51 +0200
commitdd15cb94fd522bd7c6dd48ff096e4b059a69dbd3 (patch)
tree60e4e5464b96162a2f51a7c6f931076062d97fb8 /build.zig
parentb75a76d072f9cc5e0989062a0f45f13ce576d3b6 (diff)
build: make the logo a build step
Currently, the logo is always printed when the build script is executed, resulting in the logo being printed twice with `zig build -h` and `zig build -l`. Make the logo a build step, so that the logo is printed to stderr only when necessary. Closes #211
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig34
1 files changed, 33 insertions, 1 deletions
diff --git a/build.zig b/build.zig
index 5ade0c4..035f0bb 100644
--- a/build.zig
+++ b/build.zig
@@ -572,7 +572,9 @@ pub fn build(b: *Builder) !void {
\\
;
const header_step = b.step("info", logo);
- print("{s}\n", .{logo});
+
+ const logo_step = PrintStep.create(b, logo, std.io.getStdErr());
+ logo_step.step.dependOn(header_step);
const verify_all = b.step("ziglings", "Check all ziglings");
verify_all.dependOn(header_step);
@@ -804,3 +806,33 @@ const ZiglingStep = struct {
});
}
};
+
+// Print a message to a file.
+const PrintStep = struct {
+ step: Step,
+ message: []const u8,
+ file: std.fs.File,
+
+ pub fn create(owner: *std.Build, message: []const u8, file: std.fs.File) *PrintStep {
+ const self = owner.allocator.create(PrintStep) catch @panic("OOM");
+ self.* = .{
+ .step = Step.init(.{
+ .id = .custom,
+ .name = "Print",
+ .owner = owner,
+ .makeFn = make,
+ }),
+ .message = message,
+ .file = file,
+ };
+
+ return self;
+ }
+
+ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
+ _ = prog_node;
+ const p = @fieldParentPtr(PrintStep, "step", step);
+
+ try p.file.writeAll(p.message);
+ }
+};