Skip to content

fix(macros-core): only track paths rustc can checksum - #4439

Merged
abonander merged 1 commit into
transact-rs:mainfrom
varunshahdev:macros-track-only-files
Oct 3, 2026
Merged

abonander merged 1 commit into
transact-rs:mainfrom
varunshahdev:macros-track-only-files

Conversation

@varunshahdev

Copy link
Copy Markdown
Contributor

Problem

With --cfg sqlx_macros_unstable, MtimeCacheBuilder::add_path passes every watched path to proc_macro::tracked::path. Some of those paths are not files:

  • In query/metadata.rs::load_env, each directory searched for .env that has no .env is registered as the directory itself. fix(macros): don't look for .env outside workspace聽#4282 bounds that walk to the workspace, but it still registers directories.
  • <manifest_dir>/sqlx.toml is registered even when it doesn't exist.

rustc can't checksum a directory or a missing file. Under cargo's -Z checksum-freshness it logs failed to compute checksum, omitting it from dep-info ... Is a directory (os error 21). The resulting dep-info entry has no checksum, so cargo considers the crate permanently dirty: it is recompiled on every build, even a no-op one.

That blocks the main reason to combine sqlx_macros_unstable with checksum-freshness: letting cargo rebuild a crate exactly when one of its .sqlx/query-*.json files changes.

Fix

Call proc_macro::tracked::path only when path.is_file(). The in-process MtimeCache still records every path, so its own invalidation is unchanged. The only cost is that rustc is no longer told about a .env or sqlx.toml that doesn't exist yet, so creating one later won't by itself trigger a rebuild. Before this change that case caused a rebuild on every build anyway.

Verification

I tested a single-crate project with one query!, built offline (SQLX_OFFLINE=true), using RUSTFLAGS="--cfg sqlx_macros_unstable" and CARGO_UNSTABLE_CHECKSUM_FRESHNESS=true on a 2026-09-22 nightly, with sqlx-macros-core 0.9.0 patched via [patch.crates-io]:

no-op rebuild no-op rebuild .sqlx JSON edited
0.9.0 Dirty (rebuilt) Dirty (rebuilt) Dirty
with this change Fresh Fresh Dirty (rebuilt)

Without sqlx_macros_unstable, the patched code is compiled out and behaviour is unchanged.

@abonander
abonander merged commit df46b41 into transact-rs:main Oct 3, 2026
147 checks passed
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