Skip to content

Unable to use workspace dependency in patch #15568

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

Open
tigerros opened this issue May 20, 2025 · 12 comments
Open

Unable to use workspace dependency in patch #15568

tigerros opened this issue May 20, 2025 · 12 comments
Labels
A-patch Area: [patch] table override A-workspaces Area: workspaces C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@tigerros
Copy link

tigerros commented May 20, 2025

I tried this code:

# empty project
[workspace.dependencies]
shakmaty = { git = "https://github.com/niklasf/shakmaty", branch = "master", default-features = false }

[patch.crates-io]
shakmaty = { workspace = true }

I expected to see this happen: dependencies that use shakmaty from crates.io get replaced by the git version.

Instead, this happened:

error: failed to parse manifest at `Cargo.toml`

Caused by:
  dependency (shakmaty) specified without providing a local path, Git repository, version, or workspace dependency to use

The error says I can use a workspace dependency.

Meta

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7

@tigerros tigerros added the C-bug Category: bug label May 20, 2025
@moxian

This comment has been minimized.

@ehuss ehuss transferred this issue from rust-lang/rust May 21, 2025
@ehuss ehuss added A-workspaces Area: workspaces A-patch Area: [patch] table override S-triage Status: This issue is waiting on initial triage. labels May 21, 2025
@epage
Copy link
Contributor

epage commented May 21, 2025

We should fix that error message to not mention workspace dependencies.

Could you help me understand your motivation for wanting to use a workspace dependency in a patch?

@tigerros
Copy link
Author

Could you help me understand your motivation for wanting to use a workspace dependency in a patch?

To make sure dependencies use the crate version defined in workspace.dependencies.

@epage
Copy link
Contributor

epage commented May 21, 2025

If its in workspace.dependencies, why not just have the original dependency inherit from it, rather than having some kind of dependency in there and then have the patch inherit it?

@tigerros
Copy link
Author

tigerros commented May 21, 2025

I don't understand. I can't inherit the workspace dependency for dependencies (which are not in the workspace) of workspace members. That's why I'm using a patch. Am I misunderstanding?

@epage
Copy link
Contributor

epage commented May 21, 2025

Ok, so you are patching a transitive dependency. You mentioned you want the version/source to be in workspace.dependencies. What value do you expect to gain from that?

Is this patch considered to be temporary or will you be maintaining it long term?

@tigerros
Copy link
Author

tigerros commented May 21, 2025

I gain the same value as when I specify shared dependencies in workspace.dependencies rather than duplicating it in each crate.

@epage
Copy link
Contributor

epage commented May 21, 2025

[patch] is only read in the root of the workspace, so there shouldn't be a need for duplicating a patches source.

We've had a lot of back and forth. If there is more, it might be good to provide a complete but minimal reproduction case which might help clarify some of the points of what you are doing.

@weihanglo
Copy link
Member

There is one nasty difficulty of supporting this: [patch] can also be in Cargo configuration (.cargo/config.toml), and configuration has no knowledge of what workspace is. That said, it can be interpreted as "whichever workspace cargo is building."

On the other hand, while what you're doing is not disallowed, I would suggest using crates.io dependencies in workspace.dependencies, and git repo patch in patch section instead. Benefit of this pattern:

  • Your package can still be able to publish to crates.io.
  • It is easier to spot whether you're using the same version of shakmaty across the entire dependency graph. Git dependencies are treated as completely different, and you might have chance getting duplicate versions of shakmaty.

@epage
Copy link
Contributor

epage commented May 21, 2025

Looks like we have #12031 for tracking the quality of that error message

@tigerros
Copy link
Author

tigerros commented May 21, 2025

Your package can still be able to publish to crates.io.

How can that be? I thought crates.io crates can't have git dependencies. I rely on features present only in the git repo.

[patch] is only read in the root of the workspace, so there shouldn't be a need for duplicating a patches source.

We've had a lot of back and forth. If there is more, it might be good to provide a complete but minimal reproduction case which might help clarify some of the points of what you are doing.

It's duplicated, just once. That still counts though. And this issue has a minimal reproduction case. The rest of the project is just empty. What I'm doing is just re-using the workspace dep in the patch like I would anywhere else.

@weihanglo
Copy link
Member

Your package can still be able to publish to crates.io.

How can that be? I thought crates.io crates can't have git dependencies. I rely on features present only in the git repo.

To clarify, I meant something like

[workspace.dependencies]
shakmaty = "0.27.3"


[patch.crates-io]
shakmaty = { git = "https://github.com/niklasf/shakmaty", branch = "master", default-features = false }

So your package will be ready to publish after shakmaty release a new version and you bump it. You don't need to modify the dependency declaration again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patch Area: [patch] table override A-workspaces Area: workspaces C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

5 participants