Zig build not caching?

When I run zig build and then zig build again immediately, the second command takes about a second to “Fetch Packages”. Is this expected? Shouldn’t those packages be cached? I deleted ./.zig-cache and also deleted ~/.cache/zig/, but the second zig build still fetches.

Strangely, it’s fetching a dependency of a dependency, not a direct dependency.


More info:
This is essentially zig init plus following the README from rtmidi_z

My build.zig.zon has this:

    .dependencies = .{
        .rtmidi_z = .{
            .url = "git+https://github.com/robbielyman/rtmidi_z#778089a7d04cd3afe256179b3ad98d3a89bf616a",
            .hash = "rtmidi_z-6.0.0+53809fc-YOZ1LxE1AAASrJw_kBdJ-4ASBRbc8kBeW6LP4SwiINjE",
        },
    },

rtmidi_z’s build.zig.zon has this:

    .dependencies = .{
        .upstream = .{
            .url = "https://github.com/thestk/rtmidi/archive/53809fc1869a9789c4631a11081c1840b6db1527.tar.gz",
            .hash = "12201253fb51b1c24c5dbbc2d1ea6f752289dec30ae992bc35123b2da6c572d4899b",
        },
    },

Here’s an invocation: (this is the transient “loading” text)

> zig build --summary all
Compile Build Script
└─ [2/2] Fetch Packages
   └─ upstream

Here’s that same invocation, but after the transient text disappears:

> zig build --summary all

Build Summary: 3/3 steps succeeded
install cached
└─ install tmp_qiCO342JNL cached
   └─ compile exe tmp_qiCO342JNL Debug native cached 26ms MaxRSS:32M

The second invocation is exactly the same as the first.
My zig version is 0.15.2

The hash format got updated, the old format is supported, but there is a bug that makes old hash dependencies get re fetched every time.

Just remove the hash, and the compiler should give you a new one that uses the new format. Which should fix the issue.

2 Likes

Thank you! That worked perfectly, and I’ve submitted a patch to rtmidi_z

2 Likes