Skip to main content

Module content_hash

Module content_hash 

Source
Expand description

Content-hash primitive: blake3 of a file’s bytes (#891).

soldr-daemon, FastLED/fbuild, and standalone zccache all obtain their daemon identity/discovery through running-process, and all three hit the same failure in dev: two builds sharing one home root rendezvous on the same daemon pipe + pid file, each sees the other as “stale-version”, and displaces it on every invocation — a displace-stale war that wedges the compile daemon. The shims are already version-namespaced; the daemon identity is not. Rather than reimplement isolation in each consumer, this module provides the shared primitive: a content hash of a file, so a dev build can stamp its own identity with "<version>-<first-16-hex of blake3_file(current_exe)>". Distinct dev builds → distinct identities → no cross-build displacement. (Full root-cause + evidence: zackees/soldr#2352.)

§Why the bytes, and why mmap the file (not the loaded image)

  • Hash the bytes, not the path string. Path-string hashing returns the same value across rebuilds → no isolation. The file’s contents change every build → the identity changes every build (isolating same-version rebuilds), which is the whole point.
  • mmap the file, do NOT hash the in-memory mapped image. The loaded module is mutated by ASLR base relocations, the resolved IAT, and live .data/.bss, so it differs from the file and differs every run (ASLR) → effectively a nonce → non-reproducible identity. blake3::Hasher::update_mmap_rayon on the file is page-cache-warm (the exe just executed) → memory-speed, no read() copy, multi-core. A 20 MB binary is ~1–3 ms this way (vs ~20 ms for a naive read), paid at most once per build (compute the stamp once and propagate the value down the process tree — see the issue for the client/daemon agreement).

Structs§

Hash
The blake3 digest type, re-exported so callers of blake3_file can name the return type without taking their own blake3 dependency. An output of the default size, 32 bytes, which provides constant-time equality checking.

Functions§

blake3_file
blake3 of the file’s bytes at path (open → mmap → hash, multi-core).