Build.zig.zon: 'raw' dependencies are fetched on each build

I’m seeing a curious dependency fetch behaviour in 0.14.0 which must have slipped in as a last minute change (because I was following the 0.14.0-dev versions quite closely):

In the sokol-zig build.zig.zon I have a dependency on a git repo that’s not a Zig project (and doesn’t have a build.zig.zon):

…when I run zig build multiple times, I can see that this dependency is fetched each time (or at least the build process is stuck on this each time for half a second or so).

In the global Zig cache there is only one entry though (so at least it’s not polluting the cache):

zig ➤ fd emsdk
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk.bat
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk.ps1
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk.py
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_env.bat
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_env.csh
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_env.fish
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_env.ps1
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_env.sh
p/N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78/emsdk_manifest.json

I assume this is a bug (maybe related to the new naming convention for cache entries), but first wanted to ask here if anybody else sees this behaviour before writing a ticket.

PS: to reproduce (this is on macOS):

git clone https://github.com/floooh/sokol-zig && cd sokol-zig
zig build
zig build
zig build
...

…the second and third time zig build is run you can see for a short moment that the emsdk dependency is fetched again.

Maybe you are experiencing this?
0.14.0 release-notes #New-Package-Hash-Format:

Although the legacy hash format is still supported, this change breaks any packages that do not already happen to follow the new package naming rules outlined above. There is also a known bug: legacy packages are unnecessarily fetched.

From the issue:

Suggested workaround: upgrade to new hash format
Alternate workaround: use zig-0.13.0 to zig fetch legacy packages

I have no plans to solve this bug. Problem will solve itself as projects upgrade to new hash format.

1 Like

Ooof, ‘closed as not planned’.

Bummer.

Fetching things that are not Zig packages (e.g. just raw collections of files without a build.zig.zon) was one of the best features of the package manager.

I have no idea how to integrate the Emscripten SDK with this restriction in place tbh…

PS: wait maybe I misunderstood… ‘legacy hash format’… let me try something…

I think you just need to update the hash to the new hash format.

1 Like

Yeah that works, hash now looks like this, and problem is gone. Thanks for the hint!

    .dependencies = .{
        .emsdk = .{
            .url = "git+https://github.com/emscripten-core/emsdk#4.0.3",
            .hash = "N-V-__8AAOG3BQCJ9cn-N2swm2o5cLmDhmdHmtwNngOChK78",
        },
    },
2 Likes