Conceptcore
Incremental builds
Also called incremental build, incremental compilation, rebuild, up to date, out of date, minimal build, early cutoff, build cache, dirty bit, verifying traces.
An incremental build runs again only the steps whose inputs changed since the last build. The tool must find what changed, by file times or by content hashes, and must know every input of every step.
- Applies to
- core-languages
Idea
A full build runs every step. After a small edit, most steps would make the same outputs again. An incremental build runs again only the steps whose inputs changed, and keeps the other outputs from the last build.
The paper Build Systems à la Carte calls this property minimality: "A build system is minimal if it executes tasks at most once per build and only if they transitively depend on inputs that changed since the previous build."1 Minimality saves time, but it is safe only if the result is the same as the result of a clean build. To get both, a build tool must answer two questions for each step:
- What changed? The tool compares the inputs of the step now with the inputs at the last build. It can compare file modification times, or hashes of the content.
- What does the change touch? The tool follows the edges of the Build graph from each changed input to the steps that need it. A step that is not on such a path keeps its old output.
How it works
Modification times. POSIX make uses the modification times of files to decide if a target is out of date.2 GNU Make recompiles an object file if the source file, or any of the header files named as prerequisites, has a later modification time than the object file, or if the object file does not exist.3 The tool stores nothing of its own. The paper describes the times as a dirty bit that the file system keeps for Make: a write to a file makes the targets that depend on it out of date, and a build of a target makes it up to date.1
The run below builds a small C program with GNU Make, then makes three changes. touch util.h changes only the time of the header, but both object files depend on it, so make compiles both. Next, the script writes util.c again with a different return value, and gives the file a time in 2001, as a copy from a backup can do. The file is older than util.o, so make says that app is up to date, and the program still prints the old value 42. Only a later touch util.c makes make compile it.
d=$(mktemp -d)
cd "$d"
cat >util.h <<'END'
int util(void);
END
cat >util.c <<'END'
#include "util.h"
int util(void) { return 42; }
END
cat >main.c <<'END'
#include <stdio.h>
#include "util.h"
int main(void) { printf("%d\n", util()); return 0; }
END
cat >Makefile <<'END'
app: main.o util.o
cc -o app main.o util.o
main.o: main.c util.h
cc -c main.c
util.o: util.c util.h
cc -c util.c
END
make >/dev/null
echo '$ touch util.h; make'
touch util.h
make
echo '$ (write util.c again, with a time in 2001); make'
cat >util.c <<'END'
#include "util.h"
int util(void) { return 7; }
END
touch -d '2001-01-01' util.c
make
./app
echo '$ touch util.c; make'
touch util.c
make
./app
cd /
rm -rf "${d:?}"
$ touch util.h; make
cc -c main.c
cc -c util.c
cc -o app main.o util.o
$ (write util.c again, with a time in 2001); make
make: 'app' is up to date.
42
$ touch util.c; make
cc -c util.c
cc -o app main.o util.o
7
The paper says that Make requires that file timestamps "only go forward in time, which can be violated by backup software", and that you can fool Make with the command touch, so Make is minimal only if you do not do that.1
Hashes of the inputs. Another rebuilder keeps a record, for each target, of the hashes of the inputs at its last build. On the next build, it computes the hashes again. If one of them is different, the target is out of date. The paper calls this record a verifying trace.1 A time that goes back, or a touch without an edit, does not fool it, because the content decides.
A trace can also hold things that are not files. In Ninja, outputs implicitly depend on the command line that made them, so a change to the compiler flags rebuilds them.4 Ninja keeps the command lines in a log file, .ninja_log.4 The Go build cache accounts for changes to Go source files, compilers and compiler options.5
Early cutoff. When a step runs again and makes the same output as before, the steps after it do not need to run. The paper calls this early cutoff, and gives the example of a comment added to main.c: the compiler makes the same main.o, so main.exe does not need to be built again.1 A rebuilder that compares hashes gets early cutoff for free, because the hash of main.o did not change. In the comparison of the paper, Make and Excel do not support early cutoff, and Shake and Bazel do.1 A Ninja rule can set the variable restat: Ninja then checks the outputs after the command, and treats each output whose modification time did not change as though it never needed a build.4
Shared results. A verifying trace keeps only hashes. A constructive trace also keeps the output, so a tool can copy a result from a cache in place of running the step, and it can share the cache with other users.1 In the paper, Bazel uses constructive traces, and Shake and Ninja use verifying traces.1 This is the base of a shared build cache.
Finding the inputs. Each rebuilder is only as good as its list of inputs. A C file reads its headers through #include lines, and a makefile must name each header as a prerequisite. The GNU Make manual says that you must be careful to update the makefile every time you add or remove an #include, and shows the compiler option -M, which writes these rules for you.6 Ninja can read the same rules from the compiler after each compile, with deps = gcc.4 Cargo writes a dep-info file, with a .d suffix, next to each artifact, in a syntax like a makefile, so that other build systems can know when to run Cargo again.7
In languages
| Language | Verdict | Note |
|---|---|---|
| Python | Idiom | |
| C++ | Idiom | A std::map of rules and of traces. The standard library has no SHA-256, so a hash needs a library. Alternative: The Java example. |
| Java | Idiom | |
| C | Idiom | Arrays of times and of hashes per target. The standard library has no SHA-256, so a hash needs a library. Alternative: The Go example. |
| C# | Idiom | |
| JavaScript | Idiom | A Map from each target to its inputs, and the hash function of the crypto module of Node.js for the traces. Alternative: The Python example. |
| TypeScript | Idiom | As in JavaScript, with types for the rules and the traces. Alternative: The C# example. |
| Go | Idiom | |
| Rust | Idiom | A HashMap of rules and a HashMap of traces per target. The standard library has no SHA-256, so a hash needs a crate. Alternative: The Go example. |
| Kotlin | Idiom | Maps of rules and traces, with java.security.MessageDigest for the hash. Alternative: The Java example. |
| SQL | Idiom | A table of inputs per target with the hash at the last build, joined with a table of the current hashes, lists the targets that are out of date. Alternative: The Python example. |
| Bash | Idiom | The test operator -nt of the shell compares the modification times of two files, as make does. Alternative: The make run on this page. |
| PowerShell | Idiom | Get-FileHash computes a hash of a file, and the LastWriteTime property gives its time. Alternative: The C# example. |
| HTML | Does not apply | Markup has no build steps. |
| CSS | Does not apply | Style rules have no build steps. |
| Regular expressions | Does not apply | A pattern has no build steps. |
The examples run two rebuilders on the same graph: main.o from main.c and util.h, util.o from util.c and util.h, and app from the two object files. A file is a string, and the "compiler" drops comments. The first rebuilder compares modification times from a counter, as Make does. The second keeps the SHA-256 hashes of the inputs of each target from its last build. Each step of the table makes the same change to both, and prints the targets that each one builds again:
- After
touch util.h, the time rebuilder builds everything again, and the hash rebuilder builds nothing. - After a comment in
main.c, the hash rebuilder builds onlymain.o. The output is the same, soappkeeps its old trace: this is early cutoff. - After a copy of
util.cwith a different body and an old time, the time rebuilder builds nothing, and itsappno longer matches a clean build.
# Two rebuilders on one graph: file modification times (as in Make) and content hashes.
import hashlib
RULES = {
"main.o": ["main.c", "util.h"],
"util.o": ["util.c", "util.h"],
"app": ["main.o", "util.o"],
}
ORDER = ["main.o", "util.o", "app"]
SOURCES = {
"main.c": "int main(void) { return util(); }",
"util.c": "int util(void) { return 1; }",
"util.h": "int util(void);",
}
clock = 0
def tick():
global clock
clock += 1
return clock
def action(target, content):
# The compiler drops comments, so an object file depends only on the code.
parts = [content[dep].split("//")[0].rstrip() for dep in RULES[target]]
return target + "(" + " | ".join(parts) + ")"
def digest(text):
return hashlib.sha256(text.encode()).hexdigest()
def from_scratch(content):
values = {name: content[name] for name in SOURCES}
for target in ORDER:
values[target] = action(target, values)
return values["app"]
class Builder:
def __init__(self, by_hash):
self.by_hash = by_hash
self.content = {}
self.mtime = {}
self.traces = {} # target -> {dependency: its hash at the last build}
def write(self, name, text, mtime=None):
self.content[name] = text
self.mtime[name] = tick() if mtime is None else mtime
def dirty(self, target):
if target not in self.content:
return True
deps = RULES[target]
if self.by_hash:
seen = self.traces[target]
return any(seen[dep] != digest(self.content[dep]) for dep in deps)
return any(self.mtime[dep] > self.mtime[target] for dep in deps)
def build(self):
ran = []
for target in ORDER:
if self.dirty(target):
self.write(target, action(target, self.content))
self.traces[target] = {d: digest(self.content[d]) for d in RULES[target]}
ran.append(target)
return " ".join(ran) if ran else "-"
def clean(b):
for name, text in SOURCES.items():
b.write(name, text)
def touch(b):
b.mtime["util.h"] = tick()
def comment(b):
b.write("main.c", SOURCES["main.c"] + " // entry point")
def restore(b):
# A copy from a backup keeps its old time, older than util.o.
b.write("util.c", "int util(void) { return 2; }", mtime=1)
by_time, by_hash = Builder(False), Builder(True)
print("step".ljust(24) + "mtime".ljust(20) + "hash")
for label, edit in [("clean build", clean), ("touch util.h", touch),
("comment in main.c", comment), ("old util.c, old time", restore)]:
edit(by_time)
edit(by_hash)
print(label.ljust(24) + by_time.build().ljust(20) + by_hash.build())
for name, b in [("mtime", by_time), ("hash", by_hash)]:
print(name + ": app matches a clean build:", b.content["app"] == from_scratch(b.content))
step mtime hash
clean build main.o util.o app main.o util.o app
touch util.h main.o util.o app -
comment in main.c main.o app main.o
old util.c, old time - util.o app
mtime: app matches a clean build: False
hash: app matches a clean build: True
- Verdict: idiom. A dict maps each target to its inputs, and
hashlib.sha256gives the hash of a string. Builder.traceskeeps, for each target, a dict from each input to its hash at the last build.dirtycompares these hashes, or the times, with the current state.from_scratchbuilds all targets again from the sources, so the last two lines compare each incremental result with a clean build.
// Two rebuilders on one graph: file modification times (as in Make) and content hashes.
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.*;
import java.util.function.Consumer;
public class Main {
static final Map<String, List<String>> RULES = Map.of(
"main.o", List.of("main.c", "util.h"),
"util.o", List.of("util.c", "util.h"),
"app", List.of("main.o", "util.o"));
static final List<String> ORDER = List.of("main.o", "util.o", "app");
static final Map<String, String> SOURCES = Map.of(
"main.c", "int main(void) { return util(); }",
"util.c", "int util(void) { return 1; }",
"util.h", "int util(void);");
static int clock = 0;
static int tick() {
return ++clock;
}
// The compiler drops comments, so an object file depends only on the code.
static String action(String target, Map<String, String> content) {
List<String> parts = new ArrayList<>();
for (String dep : RULES.get(target)) {
parts.add(content.get(dep).split("//", 2)[0].stripTrailing());
}
return target + "(" + String.join(" | ", parts) + ")";
}
static String digest(String text) {
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(text.getBytes(StandardCharsets.UTF_8));
return HexFormat.of().formatHex(hash);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
static String fromScratch(Map<String, String> content) {
Map<String, String> values = new HashMap<>();
for (String name : SOURCES.keySet()) {
values.put(name, content.get(name));
}
for (String target : ORDER) {
values.put(target, action(target, values));
}
return values.get("app");
}
static class Builder {
final boolean byHash;
final Map<String, String> content = new HashMap<>();
final Map<String, Integer> mtime = new HashMap<>();
// A target maps to the hashes of its dependencies at the last build.
final Map<String, Map<String, String>> traces = new HashMap<>();
Builder(boolean byHash) {
this.byHash = byHash;
}
void write(String name, String text, int time) {
content.put(name, text);
mtime.put(name, time == 0 ? tick() : time);
}
boolean dirty(String target) {
if (!content.containsKey(target)) {
return true;
}
for (String dep : RULES.get(target)) {
if (byHash && !traces.get(target).get(dep).equals(digest(content.get(dep)))) {
return true;
}
if (!byHash && mtime.get(dep) > mtime.get(target)) {
return true;
}
}
return false;
}
String build() {
List<String> ran = new ArrayList<>();
for (String target : ORDER) {
if (dirty(target)) {
write(target, action(target, content), 0);
Map<String, String> seen = new HashMap<>();
for (String dep : RULES.get(target)) {
seen.put(dep, digest(content.get(dep)));
}
traces.put(target, seen);
ran.add(target);
}
}
return ran.isEmpty() ? "-" : String.join(" ", ran);
}
}
record Step(String label, Consumer<Builder> edit) {}
public static void main(String[] args) {
List<Step> steps = List.of(
new Step("clean build", b -> {
for (String name : List.of("main.c", "util.c", "util.h")) {
b.write(name, SOURCES.get(name), 0);
}
}),
new Step("touch util.h", b -> b.mtime.put("util.h", tick())),
new Step("comment in main.c", b -> b.write("main.c", SOURCES.get("main.c") + " // entry point", 0)),
// A copy from a backup keeps its old time, older than util.o.
new Step("old util.c, old time", b -> b.write("util.c", "int util(void) { return 2; }", 1)));
Builder byTime = new Builder(false);
Builder byHash = new Builder(true);
System.out.printf("%-24s%-20s%s%n", "step", "mtime", "hash");
for (Step s : steps) {
s.edit().accept(byTime);
s.edit().accept(byHash);
System.out.printf("%-24s%-20s%s%n", s.label(), byTime.build(), byHash.build());
}
System.out.println("mtime: app matches a clean build: " + byTime.content.get("app").equals(fromScratch(byTime.content)));
System.out.println("hash: app matches a clean build: " + byHash.content.get("app").equals(fromScratch(byHash.content)));
}
}
step mtime hash
clean build main.o util.o app main.o util.o app
touch util.h main.o util.o app -
comment in main.c main.o app main.o
old util.c, old time - util.o app
mtime: app matches a clean build: false
hash: app matches a clean build: true
- Verdict: idiom.
MessageDigest.getInstance("SHA-256")computes the hash, andHexFormat.of().formatHexturns the bytes into a string thatequalscan compare. getInstancedeclares a checked exception, sodigestwraps it in anIllegalStateException.- A
record Stepwith aConsumer<Builder>holds each edit, and the loop applies it to both builders.
// Two rebuilders on one graph: file modification times (as in Make) and content hashes.
using System.Security.Cryptography;
using System.Text;
var steps = new (string Label, Action<Builder> Edit)[]
{
("clean build", b =>
{
foreach (var name in new[] { "main.c", "util.c", "util.h" })
{
b.Write(name, Graph.Sources[name]);
}
}),
("touch util.h", b => b.Mtime["util.h"] = Graph.Tick()),
("comment in main.c", b => b.Write("main.c", Graph.Sources["main.c"] + " // entry point")),
// A copy from a backup keeps its old time, older than util.o.
("old util.c, old time", b => b.Write("util.c", "int util(void) { return 2; }", 1)),
};
var byTime = new Builder(false);
var byHash = new Builder(true);
Console.WriteLine($"{"step",-24}{"mtime",-20}hash");
foreach (var (label, edit) in steps)
{
edit(byTime);
edit(byHash);
Console.WriteLine($"{label,-24}{byTime.Build(),-20}{byHash.Build()}");
}
Console.WriteLine("mtime: app matches a clean build: " + (byTime.Content["app"] == Graph.FromScratch(byTime.Content)));
Console.WriteLine("hash: app matches a clean build: " + (byHash.Content["app"] == Graph.FromScratch(byHash.Content)));
static class Graph
{
public static readonly Dictionary<string, string[]> Rules = new()
{
["main.o"] = ["main.c", "util.h"],
["util.o"] = ["util.c", "util.h"],
["app"] = ["main.o", "util.o"],
};
public static readonly string[] Order = ["main.o", "util.o", "app"];
public static readonly Dictionary<string, string> Sources = new()
{
["main.c"] = "int main(void) { return util(); }",
["util.c"] = "int util(void) { return 1; }",
["util.h"] = "int util(void);",
};
static int clock = 0;
public static int Tick() => ++clock;
// The compiler drops comments, so an object file depends only on the code.
public static string Action(string target, Dictionary<string, string> content) =>
target + "(" + string.Join(" | ", Rules[target].Select(dep => content[dep].Split("//", 2)[0].TrimEnd())) + ")";
public static string Digest(string text) => Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(text)));
public static string FromScratch(Dictionary<string, string> content)
{
var values = Sources.Keys.ToDictionary(name => name, name => content[name]);
foreach (var target in Order)
{
values[target] = Action(target, values);
}
return values["app"];
}
}
class Builder(bool byHash)
{
public readonly Dictionary<string, string> Content = [];
public readonly Dictionary<string, int> Mtime = [];
// A target maps to the hashes of its dependencies at the last build.
readonly Dictionary<string, Dictionary<string, string>> traces = [];
public void Write(string name, string text, int time = 0)
{
Content[name] = text;
Mtime[name] = time == 0 ? Graph.Tick() : time;
}
bool Dirty(string target)
{
if (!Content.ContainsKey(target))
{
return true;
}
return Graph.Rules[target].Any(dep => byHash
? traces[target][dep] != Graph.Digest(Content[dep])
: Mtime[dep] > Mtime[target]);
}
public string Build()
{
var ran = new List<string>();
foreach (var target in Graph.Order)
{
if (Dirty(target))
{
Write(target, Graph.Action(target, Content));
traces[target] = Graph.Rules[target].ToDictionary(dep => dep, dep => Graph.Digest(Content[dep]));
ran.Add(target);
}
}
return ran.Count == 0 ? "-" : string.Join(" ", ran);
}
}
step mtime hash
clean build main.o util.o app main.o util.o app
touch util.h main.o util.o app -
comment in main.c main.o app main.o
old util.c, old time - util.o app
mtime: app matches a clean build: False
hash: app matches a clean build: True
- Verdict: idiom.
SHA256.HashDatahashes the bytes, andConvert.ToHexStringgives a string, so!=compares the content. Builderhas a primary constructor,class Builder(bool byHash), andDirtyusesAnywith a conditional expression for the two rebuilders.- The steps are an array of named tuples,
(string Label, Action<Builder> Edit), so the loop can deconstruct each one.
// Two rebuilders on one graph: file modification times (as in Make) and content hashes.
package main
import (
"crypto/sha256"
"fmt"
"strings"
)
var rules = map[string][]string{
"main.o": {"main.c", "util.h"},
"util.o": {"util.c", "util.h"},
"app": {"main.o", "util.o"},
}
var order = []string{"main.o", "util.o", "app"}
var sources = map[string]string{
"main.c": "int main(void) { return util(); }",
"util.c": "int util(void) { return 1; }",
"util.h": "int util(void);",
}
var clock = 0
func tick() int {
clock++
return clock
}
// action drops comments, so an object file depends only on the code.
func action(target string, content map[string]string) string {
var parts []string
for _, dep := range rules[target] {
code, _, _ := strings.Cut(content[dep], "//")
parts = append(parts, strings.TrimRight(code, " "))
}
return target + "(" + strings.Join(parts, " | ") + ")"
}
func digest(text string) [32]byte {
return sha256.Sum256([]byte(text))
}
func fromScratch(content map[string]string) string {
values := map[string]string{}
for name := range sources {
values[name] = content[name]
}
for _, target := range order {
values[target] = action(target, values)
}
return values["app"]
}
type builder struct {
byHash bool
content map[string]string
mtime map[string]int
// traces maps a target to the hashes of its dependencies at the last build.
traces map[string]map[string][32]byte
}
func newBuilder(byHash bool) *builder {
return &builder{byHash, map[string]string{}, map[string]int{}, map[string]map[string][32]byte{}}
}
func (b *builder) write(name, text string, mtime int) {
b.content[name] = text
if mtime == 0 {
mtime = tick()
}
b.mtime[name] = mtime
}
func (b *builder) dirty(target string) bool {
if _, ok := b.content[target]; !ok {
return true
}
for _, dep := range rules[target] {
if b.byHash && b.traces[target][dep] != digest(b.content[dep]) {
return true
}
if !b.byHash && b.mtime[dep] > b.mtime[target] {
return true
}
}
return false
}
func (b *builder) build() string {
var ran []string
for _, target := range order {
if b.dirty(target) {
b.write(target, action(target, b.content), 0)
seen := map[string][32]byte{}
for _, dep := range rules[target] {
seen[dep] = digest(b.content[dep])
}
b.traces[target] = seen
ran = append(ran, target)
}
}
if len(ran) == 0 {
return "-"
}
return strings.Join(ran, " ")
}
func main() {
steps := []struct {
label string
edit func(b *builder)
}{
{"clean build", func(b *builder) {
for _, name := range []string{"main.c", "util.c", "util.h"} {
b.write(name, sources[name], 0)
}
}},
{"touch util.h", func(b *builder) {
b.mtime["util.h"] = tick()
}},
{"comment in main.c", func(b *builder) {
b.write("main.c", sources["main.c"]+" // entry point", 0)
}},
// A copy from a backup keeps its old time, older than util.o.
{"old util.c, old time", func(b *builder) {
b.write("util.c", "int util(void) { return 2; }", 1)
}},
}
byTime, byHash := newBuilder(false), newBuilder(true)
fmt.Printf("%-24s%-20s%s\n", "step", "mtime", "hash")
for _, s := range steps {
s.edit(byTime)
s.edit(byHash)
fmt.Printf("%-24s%-20s%s\n", s.label, byTime.build(), byHash.build())
}
fmt.Println("mtime: app matches a clean build:", byTime.content["app"] == fromScratch(byTime.content))
fmt.Println("hash: app matches a clean build:", byHash.content["app"] == fromScratch(byHash.content))
}
step mtime hash
clean build main.o util.o app main.o util.o app
touch util.h main.o util.o app -
comment in main.c main.o app main.o
old util.c, old time - util.o app
mtime: app matches a clean build: false
hash: app matches a clean build: true
- Verdict: idiom.
sha256.Sum256returns a[32]bytearray. Arrays in Go are comparable with!=, so the traces store the arrays as they are. strings.Cutsplits the text at the first//and returns the part before it, which is how the "compiler" drops a comment.- The steps are a slice of structs with a label and a function, and each step runs on both builders.
Variations and related ideas
- Four rebuilders. The paper separates the rebuilder from the scheduler, and names four kinds of rebuilder: a dirty bit, verifying traces, constructive traces and deep constructive traces.1 Its Table 2 puts Make with the dirty bit, Ninja and Shake with verifying traces, and Bazel with constructive traces.1 Ninja combines the topological scheduler of Make with the verifying traces of Shake.1
- Build caches in language tools. The
gocommand caches build outputs for reuse in future builds.5 Cargo keeps the incremental output of rustc in anincrementaldirectory, a cache used to speed up later builds.7dotnet buildhas the option--no-incremental, which turns off incremental compilation and forces a clean rebuild of the dependency graph of the project.8 - Builds that do nothing. When nothing changed, the build must only check. Bazel exits in less than a second, with a message that the target is up to date, when you run
bazel builda second time without changes.9 The design goals of Ninja start with fast, instant incremental builds, even for large projects.4 - Incremental compilation in the compiler. A compiler can also keep its own state between runs, and recompile less than one file. This is a separate layer from the build tool, which decides which commands to run.
Pitfalls
- A missing input. If a header is not a prerequisite, an edit to it does not rebuild the files that include it, and the program mixes old and changed code. Let the compiler write the header dependencies.6
- Times that go back. A copy from a backup, an unpacked archive or a checkout can give a source file an old time. A rebuilder that uses times then keeps an old output, as in the run above. After such a copy, do a clean build.
- Flags that are not inputs. In make, only files have times, so a change to a variable such as
CFLAGSdoes not by itself make a target out of date.2 A tool that records the command line, such as Ninja, does rebuild.4 - Inputs outside the tool. The Go build cache does not detect changes to C libraries imported with cgo; you must clean the cache or use the
-aflag.5 Any tool can miss an input that it does not see, such as a system library or an environment variable. - Marking files up to date by hand. The
-tflag of GNU Make marks targets up to date by changing their modification times, without running the recipes.10 It can save a long build after a change to a comment in a header, but a wrong use leaves old outputs that look current.
Cost
A check by time reads one time per file, from the file system. A check by hash must read and hash every input, so a build that does nothing costs more. Tools reduce this cost by keeping the times and hashes from the last build, and computing a hash again only when a time changed. The traces also need space: a verifying trace holds hashes, and a constructive trace holds the outputs too.1
The saving depends on the shape of the graph. An edit to a header that many files include rebuilds them all. An edit to one source file rebuilds one object file and the link. Early cutoff can stop a chain of steps after the first one, when that step makes the same output again.1
History
Make was in use on Unix systems from 1975, and Stuart Feldman described it in 1979.11 It decides by modification times, and a makefile lists the dependencies.2 Later tools record more about each step. Ninja records the command line of each output,4 and Bazel records hashes of the files, and keeps a cache of outputs that a team can share.1 In 2018, the paper of Mokhov, Mitchell and Peyton Jones named the choice of rebuilder as one of the two main choices in the design of a build system, next to the scheduler.1
References
- Andrey Mokhov, Neil Mitchell and Simon Peyton Jones, Build Systems à la Carte, Proceedings of the ACM on Programming Languages 2 (ICFP), Article 79, 2018, 2.1 Make (Definition 2.1 and footnote 5); 2.3 Shake (early cutoff, Fig. 3); 2.4 Bazel; 2.5 Summary (Table 1); 4.2 The Rebuilder (dirty bit, verifying traces, constructive traces); Table 2; 7.1 Other Build Systems (Ninja)
- The Open Group Base Specifications Issue 8 (IEEE Std 1003.1-2024), make, DESCRIPTION
- GNU make manual (version 4.4.1), 2.3 How make Processes a Makefile, when an object file is recompiled
- The Ninja build system manual (version 1.13.1), Philosophical overview; Comparison to Make; Header dependencies (deps); Rule variables (restat); The Ninja log
- Go 1.26.5 source, cmd/go documentation (alldocs.go), Build and test caching
- GNU make manual (version 4.4.1), 4.14 Generating Prerequisites Automatically, first paragraphs; the -M option
- The Cargo Book, Build Cache, the incremental directory; Dep-info files
- Microsoft Learn, dotnet build, Options (--no-incremental)
- Bazel documentation, Artifact-Based Build Systems, a functional perspective (a second bazel build)
- GNU make manual (version 4.4.1), 9.4 Avoiding Recompilation of Some Files, the -t flag
- Stuart I. Feldman, Make, a program for maintaining computer programs, Software, Practice and Experience 9(4), pages 255 to 265, 1979, abstract
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 6NV5Q0 Edit this page History Report an error Markdown