sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

sqlx-cli and cargo-watch

Open chaoky opened this issue 1 year ago • 4 comments

sqlx prepare is firing chmod events making it impossible to use with cargo-watch, files with queries are not necessarily affected, only lib.rs and anything inside bin, I've tried a few file structures but could still be a coincidence.

Paths updated: [
  PathOp { path: "[...]src/lib.rs", op: Some(CHMOD), cookie: None },
  PathOp { path: "[...]src/bin/serve.rs", op: Some(CHMOD), cookie: None },
  PathOp { path: "[...]src/bin/export.rs", op: Some(CHMOD), cookie: None }
]

Minimal Reproduction

  • install cargo-watch and sqlx-cli
  • run cargo watch --why -x 'sqlx prepare'

Info

  • SQLx cli version: 0.7.3
  • Operating system: linux
  • rustc --version: 1.72.0-nightly

chaoky avatar Jan 30 '24 19:01 chaoky

I am also seeing this issue with watchexec.

JadedBlueEyes avatar Jul 01 '25 17:07 JadedBlueEyes

any news? need a way to combine both

deknowny avatar Oct 03 '25 10:10 deknowny

why even --check triggers file changes

deknowny avatar Oct 03 '25 10:10 deknowny

The first problem is reliably getting the compiler to run. If you run cargo check but no project files have changed, Cargo won't do anything. Of course, we need the macros to run to generate updated metadata (which is needed even when running --check).

The second problem is getting Cargo to only recompile what's absolutely necessary. Our original strategy was to run cargo clean sqlx to invalidate any crates that depend on it, but that caused sqlx itself to recompile, as well as any crates in the graph that depend on it but don't actually use the proc macros.

Then we had an issue cargo cleaning workspace crates because it'd wipe all incremental compilation artifacts.

So instead we just touch project files to update the mtime which causes an incremental recompile of the crate.

There's lots of other alternatives we've tried but weren't happy with. All you have to do is look through the history of the following file to see everything we've tried: https://github.com/launchbadge/sqlx/blob/main/sqlx-cli/src/prepare.rs

I'm happy to discuss any improvements over the status quo.

abonander avatar Oct 05 '25 01:10 abonander