summaryrefslogtreecommitdiffstatshomepage
path: root/build.zig
diff options
context:
space:
mode:
authorManlio Perillo <manlio.perillo@gmail.com>2023-04-10 21:24:49 +0200
committerManlio Perillo <manlio.perillo@gmail.com>2023-04-11 12:52:48 +0200
commit47876e637185e2194dde1b9245e1bc603a604d7e (patch)
tree24968f1b6527085515f4a5de78a6817b6804d8ae /build.zig
parent1ee8aabcf3457fe5951958adc11a7c8ca2f3476a (diff)
build: make PrintStep thread safe
Update PrintStep to always printing to stderr, using std.debug.print, so that the message is written atomically. Note that currently it is not an issue, since PrintStep prints the message before everything else.
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig10
1 files changed, 4 insertions, 6 deletions
diff --git a/build.zig b/build.zig
index 8b93e2b..84535d1 100644
--- a/build.zig
+++ b/build.zig
@@ -557,7 +557,7 @@ pub fn build(b: *Build) !void {
const use_healed = b.option(bool, "healed", "Run exercises from patches/healed") orelse false;
const exno: ?usize = b.option(usize, "n", "Select exercise");
- const header_step = PrintStep.create(b, logo, std.io.getStdErr());
+ const header_step = PrintStep.create(b, logo);
if (exno) |n| {
if (n == 0 or n > exercises.len - 1) {
@@ -861,13 +861,12 @@ const ZiglingStep = struct {
}
};
-// Print a message to a file.
+// Print a message to stderr.
const PrintStep = struct {
step: Step,
message: []const u8,
- file: std.fs.File,
- pub fn create(owner: *Build, message: []const u8, file: std.fs.File) *PrintStep {
+ pub fn create(owner: *Build, message: []const u8) *PrintStep {
const self = owner.allocator.create(PrintStep) catch @panic("OOM");
self.* = .{
.step = Step.init(.{
@@ -877,7 +876,6 @@ const PrintStep = struct {
.makeFn = make,
}),
.message = message,
- .file = file,
};
return self;
@@ -887,7 +885,7 @@ const PrintStep = struct {
_ = prog_node;
const p = @fieldParentPtr(PrintStep, "step", step);
- try p.file.writeAll(p.message);
+ print("{s}", .{p.message});
}
};