162 Commits
Author SHA1 Message Date
Matthew Lugg 067f8dcb37 std.Build.Cache: support depending on nonexistent file/directory 2026-10-19 18:30:35 +01:00
Matthew Lugg c3b8abfc26 std.Build.Cache: fix diagnostic printing 2026-10-19 18:30:35 +01:00
Andrew Kelley 3a5777b6b1 zig build: put interesting cache statuses in build summary
build summary now tells why a cache miss occurred, if it was an uncommon
case:
* invalid cache manifest
* a specific file was invalidated
* directory contents changed
* metadata changed

Cache miss due to it being the first time a particular build step is
being executed remains silent.

Not all kinds of build steps have this extra data about which files
caused cache invalidation, most notably Compile steps.
2026-10-18 02:16:37 +02:00
Andrew Kelley 9343d0fe4b std.Build.Cache: fix cache miss when metadata changes
adds test for "changed metadata of input file but same digest causes hit"

closes #37200
2026-10-15 08:17:27 +02:00
Andrew Kelley b27aacf820 std.Build.Cache: fix handling of empty sub paths
when a sub path relative to a given prefix is length zero, it needs to
be treated as "." when doing actual file system operations.
2026-09-17 21:03:29 -07:00
Andrew Kelley 56571a70d9 std.Build.Cache: fix flagsAndPath implementation
it was scanning for sentinel starting from flags rather than flags + 1,
which could lead to the scenario where the path is empty because flags
is zero
2026-09-16 16:05:26 -07:00
Andrew Kelley 597306838d frontend: better error reporting for cache check failures 2026-09-16 13:12:47 -07:00
Andrew Kelley e8882ffcf0 std.Build.Cache: fix compilation on 32-bit 2026-09-16 13:12:47 -07:00
Andrew Kelley 5eb4a5d4b4 std.Build.Cache: use Io.File.INode type
rather than u64. fixes build on Windows
2026-09-16 13:12:47 -07:00
Andrew Kelley 28feeaf778 link: pass request_handle=true to addInputPath
when passing already open handle, this is now required when the caller
wants the cache system to keep the file handle open.
2026-09-16 13:12:47 -07:00
Andrew Kelley b9794c89ac std.Build.Cache: remove stray hash mutation 2026-09-16 13:12:47 -07:00
Andrew Kelley 3e3b0b835c std.Build.Cache: fix addDiscoveredManifest 2026-09-16 13:12:47 -07:00
Andrew Kelley 3bb9f1847b std.Build.Cache: add transitionToMissDiscovered in addDiscoveredManifest 2026-09-16 13:12:47 -07:00
Andrew Kelley a014c1a287 std.Build.Cache.DepTokenizer: slightly modernize 2026-09-16 13:12:47 -07:00
Andrew Kelley 92439e73d0 std.Build.Cache: don't preemptively truncate the manifest 2026-09-16 13:12:47 -07:00
Andrew Kelley d1b961c9eb std.Build.Cache: introduce State enum 2026-09-16 13:12:47 -07:00
Andrew Kelley e38052663c std.Build.Cache: fix writing digest to wrong place 2026-09-16 13:12:47 -07:00
Andrew Kelley 228178c151 std.Build.Cache: simplify hashing logic 2026-09-16 13:12:47 -07:00
Andrew Kelley 43397f2251 std.Build.Cache: implement populated requested contents 2026-09-16 13:12:47 -07:00
Jacob Young 9c325be987 This assertion cannot be true on later iterations.
And tautologically true on the first iteration.
2026-09-16 13:12:47 -07:00
Jacob Young 29531cc9c0 finish fixing one unit test 2026-09-16 13:12:47 -07:00
Andrew Kelley 30c3c666ab starting to fix the unit test failures 2026-09-16 13:12:47 -07:00
Andrew Kelley b91a6dc5b1 update to newest std.Build.Cache API 2026-09-16 13:12:47 -07:00
Andrew Kelley a24b4758f4 std.Build.Cache: rework the core logic again
- implement the logic for populating remaining input file digests when a
  miss occurs while checking one of the input files
- make `Manifest.check` return not just "miss" but also explain why it
  was a miss and which file caused it
- fix fundamental design flaw which clobbered input file digest, path,
  and stat information that was needed to compare against on disk
  manifest entries
- implement the logic for when the Manifest API user provides an already
  available handle, stat, or contents, and when they request the handle
  or contents.
- rename `Manifest.writeManifest` to `Manifest.finalize`
- rename `Manifest.manifest_dirty` to `Manifest.dirty`
2026-09-16 13:12:47 -07:00
Andrew Kelley 3f092f8c28 std.Build.Cache: add missing resource deallocation 2026-09-16 13:12:47 -07:00
Andrew Kelley 31b86e53aa std: update to new std.Build.Cache API 2026-09-16 13:12:47 -07:00
Andrew Kelley 0334f14a13 compiler: update to new std.Build.Cache API 2026-09-16 13:12:47 -07:00
Andrew Kelley 5b57dca62d std.build.Cache: fix regressions from the branch 2026-09-16 13:12:47 -07:00
Andrew Kelley 2c605872fc std.Build.Cache: non-async checking
Empirically this went from 29% slower than status quo on my machine to
15% faster, for `zig build` on the `zig init` project.
2026-09-16 13:12:47 -07:00
Andrew Kelley 28e360fb61 std.Build.Cache: eliminate unbounded concurrency
would be nice if Io.Select.async had a variant where it returned the
eager result rather than trying to put it in the queue so that the queue
buffer doesn't need to be dynamically allocated
2026-09-16 13:12:47 -07:00
Andrew Kelley b422974322 std.Build.Cache: add missing hash-computing logic 2026-09-16 13:12:47 -07:00
Andrew Kelley f7bdb939e1 add cache-cat subcommand
for printing .zig-cache/h/* files to zon format
2026-09-16 13:12:47 -07:00
Andrew Kelley 2a82193af4 std.Build.Cache: fix deadlock from using Io.Select
Io.Select.async has a fatal flaw: if the queue size isn't big enough to
hold the result of an eager async call, then it deadlocks.

The workaround in this thread is using concurrent() which should be
reverted because it will spawn too many threads.
2026-09-16 13:12:47 -07:00
Andrew Kelley 4dbe872dfe std.Build.Cache: fix calculation of File size when reading manifest 2026-09-16 13:12:47 -07:00
Andrew Kelley 48d6b1aa4a std.Build.Cache: rename addPathPost to addDiscoveredPath 2026-09-16 13:12:47 -07:00
Andrew Kelley d142f63f89 std.Build.Cache: fix adding files
no longer adding unwanted padding bytes
2026-09-16 13:12:47 -07:00
Andrew Kelley d3231ad090 std.Build.Cache: get it compiling again 2026-09-16 13:12:46 -07:00
Andrew Kelley 0b561847c1 std.Build.Cache: make IsDirectoryAmbiguous an assertion not error 2026-09-16 13:12:46 -07:00
Andrew Kelley 872e8c8f7d std.Build.Cache: fix some compilation errors from rewrite 2026-09-16 13:12:46 -07:00
Andrew Kelley 9ad1a6be17 std.Build.Cache: implement is_directory and metadata_only 2026-09-16 13:12:46 -07:00
Andrew Kelley ec7805b867 WIP: rework std.Build.Cache
- implement std.Build functions:
  - `dependOnDirectoryMetadata`
  - `dependOnDirectoryContents`
  - `dependOnFileMetadata`
  - `dependOnFileContents`
- switch cache manifest to binary format. saves about 25% of file size,
  which is not a ton, but this is in the really hot path, so any amount
  we can reduce file system cache pressure is going to help a lot.
  - also means saving and loading is simpler - just copying bytes in and
    out of memory plus a tiny bit of validation.
- batch cache manifest memory allocations together. one big allocation
  for the entire manifest file contents, with the files hash map only
  tracking starting offsets for each entry, and the input files as a
  simple array list with the extra information needed for input files
  (so they can be lazily loaded only on cache miss)
- remove the manifest file size limit
- input files that have requested content to be loaded is loaded
  together into one big allocation rather than separately tracked.
- each file entry in the cache now tracks two additional bits:
  - kind: file or directory
  - tracking mode: contents or metadata
    - when tracking a directory, "contents" are considered to be the
      sorted list of file names contained in the directory (non recursive)
- rename "hit" to "check" and make it return enum instead of bool
- merge most "add...File" function variants together into one that has
  an "options bag" parameter.
- take advantage of async I/O when checking for cache hit to compute
  hashes concurrently. Care is taken to never cancel useful work, and
  never wait for unnecessary work to complete.

bonus:
- build.zig: use std.log for printing log messages
2026-09-16 13:12:46 -07:00
Andrew Kelley 166cf303b2 std.Build.Cache: update unit tests to new API 2026-08-19 12:39:37 -07:00
Andrew Kelley e8090258b5 frontend: more resistant to absolute paths
When using Compilation.Path, we already know the path prefix, so just
use that directly instead of taking a detour through absolute paths.

Also, when using whole cache mode, don't call
`addModuleTableToCacheHash` because it is redundant with the logic
in `PerThread.update` which iterates over `zcu.alive_files` and adds
those files discovered via `@import` to the whole cache manifest.
That was causing files relative to cwd to be added to cache manifest
rather than being relative to build_root.
2026-08-19 12:39:36 -07:00
Andrew Kelley 83d41cf04d add build_root to cache prefix directories 2026-08-19 12:39:36 -07:00
Andrew Kelley 9df1d1e5ed std.Build.Cache: add some more doomed assertions 2026-08-19 12:39:36 -07:00
Andrew Kelley 65b8b8b27b std.Build.Cache: remove deprecated APIs
improves Path hygiene in the compiler in some places

also includes an assertion that will probably nede to be removed
regarding absolute paths making it into the cache manifest
2026-08-19 12:39:36 -07:00
Andrew Kelley a68b5ee372 std.Build.Cache: introduce API for taking the files
ability to take ownership of the set of input files prior to
deinitializing a Manifest
2026-08-13 11:32:46 +02:00
Techatrix 59451cce93 std.Build.Cache: skip over prefixes that are the cwd
Any of the added cache prefixes may be the cwd itself. Skip them like
the null prefix.
2026-07-03 19:33:58 +02:00
Andrew Kelley 15f00d1756 std.Build.Cache: make Progress.Node for hits
Occasionally, two different Zig processes are waiting on the same
compilation artifacts. For example, if the user runs `zig build` for the
first time in two different terminals with the same version of Zig, one
of them will win the race on compiler_rt and start building it, while
the other process waits. Then they both use the same cache artifacts.

Now, the fact that this is happening is communicated to the user by
displaying it in a progress node during the checking for cache hit.
2026-07-01 10:16:22 +02:00
Andrew Kelley 779b6cc63c Maker: partially implement configurer cache invalidation
progress towards #35473
2026-06-29 23:50:20 -07:00