Skip to content
BIASED

Builds and dependencies

How source becomes an artifact: a build as a graph of targets, make with rules and timestamps, content-hash caching, dependency ranges resolved into lockfiles, reproducible builds, and how artifacts are versioned and stored.

A build is a graph of targets

A commit is an exact named tree of source. Between source and something a machine can run sits the build: compile, link, bundle, pack, and fetch other people's code. A shell script that always rebuilds everything is correct and wasteful — on a mid-size service a clean compile of 2 000 translation units can take 8–12 minutes while an incremental rebuild after editing one header may finish in under 30 seconds. A build tool replaces the always-everything script with a directed acyclic graph: each target has prerequisites and a recipe; the tool runs recipes in topological order and can schedule independent nodes on parallel workers (make -j8, Ninja, Bazel).

Worked example. Calculator sources: parse.c, eval.c, main.c. Edit eval.h (included by eval.c and main.c, not by parse.c). Rebuild set: eval.o, main.o, relink calc, re-run tests. parse.o is kept. If eval.o and main.o each take 4 s and the link takes 1 s, serial work is 9 s; with two cores the critical path is 4+1=54+1=5 s. The same graph that saves work also exposes parallelism.

Key idea. Describe inputs→outputs; after a change, only targets reachable from changed files need work. The remaining question is how the tool decides an input changed.

make and modification times

GNU make reads rules target: prerequisites plus a tab-indented recipe. To refresh a target it refreshes prerequisites recursively, then runs the recipe if the target is missing or any prerequisite has a newer modification time — Feldman's 1976 rule. make -n prints the plan without running it. Compiler flags -MMD -MP emit header dependency fragments so eval.h enters the graph without being hand-listed; without them, editing a header leaves stale .o files that still look up to date.

Timestamps are cheap and fragile. Clock skew between an NFS client and a build host, touch without a content change, and identical rebuilds that still look "newer" all force needless work. Content-hash systems (Bazel, Buck2, sccache remote caches) skip a downstream step when the new output bytes match the old — even if mtimes moved. Remote cache hit rates of 70–90% on a shared CI fleet turn a 10-minute clean build into a 1–2 minute cold-cache miss for most PRs; the graph still decides what to ask the cache for.

A practical habit: keep the graph honest. Generated code, protobuf stubs and string tables must be explicit nodes, not side effects of a silent script. Incomplete graphs are the main source of "works on my machine, fails in CI" after a supposedly incremental build.

Ranges and lockfiles

Application dependencies are declared as ranges (>=1.4,<2). A resolver picks one concrete tree today; tomorrow the same range may pick another when a maintainer publishes 1.5.0. A lockfile records the exact versions (and often content hashes) so every machine installs the same tree. Commit the lockfile; CI and production install from it; deliberate upgrades are a separate change that updates the lock and runs the test suite against the new graph.

Language tooling differs (uv.lock, package-lock.json, Cargo.lock, go.sum, Maven lock plugins) but the role is the same: pin the dependency graph that the build graph sits on. Without a lock, two CI runners resolving requests>=2.28,<3 an hour apart can ship different transitive OpenSSL bindings and produce "same commit, different bugs." Supply-chain practice pairs the lock with hash verification: refuse to install a package whose digest is not in the lock.

Ranges still matter for libraries you publish — consumers need room to resolve — but an application that ships as a service should treat the lock as part of the release. Audit tools (npm audit, cargo audit, OSV scanners) read the lock, not the range manifesto, when they report CVEs against what you actually run.

Reproducible builds

Two builds of the same commit produce the same bytes only if the whole input matches: sources, lockfile, toolchain versions, and flags that remove nondeterminism (timestamps via SOURCE_DATE_EPOCH, stable file order, no embedded host paths, sorted directory iteration). Embed a build date with date and two "identical" releases differ by eight bytes and break digest equality forever. The output is an artifact identified by version and content digest — the unit the rest of "build and ship" moves.

Storing artifacts in a registry or artifact store with immutable references closes the loop: the commit hash names the source; the artifact digest names the bytes built from it. Promote by digest, never by "whatever latest pointed at this morning." Retention policies (keep every digest for 90 days, keep release tags forever) are operational choices; content addressing is the invariant.

Scale sketch. A monorepo CI that rebuilds 400 packages on every commit spends ~0.02/min×12min×200commits/day≈0.02/min × 12 min × 200 commits/day ≈ 48/day on compute alone. Content-hash caching that skips 80% of packages drops that toward $10/day — the same economics as make's incremental rebuild, applied across machines.

What changed

Script always rebuilds Graph + mtime Graph + content hash
Correctness yes yes if graph complete yes if graph complete
Least work no approx. via mtime stops early on identical outputs
Reproducibility depends on env depends on env pairs well with pinned toolchains
Typical feedback minutes–hours seconds–minutes seconds with warm cache

The next topic, Container images, ships the program together with the user-space file tree it expects, as content-addressed layers — another Merkle tree sitting on top of the artifact digest you just produced.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.