Skip to content

fix(build): use ZIG_GLOBAL_CACHE_DIR for Zig 0.17+ - #172

Merged
psadi merged 1 commit into
mainfrom
fix/zig-0.17-offline-cache
Oct 28, 2026
Merged

psadi merged 1 commit into
mainfrom
fix/zig-0.17-offline-cache

Conversation

@psadi

@psadi psadi commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Nightly builds have failed every day since 2026-10-21. Two separate Zig 0.17.0 regressions are responsible; ZIG_VERSION is read dynamically from upstream build.zig.zon (minimum_zig_version), so both appeared without any change in this repo once tip moved to 0.17.0.

1. --global-cache-dir was removed from zig build

Zig 0.17.0 only accepts --global-cache-dir on build-exe/run, not zig build, so the build died seconds after starting:

+ zig build ... --global-cache-dir /tmp/offline-cache
error: unrecognized argument: --global-cache-dir

Fix: feed the pre-fetched offline cache through ZIG_GLOBAL_CACHE_DIR, which every Zig release honors (and which fetch-zig-cache.sh already required). No version-gated CLI flag is needed any more.

2. zig fetch caches tarballs in a layout zig build rejects

With the flag fixed, the build then failed with hash mismatches for all 37 dependencies:

pkg/zlib/build.zig.zon:10:21: error: hash mismatch: manifest declares N-V-__8AAB0eQwD-0Md...
but the fetched package has N-V-__8AAB0eQwDaat...

In 0.17.0, standalone zig fetch stores the package tarball with the upstream top-level directory still nested (<hash>/zlib-1.3.1/...), while zig build expects package-root-relative paths and therefore re-hashes it as a different package. Reproduced outside containers with a clean global cache; a plain zig build fetch produces the correct layout.

Fix: on Zig >= 0.17 pre-populate the cache with zig build --fetch=all (new in 0.17), which writes the layout the build expects and resolves lazy/transitive deps itself — the exact gap nix/build-support/fetch-zig-cache.sh used to work around.

Zig < 0.16 keeps the previous --system /tmp/offline-cache/p + fetch-script behaviour.

Verification

  • 0.17.0: zig build --fetch=all on the tip source succeeds, and the following zig build no longer reports hash mismatches.
  • shellcheck --severity=warning --shell=sh, shfmt, and the rest of pre-commit pass.
  • Full pipeline (setup-env → build-ghostty → bundle-appimage → validate-appimage) running in the same Arch container CI uses; this PR run is the end-to-end check.

Note: transient 500s from deps.files.ghostty.org were seen while testing; unrelated to this change.

Zig 0.17.0 broke the build in two places:

1. `--global-cache-dir` was removed from the `zig build` subcommand (it is
   only accepted by build-exe/run now), so nightly builds failed with
   'error: unrecognized argument: --global-cache-dir'. Use the
   ZIG_GLOBAL_CACHE_DIR env var instead, which every Zig release honors and
   which already had to be set for the fetch step.

2. Standalone `zig fetch` now caches tarballs with the upstream top-level
   directory still nested, so the subsequent `zig build` re-hashes them and
   fails with 'hash mismatch'. `zig build --fetch=all` fills the cache in the
   layout the build expects and also resolves lazy/transitive deps, which is
   exactly what fetch-zig-cache.sh worked around.

Upstream tip bumped minimum_zig_version to 0.17.0 and the version is read
dynamically from build.zig.zon, so both regressions appeared without any
change in this repo. Zig < 0.16 keeps the previous behaviour.
@psadi
psadi force-pushed the fix/zig-0.17-offline-cache branch from be91fe5 to fb0eb4b Compare October 27, 2026 19:22
@psadi
psadi merged commit 3e75caa into main Oct 28, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant