1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Per-worktree build stamp (#2759). Writes this crate's own
// `CARGO_MANIFEST_DIR` — an absolute path that is worktree-specific by
// construction — into a small file under `OUT_DIR`. The shared
// `CARGO_TARGET_DIR` freshness check (`scripts/check-target-freshness.mjs`)
// reads it back and compares it against `git worktree list` to answer "was
// this cached artifact last built by a *different, still-live* worktree?"
// instead of the static "a collision is structurally possible" heuristic it
// replaces. See that script's module doc for the full design, including how
// a missing/unreadable/stale-worktree stamp is handled (never as a reason
// to go red on a legitimately fresh tree).
//
// Deliberately dependency-free (std only) and best-effort: nothing here may
// ever fail the actual build, so every fallible step is swallowed rather
// than propagated with `?`/`unwrap`/`expect` (all denied by workspace
// lints, and rightly so for a build script's side channel).
//
// No `cargo:rerun-if-changed` is emitted, on purpose — but NOT because
// cargo reruns build scripts on every invocation by default; it does not.
// Cargo's documented default (absent any `rerun-if-*` directive) is to
// rerun a build script only when a file inside the package has changed
// since the last run that actually executed it. What this design relies on
// is narrower and still holds under that real default: the stamp always
// names the last worktree for which cargo actually re-ran this build
// script — and a no-op repeat build in the *same* worktree (nothing
// changed, so the script does not rerun) simply leaves the stamp naming
// that same worktree, which is still the correct answer. The stamp
// reflects the most recent worktree that caused a rerun, not every
// worktree that has ever built this package — that is enough for the
// freshness check's purposes.
//
// This crate is published to crates.io (see docs/releasing.md's "Publish
// surface: build.rs worktree stamp" section) — the `CARGO_TARGET_DIR` guard
// below keeps this a no-op off the shared-cache convention this tool exists
// for, so a downstream consumer of the published crate never gets a stamp
// file written under their own target dir for no reason.