Skip to content

fix(control): stop rebuilding hearth-control on every cargo run - #47

Open
PermutationResearch wants to merge 1 commit into
fix/hearth-template-dbfrom
fix/console-rerun-path
Open

PermutationResearch wants to merge 1 commit into
fix/hearth-template-dbfrom
fix/console-rerun-path

Conversation

@PermutationResearch

Copy link
Copy Markdown
Owner

crates/hearth-control/build.rs always told Cargo to watch web/console/dist. Cargo treats a watched path that does not exist as changed: in fingerprint::find_stale_file, a failed paths::mtime_recursive returns StaleItem::MissingFile. So wherever the console had not been built, CI included, the build script reran and hearth-control recompiled on every cargo invocation.

Evidence

In #42's runs, the unit-test step recompiled hearth-control immediately after the build step had compiled it, with no source change in between:

Run 46578304787 build step unit-test step
attempt 1 (no cache) compiled hearth-control compiled it again, 29.35 s
attempt 2 (cache hit) compiled hearth-control compiled it again, 31.13 s

Change

Watch dist once it exists, and until then the web/console directory. Creating dist changes that directory's own mtime, which Cargo's recursive scan includes, so building the console later still triggers a rebuild. If neither exists, watch neither.

Running the old and new scripts on their own against three layouts:

Layout Old watches New watches HEARTH_CONSOLE_DIST
console not built (this repo, CI) dist, missing web/console console-missing, unchanged
console built dist dist the canonical dist path, unchanged
no web/console dist, missing nothing console-missing, unchanged

console-missing is watched in all cases, as before.

Trade-off

While dist is absent, any change under web/console (sources, node_modules) reruns the script and recompiles the crate. Cargo also walks that directory on each build. That is narrower than today's rebuild on every invocation, but it is not free on a checkout with node_modules installed and no dist.

Not yet verified

  • CI for this PR should show hearth-control compiled once, in the build step, and not again in the unit-test step.
  • No automated regression test: the behaviour lives in Cargo's fingerprinting, and a test would have to run nested cargo builds.

Stacked on #43 (fix/hearth-template-db).

🤖 Generated with Claude Code

build.rs watched web/console/dist unconditionally. Cargo treats a watched
path that does not exist as changed (fingerprint::find_stale_file returns
StaleItem::MissingFile when mtime_recursive fails), so wherever the
console had not been built, CI included, the build script reran and the
crate recompiled on every cargo invocation. In CI that cost about 30 s
per extra cargo command: the unit-test step recompiled what the build
step had just built.

Watch dist once it exists, and until then the console directory, whose
own mtime changes when a build creates dist. If neither exists, watch
neither. The embedded HEARTH_CONSOLE_DIST is unchanged in every layout.
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.

2 participants