zig icon indicating copy to clipboard operation
zig copied to clipboard

std.Build.Step.Run: ability to provide a FileSource as the stdin input to the run command

Open andrewrk opened this issue 2 years ago • 0 comments

Currently we have this:

https://github.com/ziglang/zig/blob/1253d591be2aeea49c0b67ce0416237060e78a57/lib/std/Build/Step/Run.zig#L39-L40

This requires the stdin to be passed to the child process to be buffered in a slice. Sometimes this is handy, but other times, the build script might have a FileSource that should get piped via stdin to the child process. There should be API to handle this gracefully and with cache integration.

To solve this issue, I suggest to start here:

--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -36,8 +36,8 @@ env_map: ?*EnvMap,
 /// be skipped if all output files are up-to-date and input files are
 /// unchanged.
 stdio: StdIo = .infer_from_args,
-/// This field must be `null` if stdio is `inherit`.
-stdin: ?[]const u8 = null,
+/// This field must be `none` if stdio is `inherit`.
+stdin: StdIn = .none,
 
 /// Additional file paths relative to build.zig that, when modified, indicate
 /// that the Run step should be re-executed.
@@ -77,6 +77,12 @@ captured_stderr: ?*Output = null,
 
 has_side_effects: bool = false,
 
+pub const StdIn = union(enum) {
+    none,
+    bytes: []const u8,
+    file_source: std.Build.FileSource,
+};
+
 pub const StdIo = union(enum) {
     /// Whether the Run step has side-effects will be determined by whether or not one
     /// of the args is an output file (added with `addOutputFileArg`).

andrewrk avatar Jun 15 '23 18:06 andrewrk