Skip to content

Allow cargo tree to run despite native library conflicts #14512

Open
@eopb

Description

@eopb

Problem

cargo tree can be helpful for debugging dependency trees.

Take this simplified example Cargo.toml:

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
sqlx7 = { version = "0.7.0", package = "sqlx" }
sqlx8 = { version = "0.8.0", package = "sqlx" }

This crate depends on two major versions of sqlx, which in turn depend on two major versions of libsqlite3-sys. Since both of these libsqlite3-syss link sqlite3, cargo will refuse to build this project:

> cargo check
    Updating crates.io index
error: failed to select a version for `libsqlite3-sys`.
    ... required by package `sqlx-sqlite v0.7.0`
    ... which satisfies dependency `sqlx-sqlite = "=0.7.0"` of package `sqlx v0.7.0`
    ... which satisfies dependency `sqlx7 = "^0.7.0"` of package `hi v0.1.0 (/tmp/tmp.la1oWCFyGQ/hi)`
versions that meet the requirements `^0.26.0` are: 0.26.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.28.0`
    ... which satisfies dependency `libsqlite3-sys = "^0.28.0"` of package `sqlx-sqlite v0.8.0`
    ... which satisfies dependency `sqlx-sqlite = "=0.8.0"` of package `sqlx v0.8.0`
    ... which satisfies dependency `sqlx8 = "^0.8.0"` of package `hi v0.1.0 (/tmp/tmp.la1oWCFyGQ/hi)`
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

Since my project is often more complex than this example, it may not be immediately obvious where the dependency on the old version of libsqlite3-sys is coming from. To debug this, I attempt to run cargo tree -i [email protected].

Unfortunately, that isn't very helpful:

> cargo tree -i [email protected]
    Updating crates.io index
error: failed to select a version for `libsqlite3-sys`.
    ... required by package `sqlx-sqlite v0.7.0`
    ... which satisfies dependency `sqlx-sqlite = "=0.7.0"` of package `sqlx v0.7.0`
    ... which satisfies dependency `sqlx7 = "^0.7.0"` of package `hi v0.1.0 (/tmp/tmp.la1oWCFyGQ/hi)`
versions that meet the requirements `^0.26.0` are: 0.26.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.28.0`
    ... which satisfies dependency `libsqlite3-sys = "^0.28.0"` of package `sqlx-sqlite v0.8.0`
    ... which satisfies dependency `sqlx-sqlite = "=0.8.0"` of package `sqlx v0.8.0`
    ... which satisfies dependency `sqlx8 = "^0.8.0"` of package `hi v0.1.0 (/tmp/tmp.la1oWCFyGQ/hi)`
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

Proposed Solution

Ignore conflicts due to multiple dependencies linking the same native library when resolving for cargo tree

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-treeS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions