# Mutating generated files in later steps

**URL:** <https://ziggit.dev/t/mutating-generated-files-in-later-steps/18060>\
**Category:** Help\
**Tags:** build-system\
**Created:** [October 22, 2026, 9:13pm UTC](https://ziggit.dev/t/mutating-generated-files-in-later-steps/18060 "2026-10-22T21:13:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mba6comma1](https://ziggit.dev/user_avatar/ziggit.dev/mba6comma1/32/10401_2.png) [@mba6comma1](https://ziggit.dev/u/mba6comma1)\
**Post date:** [October 22, 2026, 9:13pm UTC](https://ziggit.dev/t/mutating-generated-files-in-later-steps/18060/1 "2026-10-22T21:13:40Z")

</div>

The gist of what I’m trying to do is: I’m making an ISO file by calling an external command, and then I’m trying to _modify_ that ISO file by calling another command that isn’t actually external but for the purposes of this question we can pretend that it is.

Here’s how I’ve implemented this in my `build.zig`:

```zig
const iso_staging_dir = b.addWriteFiles();
// ...set up the ISO filesystem hierarchy...

const build_iso_cmd = b.addSystemCommand(&.{ "xorriso", "-as", "mkisofs" });
// ...what feels like twenty thousand calls to `build_iso_cmd.addArgs`...
build_iso_cmd.addArg("-output");
const iso_path = build_iso_cmd.addOutputFileArg("aurora.iso");
build_iso_cmd.addDirectoryArg(iso_staging_dir.getDirectory());

const write_boot_sector = b.addRunArtifact(limine_exe); // pretend this is `addSystemCommand`
write_boot_sector.addArg("bios-install");
write_boot_sector.addFileArg(iso_path);

```

(`limine_exe` is a C program I built from a package dependency; it only supports mutating files in-place.)

Now I try to run QEMU passing it my ISO file. By my understanding, all I _should_ have to do is call `addFileArg` and give it the `LazyPath` to my ISO (which I bound to `iso_path` above):

```zig
const qemu_cmd = b.addSystemCommand(&.{"qemu-system-x86_64"});
// ...irrelevant arguments...
qemu_cmd.addArg("-cdrom");
qemu_cmd.addFileArg(iso_path);

```

But this doesn’t quite work. When I run a clean build (i.e. after deleting `zig-cache`), the build runner skips my `write_boot_sector` step and only does `build_iso_cmd` (and `qemu_cmd`). If I want it to work properly, I have to explicitly make `qemu_cmd` depend on `write_boot_sector`:

```zig
// FIXME: This is definitely necessary and I'm not entirely sure why.
qemu_cmd.step.dependOn(&write_boot_sector.step);

```

After adding this line everything seems to work fine (or at any rate I haven’t figured out how to break it yet), but it just feels _wrong_ to me.

I initially thought that the `LazyPath` was keeping track of whatever it was passed to so that the build runner could order dependencies correctly, but after looking at the source that doesn’t appear to be the case; AFAICT the type can only hold at most one `*Step` at a time, presumably the one that first created the `LazyPath` instance. I did a bit more digging and found a few doc comments suggesting that what I’m doing here (mutating the file referenced by a `LazyPath` after the step that initally generated said file) is not a supported use case, or at any rate that I’m doing it wrong.

So I guess what I’m asking is:

1. Am I understanding correctly how this is _supposed_ to work?
2. How can I mutate this generated file in a way that’s actually supported and won’t potentially break the build cache system or anything similar?

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [October 23, 2026, 1:04am UTC](https://ziggit.dev/t/mutating-generated-files-in-later-steps/18060/2 "2026-10-23T01:04:19Z")

</div>

There is nothing stopping it from mutating an input path (`addFileArg`), the issue is the API doesn’t track mutating steps, which just means you have to add the step dependencies your self.

Alternatively, you could make a simple wrapper script that first copies an input path to an output path before running the actual utility, this way you get new lazy paths from each mutation.

---

<div class="post-metadata">

**Author:** ![leecannon](https://ziggit.dev/user_avatar/ziggit.dev/leecannon/32/82_2.png) [@leecannon](https://ziggit.dev/u/leecannon)\
**Post date:** [October 23, 2026, 10:17am UTC](https://ziggit.dev/t/mutating-generated-files-in-later-steps/18060/3 "2026-10-23T10:17:50Z")

</div>

Related issue: [build system: support run steps that modify input files · Issue #24758 · ziglang/zig](https://github.com/ziglang/zig/issues/24758).

The current solution people use is things like [limine-install](https://github.com/CascadeOS/CascadeOS/blob/main/tool/limine_install/limine_install.zig) and [zig-limine-install](https://github.com/zig-osdev/zig-limine-install/blob/main/wrapper.zig).
