Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bonsairobo opened this issue Apr 11, 2024 · 2 comments
Labels

Comments

@bonsairobo
Copy link

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

  • SQLx version: 0.7.4
  • SQLx features enabled: migrate
  • Database server and version: Postgres 14.9 (or none!)
  • Operating system: NixOS (Linux 6.1.69)
  • rustc --version: 1.76
@bonsairobo bonsairobo added the bug label Apr 11, 2024
@abonander
Copy link
Collaborator

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: rust-lang/cargo#10801 (comment)

@bonsairobo
Copy link
Author

@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 #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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants