aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build
diff options
context:
space:
mode:
authorIsaac Freund <mail@isaacfreund.com>2025-08-16 11:32:10 +0200
committerAndrew Kelley <andrew@ziglang.org>2025-08-16 15:43:48 -0700
commit551e009da7be279293fe261b729280d29fcf81b0 (patch)
tree2cc356fc7c44c09d8e893f4f1b5a63b3290ec993 /lib/std/Build
parent399bace2f20e64e4c10c014dc3b8e202a891c6e4 (diff)
downloadzig-551e009da7be279293fe261b729280d29fcf81b0.tar.gz
zig-551e009da7be279293fe261b729280d29fcf81b0.zip
Build.Step.Run: fix missing stdin buffer and flush
Writer.sendFileAll() asserts non-zero buffer capacity in the case that the fallback is hit. It also requires the caller to flush. The buffer may be bypassed as an optimization but this is not a guarantee. Also improve the Writer documentation and add an earlier assert on buffer capacity in sendFileAll().
Diffstat (limited to 'lib/std/Build')
-rw-r--r--lib/std/Build/Step/Run.zig12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index 823e9a8b41..78cf08dd43 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1780,9 +1780,10 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
};
defer file.close();
// TODO https://github.com/ziglang/zig/issues/23955
- var buffer: [1024]u8 = undefined;
- var file_reader = file.reader(&buffer);
- var stdin_writer = child.stdin.?.writer(&.{});
+ var read_buffer: [1024]u8 = undefined;
+ var file_reader = file.reader(&read_buffer);
+ var write_buffer: [1024]u8 = undefined;
+ var stdin_writer = child.stdin.?.writer(&write_buffer);
_ = stdin_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {
error.ReadFailed => return run.step.fail("failed to read from {f}: {t}", .{
path, file_reader.err.?,
@@ -1791,6 +1792,11 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult {
stdin_writer.err.?,
}),
};
+ stdin_writer.interface.flush() catch |err| switch (err) {
+ error.WriteFailed => return run.step.fail("failed to write to stdin: {t}", .{
+ stdin_writer.err.?,
+ }),
+ };
child.stdin.?.close();
child.stdin = null;
},