Surprising dependency resolution failure

I recently tried to add aws-sdk-s3 to a project which also uses octocrab, and encountered this error:

% cargo add aws-sdk-s3
    Updating crates.io index
      Adding aws-sdk-s3 v0.24.0 to dependencies.
             Features:
             + rt-tokio
             + rustls
             - native-tls
             - test-util
error: failed to select a version for `percent-encoding`.
    ... required by package `hyperx v1.3.0`
    ... which satisfies dependency `hyperx = "^1.3.0"` of package `octocrab v0.18.1`
    ... which satisfies dependency `octocrab = "^0.18.1"` of package `botanist-operator-cli v0.1.0-dev (/Users/owen/Development/botanist-app/operator-cli)`
versions that meet the requirements `>=2.1.0, <2.2` are: 2.1.0

all possible versions conflict with previously selected packages.

  previously selected package `percent-encoding v2.2.0`
    ... which satisfies dependency `percent-encoding = "^2.1.0"` of package `aws-http v0.54.1`
    ... which satisfies dependency `aws-http = "^0.54.1"` of package `aws-sdk-s3 v0.24.0`
    ... which satisfies dependency `aws-sdk-s3 = "^0.24.0"` of package `botanist-operator-cli v0.1.0-dev (/Users/owen/Development/botanist-app/operator-cli)`

failed to select a version for `percent-encoding` which could resolve this conflict

This surprises me, and I'd like some input into how to resolve it. Here's the source of my surprise:

error: failed to select a version for `percent-encoding`.
    ... required by package `hyperx v1.3.0`
    ... which satisfies dependency `hyperx = "^1.3.0"` of package `octocrab v0.18.1`
    ... which satisfies dependency `octocrab = "^0.18.1"` of package `botanist-operator-cli v0.1.0-dev (/Users/owen/Development/botanist-app/operator-cli)`
versions that meet the requirements `>=2.1.0, <2.2` are: 2.1.0

To me, this appears to say that percent-encoding 2.1.0 is satisfactory via the dependency chain rooted in octocrab. Then,

  previously selected package `percent-encoding v2.2.0`
    ... which satisfies dependency `percent-encoding = "^2.1.0"` of package `aws-http v0.54.1`
    ... which satisfies dependency `aws-http = "^0.54.1"` of package `aws-sdk-s3 v0.24.0`
    ... which satisfies dependency `aws-sdk-s3 = "^0.24.0"` of package `botanist-operator-cli v0.1.0-dev (/Users/owen/Development/botanist-app/operator-cli)`

This appears to me to be saying that percent-encoding 2.1.0 would be acceptable, even though it selected v2.2.0 instead.

Why is Cargo not resolving 2.1.0 here? What should I do to address this so that I can use both libraries?

Full dependencies:

[dependencies]
anyhow = "1.0.69"
async-trait = "0.1.66"
aws-sdk-s3 = "0.24.0"
clap = { version = "4.1.8", features = ["derive", "env"] }
http = "0.2.9"
jsonwebtoken = "8.2.0"
octocrab = "0.18.1"
secrecy = "0.8.0"
serde = { version = "1.0.156", features = ["derive"] }
serde_yaml = "0.9.19"
sqlx = { version = "0.6.2", features = ["runtime-tokio-native-tls", "postgres", "uuid", "offline"] }
tokio = { version = "1.26.0", features = ["rt", "macros", "rt-multi-thread"] }
uuid = { version = "1.3.0", features = ["v4", "serde"] }

It appears that hyperx does not declare semver-open dependency version constraints for some reason: Why do dependencies have upper bounds? · Issue #39 · dekellum/hyperx · GitHub. Dependency resolution is NP-Complete in general, and Cargo's solver does not attempt the backtracking required to handle non-open constraints.

You may be able to produce a working lockfile with some careful cargo update -p <package> --precise <version> usage, but I would try to avoid packages that do that in general.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.