How to delete all files in the target LazyPath before an InstallDirectory build step?

If looks InstallDirectory doesn’t clear the files in the target path.

I think clearing the target directory should be a separate task, rather than implicit behavior of InstallDirectory.

Build systems generally leave this kind of orchestration to the dependency graph. If a clean build or install is desired, the graph can explicitly express clear -> build -> install.

I realize Zig doesn’t provide a built-in zig build clean command, so users would need to define their own clean step. However, I think it’s better to explicitly define a clean step when needed than to have InstallDirectory clear the target directory as part of the install task. It keeps the install step predictable and composable, while allowing users to choose when cleaning is necessary.

it does provide a placeholder zig build uninstall, however it is not yet implemented.

There is a complication in that it cannot simply delete everything because the build system output is designed so you can just --prefix ~/.local (or /usr) to install the project. And particular projects may have more than just the build output to remove.

So I think it is likely that it will be removed.

I would recommend just deleting the output directory manually, if you do it often you can just combine the commands and use shell history or an alias or something.

Alternatively, you can make it happen automatically by putting this in build.zig

    const clean = b.addSystemCommand(&.{"rm", "-r", "zig-out"});
    clean.has_side_effects = true;
    b.getInstallStep().dependOn(&clean.step);

Okay.

It looks 0.15 supports Step.RemoveDir, but which is removed now. There should be a reason for it.