# Build.zig do step if certain directory changes?

**URL:** <https://ziggit.dev/t/build-zig-do-step-if-certain-directory-changes/18001>\
**Category:** Help\
**Tags:** build-system\
**Created:** [October 17, 2026, 10:53am UTC](https://ziggit.dev/t/build-zig-do-step-if-certain-directory-changes/18001 "2026-10-17T10:53:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![senjosei](https://ziggit.dev/user_avatar/ziggit.dev/senjosei/32/7498_2.png) [@senjosei](https://ziggit.dev/u/senjosei)\
**Post date:** [October 17, 2026, 10:53am UTC](https://ziggit.dev/t/build-zig-do-step-if-certain-directory-changes/18001/1 "2026-10-17T10:53:51Z")

</div>

Im trying to migrate my project to the new build system. Is there a way to say “rerun this step if a directory and its content changes”?  
This is my code rn, `java-sources.zig` just walks the first arg dir and writes the abs path of it into the second arg.

```zig
const java_sources = b.addRunArtifact(b.addExecutable(.{
    .name = "java-sources",
    .root_module = b.createModule(.{
        .root_source_file = b.path("src/build-tools/java-sources.zig"),
        .target = target,
        .optimize = .debug,
    }),
}));

java_sources.addDirectoryArg2(b.path("src/runtime-java/"), .{});
const java_sources_file = java_sources.addOutputFileArg2("java-sources.txt", .{});

const javac = b.addSystemCommand(&.{
    "javac",
    "-cp",
    "asset/jar-libs/*",
    "-d"
});
javac.step.dependOn(&java_sources.step);
const class_dir = javac.addOutputDirectoryArg2("class", .{});
javac.addPrefixedFileArg("@", java_sources_file);

const jar = b.addSystemCommand(&.{ // jar cvf myapp.jar -C bin .
    "jar",
    "cvf"
});
jar.step.dependOn(&javac.step);
const jar_file = jar.addOutputFileArg("runtime.jar");
jar.addArg("-C");
jar.addDirectoryArg(class_dir);
jar.addArg(".");

b.getInstallStep().dependOn(&jar.step);
b.getInstallStep().dependOn(&b.addInstallBinFile(jar_file, "runtime.jar").step);
b.getInstallStep().dependOn(&b.addInstallBinFile(java_sources_file, "java-source.txt").step);

```

i thought it was enough to just reference the dir with `b.path` but its not apparently

---

<div class="post-metadata">

**Author:** ![sohro\_desu](https://ziggit.dev/user_avatar/ziggit.dev/sohro_desu/32/4267_2.png) [@sohro\_desu](https://ziggit.dev/u/sohro_desu)\
**Post date:** [October 17, 2026, 1:48pm UTC](https://ziggit.dev/t/build-zig-do-step-if-certain-directory-changes/18001/2 "2026-10-17T13:48:24Z")

</div>

I found this:

std.Build.dependOnDirectoryMetadata - indicates that the build.zig logic depends on a particular directory’s last modification date.

from here: [0.17.0 Release Notes ⚡ The Zig Programming Language](https://ziglang.org/download/0.17.0/release-notes.html#Build-System)

I myself had to sift through build system code to get my apk producer working inside termux and it was a great success. And I think it’s really worth just browsing definitions with the help of lsp.

Pretty sure `dependOnDirectoryMetadata` will work for you

---

<div class="post-metadata">

**Author:** ![vincentd](https://ziggit.dev/user_avatar/ziggit.dev/vincentd/32/9870_2.png) [@vincentd](https://ziggit.dev/u/vincentd)\
**Post date:** [October 17, 2026, 3:41pm UTC](https://ziggit.dev/t/build-zig-do-step-if-certain-directory-changes/18001/3 "2026-10-17T15:41:31Z")

</div>

Configure cache poisoning should solve it for you. Specifically, either `std.Build.dependOnDirectoryMetadata` or `std.Build.dependOnDirectoryContents`. The difference is described in their documentation. Beware: **they are not recursive.**

To a similar problem:

> [@Recusively adding a directory and sub-directories to include path](https://ziggit.dev/t/recusively-adding-a-directory-and-sub-directories-to-include-path/17842/3):
>
> I think zig 0.17.0 will let you do it with [Configure Cache Poisoning](https://ziglang.org/download/0.17.0/release-notes.html#Introduce-the-Concept-of-Configure-Cache-Poisoning), specifically std.Build.dependOnDirectoryMetadata. That tells the ‘maker’ to rerun the ‘configurer’ if the directory contents changes. NB: it is not recursive. That said, I recommend listing individual files. Unlike zig, C & C++ don’t have a mechanism for the compiler to determine what code is and isn’t used, so by listing them individually: It makes it easy for other people reading your project to see what it’s doing. Your …
