Skip to content

fix: let cargo decide freshness for scripts with path dependencies - #162

Open
MatthewYe wants to merge 1 commit into
fornwall:mainfrom
MatthewYe:fix/path-dependency-cache
Open

fix: let cargo decide freshness for scripts with path dependencies#162
MatthewYe wants to merge 1 commit into
fornwall:mainfrom
MatthewYe:fix/path-dependency-cache

Conversation

@MatthewYe

Copy link
Copy Markdown

Fixes #122.

rust-script's binary cache freshness check compares the cached binary's creation time against the script file and the generated manifest, so a change in a path dependency's sources never invalidates the cached binary — the script keeps running the old dependency code until the script file itself changes or --force is passed. Minimal repro: a script with dep = { path = "dep" }, run it, edit dep/src/lib.rs, run again → the old value is printed.

Fix

manifest::has_path_dependencies() parses the manifest and detects path entries under dependencies / dev-dependencies / build-dependencies (including target.* tables). When it finds any, the cache short-circuit is skipped for that script: cargo then decides freshness — a no-op when nothing changed, a rebuild when a dependency changed. Scripts without path dependencies keep the existing fast path.

Alternative considered: stat the path-dependency trees and compare max mtimes. Rejected — walking arbitrary trees on every run is potentially expensive, and letting cargo decide is exact (it already tracks dependency fingerprints).

Tests

  • New tests/scripts/path-dependency-cache.script: writes a script plus a path dependency, runs it, edits the dependency, runs it again, expects v1 then v2. It prints v1 twice on current main and passes with the patch.
  • cargo test green, cargo fmt --check green, ./tests/scripts/test-runner.sh green.
  • Note: local clippy (rustc 1.98) reports 3 pre-existing lints elsewhere in the crate; they reproduce on unmodified main, unrelated to this change.

The binary cache freshness check compares only the script file and the
generated manifest mtimes; path dependency sources are invisible to it, so
a cached binary keeps running stale dependency code (issue fornwall#122). Detect
path dependencies in the manifest and skip the short-circuit for them:
cargo then no-ops when everything is fresh and rebuilds when a dependency
changed.

Adds a regression test under tests/scripts (runs the same script twice with
a modified path dependency in between).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Caching Behaviour with Path Dependencies

1 participant