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

Can't [patch] the rust-s3 crate #9370

Closed
ericseppanen opened this issue Apr 17, 2021 · 9 comments
Closed

Can't [patch] the rust-s3 crate #9370

ericseppanen opened this issue Apr 17, 2021 · 9 comments
Labels
C-bug Category: bug

Comments

@ericseppanen
Copy link

Problem
I am using [patch.crates-io] to test out some modifications to upstream crates, and I find that one crate in particular (rust-s3) is unable to be patched this way. I have no idea why-- this method works fine on several other crates.

Steps

  1. Create a test crate, with this in its Cargo.toml:
[patch.crates-io]
# This is just the upstream source for the published crate
rust-s3 = { git = "https://github.com/durch/rust-s3.git" }

[dependencies]
rust-s3 = { version = ">= 0.26" }
  1. Run a cargo command, e.g. cargo build, cargo check, or cargo update. Any of them print:
warning: Patch `rust-s3 v0.27.0-rc4 (https://github.com/durch/rust-s3.git#ae166bad)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.

and the patched crate is not used in the build.

Possible Solution(s)

It's possible that there's something wrong with the rust-s3 crate that triggers this, but I can't figure out what it is.

Could this be related to #6827 ? I notice that the library name (s3) does not match the crate name (rust-s3).

Notes

Output of cargo version:

cargo 1.51.0 (43b129a20 2021-03-16)

The same behavior happens with cargo 1.53.0-nightly (65d57e6f3 2021-04-04).

@ericseppanen ericseppanen added the C-bug Category: bug label Apr 17, 2021
@Eh2406
Copy link
Contributor

Eh2406 commented Apr 17, 2021

So I think that the problem is the -rc4 witch marks this as a pre-release version. Meanwhile your dependency requirement ">= 0.26" does not allow pre-release versions. It is odd, but that is how Cargo has always treated pre-release. You have to opt into it to get a pre-release version. Yes, that does make it hard to use pre-release versions to test as you prepare for a release. The irony is noted.

I think there are 2 ways I can think of to get this working:

  • Point your patch to a branch/fork that has a non pre-release version. Like 0.27.0.
  • Change your requirement to allow pre-release versions. Like ">= 0.26.0-rc4".

@ericseppanen
Copy link
Author

Change your requirement to allow pre-release versions. Like ">= 0.26.0-rc4".

I get the same result if I use that string.

@ericseppanen
Copy link
Author

I also cloned the upstream repo and reset it to the last released version 0.26.3. Then I retried my test with:

[patch.crates-io]
rust-s3 = { git = "https://github.com/ericseppanen/rust-s3.git" }

[dependencies]
rust-s3 = { version = ">= 0.26" }

And I get the same result.

warning: Patch `rust-s3 v0.26.3 (https://github.com/ericseppanen/rust-s3.git#f30d1f59)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.

There are no longer any pre-releases in sight, so I don't think that can be the problem.

Thank you for the suggestion; it would be nice if that had been it...

@Eh2406
Copy link
Contributor

Eh2406 commented Apr 17, 2021

Sorry for the misdirection.
@ehuss any thoughts, is this related to #9352?

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2021

I think the versions in the suggestions were backwards. They should be:

  1. Specify the git dependency with a rev, tag, or branch that selects a 0.26.4 version.
  2. Change the version requirement to select a 0.27 prerelease such as "0.27.0-rc4"

The error message could definitely be a lot better here.

@ericseppanen
Copy link
Author

ericseppanen commented Apr 17, 2021

I can't get your suggestion # 1 (specify a rev, tag, or branch) to work. For example, using my fork that's reset to the previous non-prerelease rust-s3 release, this still fails:

[patch.crates-io]
rust-s3 = { git = "https://github.com/ericseppanen/rust-s3.git", branch = "master" }

[dependencies]
rust-s3 = { version = ">= 0.26.0" }

Adding rev = "fc78527" also fails. Setting the dependencies version to 0.26 or 0.26.3, also still fails.

The good news:

Your suggestion # 2 (name a prerelease version in the dependency string) does work. For example:

[patch.crates-io]
rust-s3 = { git = "https://github.com/durch/rust-s3.git" }

[dependencies]
rust-s3 = { version = ">= 0.27.0-rc4" }

It still works if I give it other valid prerelease versions, e.g. { version = "0.27.0-rc1" } works just as well. So at least I don't need to keep making updates each time there's a new -rc release.

Note the prerelease version given must actually exist-- I can't type { version = "0.26.0-rc" } because there is no such thing.

@ericseppanen
Copy link
Author

@ehuss, thank you for your help!

@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2021

The reason your first example doesn't work is that the 0.26 version on crates.io is 0.26.4. It's not clear where that version came from since it is not tagged in the git repo. The patch in your first example is pointing at 0.26.3. Cargo eagerly fetches the newer version (0.26.4) and thus skips the patch. The patch { git = "https://github.com/ericseppanen/rust-s3.git", branch = "master" } can be forced to use an older version with:

cargo update -p rust-s3 --precise 0.26.3

That should cause it to switch over to the patched version.

The way [patch] works is that it is an overlay on top of the crates.io index. When cargo checks the index for a version matching "0.26", it will see:

  • 0.26.0 - crates.io
  • 0.26.1 - crates.io
  • 0.26.2 - crates.io
  • 0.26.3 - github patch
  • 0.26.4 - crates.io

Cargo's resolver always fetches the "newest" semver-compatible version, so it goes with 0.26.4 in this case. Using cargo update with --precise you can force it to use an older semver-compatible version. Another option is to change your patched copy to be 0.26.4 (or 0.26.5 or whatever).

@ericseppanen
Copy link
Author

Good to know, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants