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.52k stars 1.28k forks source link

Sqlx depend on libsqlite3-sys if `sqlite` feature is disabled #3556

Closed LuckyTurtleDev closed 1 month ago

LuckyTurtleDev commented 1 month ago

Bug Description

Sqlx depend on libsqlite3-sys if sqlite feature is disabled.

Minimal Reproduction

❯ mkdir sqlx-test
❯ cd sqlx-test
❯ cargo init

add the following dependecies to the Cargo.toml

matrix-sdk = { version = "0.7.1", default-features = false, features = ["native-tls", "e2e-encryption"], optional = true }
sqlx = { version = "0.8.2", optional = true, default-features = false, features = ["runtime-tokio", "migrate", "postgres", "macros"] }
❯ cargo run
    Updating crates.io index
error: failed to select a version for `libsqlite3-sys`.
    ... required by package `rusqlite v0.30.0`
    ... which satisfies dependency `rusqlite = "^0.30.0"` of package `matrix-sdk-sqlite v0.7.0`
    ... which satisfies dependency `matrix-sdk-sqlite = "^0.7.0"` of package `matrix-sdk v0.7.1`
    ... which satisfies dependency `matrix-sdk = "^0.7.1"` of package `sqlx-test v0.1.0 (/home/lukas/test/sqlx-test)`
versions that meet the requirements `^0.27.0` are: 0.27.0

the package `libsqlite3-sys` links to the native library `sqlite3`, but it conflicts with a previous package which links to `sqlite3` as well:
package `libsqlite3-sys v0.30.1`
    ... which satisfies dependency `libsqlite3-sys = "^0.30.1"` of package `sqlx-sqlite v0.8.2`
    ... which satisfies dependency `sqlx-sqlite = "=0.8.2"` of package `sqlx v0.8.2`
    ... which satisfies dependency `sqlx = "^0.8.2"` of package `sqlx-test v0.1.0 (/home/lukas/test/sqlx-test)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "sqlite3"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `libsqlite3-sys` which could resolve this conflict

Additional Info

Looks like this only happen if the migrate is enabled.

Info

CommanderStorm commented 1 month ago

This is a bug in the way cargo resolves dependencys. Please see https://github.com/launchbadge/sqlx/issues/3211

The workaround would be to match up the libsqlite3-sys versions as suggested in the Cargo error.

LuckyTurtleDev commented 1 month ago

thanks, for the fast feedback. sadly the other version is out of my control.

LuckyTurtleDev commented 1 month ago

a small hack to workaround this issue is to use [patch.crates-io], to patch one libsqlite3-sys version to not use the c dependency anymore.

Cargo.toml:

[patch.crates-io]
libsqlite3-sys = { path = "./dummy-libsqlite3-sys" }

dummy-libsqlite3-sys/Cargo.toml:

[package]
name = "libsqlite3-sys"
version = "0.30.1"

[features]
default = []
bundled = []
pkg-config = []
unlock_notify = []
vcpkg = []

dummy-libsqlite3-sys/src/lib.rs:

//! Hack, due cargo bug