There’s a program generating Zig code, and if it detects that a file it needs is stale, then the code it generates is compiled and run, and the program runs a second time with the not-stale file which is output by the first run.
Then that second output is routed just like it would have been if the system only ran once.
I guess that sounds, odd, without providing the reason why, but I assure you that it does make sense and I’ll stop being vague when it works
I want other people to be able to do this, not just me, so I’d like to make it relatively painless. I’m pretty sure I could kludge together something which does this, maybe, but I’d love some better ideas than anything I’ve come to myself.
Is there an obvious build command where I simply didn’t read the doc comment correctly? (that’s a joke)
I want: codegen -> [file is fresh] -> output
and also: codegen -> [file is stale] -> other_out -> compile to program -> program runs -> codegen again -> [file is now fresh] -> output
I freely grant that it’s odd and confusing that the codegen would emit a different program, and that would be the natural thing to have happen, but it is.
That would make a rare event happen unconditionally. But I do know how to do it. I’m hoping I can avoid it.
When you give run steps inputs as files those run steps only rerun when the inputs change, otherwise their output would be cached and reused.
So the first time both would run then only when one of the generated outputs is different from what was previously generated, the following parts would rerun.
Still not sure whether I understand what you actually want to do.
What decides whether a file is fresh?
Maybe one option would to have a “fat” run step with has_side_effects = true, that then does its internal logic to look at the input file, decide whether it is fresh and based on that generate directly output or invoke the compile, run, mark as fresh, return output.
This is hard to explain because it’s a weird thing to do.
codegen produces one of two files, both Zig code. It wants to talk to build system, so in stale condition, the output is compiled and run as a tool. That tool produces fresh file, and then codegen runs again and produces intended-output. codegen is what’s in a position to know when the file becomes stale, and as odd as it may seem, the output of codegen is very much the proper thing to modify in order to freshen the file. By compiling and running it.
I’ve considered a side-channel, like a sentinel file which only shows up if we’re on the stale track, and then I have to delete it. It’s not terrible, I wonder if I can do better though.