Skip to content

std.Build.Step.WriteFile does not implement caching correctly for directories #20571

@andrewrk

Description

@andrewrk

Zig Version

0.14.0-dev.208+854e86c56

Steps to Reproduce and Observed Behavior

zig init

Add this code to build.zig:

    const wf = b.addWriteFiles();
    b.installDirectory(.{
        .source_dir = wf.addCopyDirectory(b.path("stuff"), "stuff", .{}),
        .install_dir = .prefix,
        .install_subdir = "",
    });
$ mkdir stuff
$ touch stuff/1
$ zig build
$ ls zig-out/
1  bin  lib
$ touch stuff/2
$ zig build
$ ls zig-out
1  bin  lib

Expected Behavior

When running zig build the second time, it should notice that a second file exists (2) and copy it to the WriteFile output directory, and then copy it to the installation prefix.

Diagnosis

This happens because the implementation only adds the directory name to the cache hash, instead of marking the file and directory itself as part of the cache input.

for (write_file.directories.items) |dir| {
man.hash.addBytes(dir.source.getPath2(b, step));
man.hash.addBytes(dir.sub_path);
for (dir.options.exclude_extensions) |ext| man.hash.addBytes(ext);
if (dir.options.include_extensions) |incs| for (incs) |inc| man.hash.addBytes(inc);
}

This is insufficient and results in false positive cache hits. False positives in the cache system are not allowed; this must be fixed to work perfectly or the feature reverted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorzig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions