launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.4k stars 1.27k forks source link

All database cargo features are enabled when `migrate` cargo feature is enabled #3196

Closed bonsairobo closed 6 months ago

bonsairobo commented 6 months ago

Bug Description

I am encountering unexpected behavior of the cargo features in this crate. I want to enable only the postgres and migrate features, but it seems to pull in all database features whenever migrate is enabled.

This is surprising because all of the database crates (sqlx-sqlite, etc) are optional and should only be enabled by their corresponding features. This is how the migrate feature is defined:

migrate = ["sqlx-core/migrate", "sqlx-macros?/migrate", "sqlx-mysql?/migrate", "sqlx-postgres?/migrate", "sqlx-sqlite?/migrate"]

My understanding of the ? in a cargo manifest is that it should not enable the feature before the ?, and only enable the feature following the ? if the parent crate is already enabled somewhere else. The behavior I observe is not consistent with this.

To be fair, this might be a cargo bug. I can't really tell.

Minimal Reproduction

cargo init --lib foo
cd foo
cargo add sqlx --no-default-features --features migrate
cargo check
rg "sqlite|mysql|postgres" Cargo.lock

Expected output: empty

Actual output:

468:name = "libsqlite3-sys"
898: "sqlx-mysql",
899: "sqlx-postgres",
900: "sqlx-sqlite",
976:name = "sqlx-mysql"
1017:name = "sqlx-postgres"
1055:name = "sqlx-sqlite"
1067: "libsqlite3-sys",

Info

abonander commented 6 months ago

Showing up in the Cargo.lock doesn't mean they're actually getting compiled

This is likely the same as #2964 which appears to be a result of the following Cargo bug: https://github.com/rust-lang/cargo/issues/10801#issuecomment-1874741198

bonsairobo commented 6 months ago

@abonander

Showing up in the Cargo.lock doesn't mean they're actually getting compiled

Interesting! I guess I'm not worried about this then.

This is likely the same as https://github.com/launchbadge/sqlx/issues/2964

This was the original issue I was running into as well, except I've got rusqlite in my dep tree instead of sqlsync. Sorry I didn't manage to find it in my search. For now, I can live with a workaround where I just downgrade rusqlite so the libsqlite3-sys versions match up, even though I'm not even using sqlx for SQLite.

Feel free to close this issue as a duplicate of #2964 .