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

How to force using a version via [patch] #584

Closed
dcecile opened this issue Jan 5, 2024 · 4 comments · Fixed by #586
Closed

How to force using a version via [patch] #584

dcecile opened this issue Jan 5, 2024 · 4 comments · Fixed by #586
Labels
enhancement New feature or request

Comments

@dcecile
Copy link

dcecile commented Jan 5, 2024

Is your feature request related to a problem? Please describe.
Following the cargo-deny book, I'm trying to set up this use case:

Maybe, even though the versions are supposedly incompatible according to semver, they actually aren't, and you can temporarily introduce a [patch] to force the crate to use a particular version for your entire workspace.

I want to do a simple version override where the new version already published on crates.io. For example, this is just one line in NPM.

But I can't find any info in the Cargo book or elsewhere about how to do this.

Describe the solution you'd like

It would be nice if this part of the cargo-deny book linked to a how-to article or had a Cargo.toml example.

If the only options are changing the "version dependency" to a "Git dependency", or forking the package causing the dependency, that might be nice to explain.

Describe alternatives you've considered
I tried this [patch] section...

[patch.crates-io]
windows-targets = { version = "0.52.0" }

...but it gives this error:

error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`

Caused by:
  patch for `windows-targets` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources

Additional context

Presumably related open Cargo issues:

@dcecile dcecile added the enhancement New feature or request label Jan 5, 2024
@Jake-Shadle
Copy link
Member

The wording is confusing, but it means that you can patch one or more of the crates that depend on a crate to relax/refine the version constraint without making any changes to the code itself.

@dcecile
Copy link
Author

dcecile commented Jan 15, 2024

Let's suppose I have the following dependency chain:

  • My package depends on...
    • A, which depends on..
      • B, which depends on...
        • C

And in this scenario, I want to use a different version of C.

So I could patch B, right? For someone who's never done this before, this means forking B and editing its Cargo.toml, then adding a line in [patch] to use my forked B (e.g. on GitHub) instead of the original B?

@Jake-Shadle
Copy link
Member

Yes.

@dcecile
Copy link
Author

dcecile commented Jan 15, 2024

Perfect, thank you!

@dcecile dcecile closed this as completed Jan 15, 2024
Jake-Shadle added a commit that referenced this issue Jan 19, 2024
This fixes 2 bugs that were originally opened on this repo but really
belong to the crate used to create crate graphs:

- EmbarkStudios/krates#60
- EmbarkStudios/krates#64

Resolves: #584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants