Skip to content
BIASED

Builds and dependencies

Block 1 of 5~2 min

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.

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