Skip to content

Conversation

Justus2308
Copy link
Contributor

@Justus2308 Justus2308 commented Sep 13, 2025

Adds addFileContentArg and addPrefixedFileContentArg to pass the content
of a file with a lazy path as an argument to a std.Build.Step.Run.
This enables replicating shell $() / cmake execute_process with OUTPUT_VARIABLE
as an input to another execute_process in conjuction with captureStdOut/captureStdErr.

To also be able to replicate $() automatically trimming trailing newlines and cmake
OUTPUT_STRIP_TRAILING_WHITESPACE, this patch also adds an options arg to those
functions which allows specifying the desired handling of surrounding whitespace.

The options arg also allows to specify a custom basename for the output. e.g.
to add a file extension (concrete use case: Zig @import() requires files to have a
.zig/.zon extension to recognize them as valid source files).

I've tested this patch on a private project and it worked just fine, however if I should write some kind of test case I'll be happy to do so. I just wasn't sure what such a test case should look like, so any advice on that would be appreciated.

@Justus2308 Justus2308 force-pushed the build-file-content-arg branch from aa43e17 to 1c25c1d Compare September 15, 2025 16:34
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Ready to merge aside from some minor requests.

Adds `addFileContentArg` and `addPrefixedFileContentArg` to pass the content
of a file with a lazy path as an argument to a `std.Build.Step.Run`.
This enables replicating shell `$()` / cmake `execute_process` with `OUTPUT_VARIABLE`
as an input to another `execute_process` in conjuction with `captureStdOut`/`captureStdErr`.

To also be able to replicate `$()` automatically trimming trailing newlines and cmake
`OUTPUT_STRIP_TRAILING_WHITESPACE`, this patch adds an `options` arg to those functions
which allows specifying the desired handling of surrounding whitespace.

The `options` arg also allows to specify a custom `basename` for the output. e.g.
to add a file extension (concrete use case: Zig `@import()` requires files to have a
`.zig`/`.zon` extension to recognize them as valid source files).
@Justus2308 Justus2308 force-pushed the build-file-content-arg branch from 1c25c1d to 4045043 Compare September 19, 2025 17:08
@Justus2308
Copy link
Contributor Author

Thanks for the review! I've addressed your comments

@Justus2308 Justus2308 requested a review from andrewrk September 19, 2025 17:12
@andrewrk
Copy link
Member

Thanks!

@andrewrk andrewrk enabled auto-merge (rebase) September 19, 2025 17:52
@andrewrk andrewrk merged commit be571f3 into ziglang:master Sep 20, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants