I'd like to have a build.zig step which takes in a *.zig file, does a transoformation on it, and outputs the resulting *.zig file. I've thought of a few ways of doing this, I'm wondering if there's a better way that I'm missing.
(Background: What I'm trying to do is run a translate-c step on some *.h files, then run a transformation on the output because I know some of the input headers contained structs with bitfields on them. The transformation would replace these headers with zig implementations rather than opaque {}. After the transformation, I'll include the resulting *.zig as a module for the final product.)
Here's what I've thought of:
addSystemCommand(). I could use awk or sed to replace theopaquedefinitions with zig structs. This is problematic for 2 reasons: one is that using text transformations is just fragile in general, and two is that I can't seem to get it to work. For example, I attempted to run the following sed command through addSystemCommand, and it would always complain about some syntax failure, even though the command works perfectly for my purpose when run from the terminal.
Example command I'd try to run (to no avail):
const fixup_module_step = b.addSystemCommand(&.{
"sed",
"-e",
"'pub const struct_contains_bitfields/{r c_import/header.zig' -e 'd}'",
});
fixup_module_step.addFileArg(translate_c_path);
const fixup_module_path = fixup_module_step.captureStdOut();
(continued in comment)