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

Allow cargo tree to run despite native library conflicts #14512

Open
eopb opened this issue Sep 7, 2024 · 2 comments
Open

Allow cargo tree to run despite native library conflicts #14512

eopb opened this issue Sep 7, 2024 · 2 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-tree S-triage Status: This issue is waiting on initial triage.

Comments

@eopb
Copy link
Contributor

eopb commented Sep 7, 2024

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

@eopb eopb added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Sep 7, 2024
@eopb
Copy link
Contributor Author

eopb commented Sep 7, 2024

@rustbot label Command-tree

@epage
Copy link
Contributor

epage commented Sep 9, 2024

cargo tree is showing the results from the resolver but in this case, the resolver is failing.

We could potentially solve this by having cargo tree identify that the resolve failed and then running a second, in-memory-only, resolve that disabled links handling. There is the potential for this to make things quite messy due to puncturing through abstractions and risky by having cases that must fail, pass.

If we were to do that, we'd then need to also handle the UX side of this. Kind of like if we solved #10096 as requested, we'd be documenting the command to be showing one thing but we'd instead be showing something else.

If the problem is with the error reporting, we are hopeful that we'll be able to improve that with a new resolver that is actively being worked on. Our issue for that is #5284.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-tree S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants