Repository navigation
build: isolate the target dir when runtime/ diverges #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
269ec87
daea05e
672a6c1
fa2d907
67ea5ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,13 @@ leaves=":(exclude)crates/nub-cli :(exclude)crates/nub-native :(exclude)crates/nu | |
| # Both checks are deliberately broad (any path under a depended-on crate, not just | ||
| # *.rs): over-isolating on an irrelevant file costs one cold build; under-isolating | ||
| # risks the clobber. Depended-on = every workspace/vendored crate except nub-cli. | ||
| # `runtime/` is in the set for a different reason than the crates: the binary | ||
| # resolves `runtime/*.cjs` at run time from the tree that compiled nub-core (its | ||
| # baked CARGO_MANIFEST_DIR), so a shared-bucket binary loads whichever SHARER | ||
| # compiled last — a worktree with edited runtime files would test a sibling's | ||
| # copy, silently. Isolating on runtime divergence keeps every shared-bucket | ||
| # binary pointed at base-identical runtime content. (Observed: three worktrees' | ||
| # red/green verdicts flipped as siblings rebuilt the common bucket.) | ||
| # `-C "$root"` on the git queries so the pathspecs resolve from the repo root | ||
| # regardless of the CWD the wrapper was invoked from (a subdir would otherwise | ||
| # misread them). The final `exec cargo` still runs in the original CWD. | ||
|
|
@@ -105,17 +112,17 @@ diverged="" | |
| if [ -n "$base" ]; then | ||
| # shellcheck disable=SC2086 # $leaves must word-split into separate pathspecs | ||
| diverged=$(git -C "$root" diff --name-only "$base" -- \ | ||
| vendor/aube crates $leaves 2>/dev/null || true) | ||
| vendor/aube crates runtime $leaves 2>/dev/null || true) | ||
| fi | ||
| # shellcheck disable=SC2086 | ||
| untracked=$(git -C "$root" ls-files --others --exclude-standard -- \ | ||
| vendor/aube crates $leaves 2>/dev/null || true) | ||
| vendor/aube crates runtime $leaves 2>/dev/null || true) | ||
|
|
||
| # The content key names the bucket AND, when isolating, names the seed to clone | ||
| # from — so it is computed unconditionally. `ls-files -s` emits the staged blob | ||
| # OIDs, so this is a pure content hash of the depended-on crates. ~0.2s. | ||
| # shellcheck disable=SC2086 | ||
| key=$(git -C "$root" ls-files -s -- vendor/aube crates $leaves 2>/dev/null \ | ||
| key=$(git -C "$root" ls-files -s -- vendor/aube crates runtime $leaves 2>/dev/null \ | ||
| | shasum 2>/dev/null | cut -c1-12 || true) | ||
| if [ "$keyed" = 1 ]; then | ||
| bucket="$shared${key:+-$key}" | ||
|
|
@@ -188,14 +195,28 @@ if [ -n "$diverged" ] || [ -n "$untracked" ]; then | |
| else | ||
| target="$bucket" # shared fast path, content-keyed | ||
| why="shared bucket ${key:-none} — depended-on crate content" | ||
| # MIGRATION: content-keying renames the bucket, so on the first run after this | ||
| # change lands the warm legacy dir would be orphaned and every worktree would | ||
| # eat one cold build. Seed the new bucket from it (same CoW clone, ~0 cost). | ||
| # Self-retiring: the legacy dir is covered by the GC below, so once every live | ||
| # worktree has moved to a keyed bucket it ages out on its own. | ||
| if [ "$target" != "$shared" ] && seed_from "$shared" "$target"; then | ||
| why="$why (migrated from the legacy shared dir)" | ||
| fi | ||
| # A SHARED bucket is NEVER seeded from another bucket. Any other bucket's | ||
| # hashed content differs by construction (a matching key would BE this bucket), | ||
| # CoW clones preserve mtimes, and cargo's path-dep freshness check | ||
| # (LocalFingerprint::CheckDepInfo) compares mtimes rather than content — so a | ||
| # sharer whose checkout is older than the seeded dep-info would accept a | ||
| # foreign rlib as fresh: the phantom E0063 this keying exists to prevent, | ||
| # persisting inside a bucket other worktrees join. A key move therefore costs | ||
| # the FIRST worktree one cold build and everyone else joins warm — that is the | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cost accounting covers sharers but not isolated worktrees. Technical details# The re-key cold build is not confined to the first sharer
## Affected sites
- `scripts/rust-build.sh:204-207` — "A key move therefore costs the FIRST worktree one cold build and everyone else joins warm" accounts only for the shared branch.
- `scripts/rust-build.sh:222,227` — `mkdir -p "$target"` then `touch "$target"` make the brand-new, still-empty bucket the newest by mtime before cargo has produced a single artifact.
- `scripts/rust-build.sh:174-177` — `newest_bucket()` sorts `ls -dt` and filters only `.seeding`, so that empty bucket is the top hit.
- `scripts/rust-build.sh:189-194` — a diverged worktree's own `$bucket` is keyed by its index and therefore never exists on disk, so `newest_bucket()` is the seed source for essentially every isolated worktree.
- `scripts/rust-build.sh:140-166` — `seed_from` succeeds on an empty source (`cp -a src/. dst/` copies nothing and exits 0), so `$why` reports a successful seed that inherited nothing.
## Required outcome
- An isolated worktree does not adopt a bucket that has no artifacts in it yet, and the `(seeded from ...)` message is not printed when nothing was actually inherited.
## Open questions for the human
- Seeding from a bucket a sibling is *actively building into* pairs a fresh-looking fingerprint with a partial rlib — the same hazard `newest_bucket()`'s `.seeding` filter already names in its own comment. That exposure is pre-existing in kind, but deleting the shared-branch seed makes a from-scratch bucket the guaranteed state after every merge that moves the key. Is bounding it worth a warmth check (e.g. requiring a non-empty `deps/`) here, or is the window short enough to accept? |
||
| # designed price. (The isolated branch may seed foreign content because its | ||
| # target is PRIVATE and its just-edited divergent files carry fresh mtimes.) | ||
| fi | ||
|
|
||
| # `--print-target` resolves the target dir the SAME way a real build would and | ||
| # prints it, so callers that must locate the artifact afterwards (make | ||
| # install-dev symlinking nub-dev) follow the shared/isolated decision instead of | ||
| # hardcoding a path that is only right in one of the two cases. It exits HERE, | ||
| # before the mkdir/GC below, so it is a pure read — tooling that compares | ||
|
pullfrog[bot] marked this conversation as resolved.
Resolved
|
||
| # against it (the disk-reduction bucket sweep's positive control) must not | ||
| # materialize an empty bucket as a side effect of asking. | ||
| if [ "${1:-}" = "--print-target" ]; then | ||
| printf '%s\n' "$target" | ||
| exit 0 | ||
| fi | ||
|
|
||
| mkdir -p "$target" | ||
|
|
@@ -243,15 +264,6 @@ if [ "${NUB_BUILD_FG:-}" != "1" ] && [ "$(uname)" = "Darwin" ] \ | |
| qos="taskpolicy -c utility" | ||
| fi | ||
|
|
||
| # `--print-target` resolves the target dir the SAME way a real build would and | ||
| # prints it, so callers that must locate the artifact afterwards (make | ||
| # install-dev symlinking nub-dev) follow the shared/isolated decision instead of | ||
| # hardcoding a path that is only right in one of the two cases. | ||
| if [ "${1:-}" = "--print-target" ]; then | ||
| printf '%s\n' "$target" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # The machine-global rustc wrapper (make qos-global) now carries the GLOBAL | ||
| # CONCURRENCY SEMAPHORE, not just a QoS clamp, so this invocation must let it | ||
| # run. It previously blanked RUSTC_WRAPPER — sound when the wrapper only | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.