sqlx
sqlx copied to clipboard
sqlx prepare should not clean sqlx
Bug Description
The minimal_project_recompile step of cargo sqlx prepare --workspace
always runs cargo clean -p sqlx
, because it depends on sqlx-macros
(assuming the macros
feature is enabled).
cargo sqlx prepare --database-url "postgres://postgres:password@localhost/example" --workspace
Cleaning [=============================] 1/1: sqlx, 0 files/folders cleaned
Surprisingly, cargo clean -p sqlx
can take several minutes in a large project, and I don't think it is necessary since sqlx
itself does not contain any query macros.
Edit: it seems like it was always the plan to exclude sqlx
from being cleaned: https://github.com/launchbadge/sqlx/pull/1802#issuecomment-1099801198
Suggestions
- Hardcode an exclusion filter for
sqlx
inout_of_workspace_dependents
. - Accept a list of exclusions from an environment variable, like
SQLX_PREPARE_NO_CLEAN="sqlx crate1 crate2"
? - Something else?
Minimal Reproduction
Reproducible in any workspace where the macros
feature is enabled for sqlx::query!
, and cargo sqlx prepare --workspace
is run.
E.g. https://github.com/cycraig/sqlx_prepare_bug.
Info
- SQLx version: 0.7.1
- SQLx features enabled:
["chrono", "ipnetwork", "json", "macros", "migrate", "postgres", "runtime-tokio-rustls", "uuid"]
(onlymacros
seems relevant here) - Database server and version: Postgres 14
- Operating system: MacOS
-
rustc --version
: 1.72.0
Edit: it seems like it was always the plan to exclude sqlx from being cleaned: https://github.com/launchbadge/sqlx/pull/1802#issuecomment-1099801198
It looks like this issue is now of interest to me. I can take a look, but yes excluding sqlx
from the clean should be fine
Just noting that for our relatively large workspace, cargo sqlx prepare
has gone from being a fairly quick operation to one that takes nearly 4 minutes to complete:
❯ time make db-sqlx-offline-data
Checking cargo sqlx-cli version
cargo sqlx-cli (0.7.3) is the same version as sqlx-cli (0.7.3)
Generating sqlx offline data
Removed 13 files, 334.6KiB total
Checking sqlx v0.7.3
<snip>
Finished dev [unoptimized + debuginfo] target(s) in 14.81s
query data written to .sqlx in the workspace root; please check this into version control
________________________________________________________
Executed in 230.85 secs fish external
usr time 248.45 secs 397.00 micros 248.45 secs
sys time 43.08 secs 196.00 micros 43.08 secs
The make command just runs:
cargo sqlx prepare \
--workspace --database-url "$$DATABASE_URL" \
-- --all-features --all-targets
Do you have a fairly large target dir (as in 10's of GBs)?
Yep, it's quite large:
❯ du -sh target
83G target
Cleaning that will likely drastically reduce the run time as a temporary workaround
I've been meaning to dig into cargo clean -p
more to see what all is slow there, but I've had very limited free time lately
Cleaning that will likely drastically reduce the run time as a temporary workaround
Oh yeah, nice! Did an rm -rf target
, recompiled, and now it's much faster indeed:
❯ du -sh target
2.2G target
❯ time make db-sqlx-offline-data
Checking cargo sqlx-cli version
cargo sqlx-cli (0.7.3) is the same version as sqlx-cli (0.7.3)
Generating sqlx offline data
Removed 0 files
Checking sqlx v0.7.3
<snip>
Finished dev [unoptimized + debuginfo] target(s) in 6.85s
query data written to .sqlx in the workspace root; please check this into version control
________________________________________________________
Executed in 12.95 secs fish external
usr time 20.38 secs 0.00 millis 20.38 secs
sys time 8.51 secs 1.01 millis 8.51 secs
Thanks for the tip!