Skip to content

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

Closed as not planned
@bonsairobo

Description

@bonsairobo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions