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

Ignore errors when declaring a registry on path dependency #12807

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

w4
Copy link

@w4 w4 commented Oct 11, 2023

When depending on crate A from crate B, if crate A declares a registry on a path local dependency, cargo would attempt to resolve the registry name from crate B's config.toml, even though it would never be used and likely doesn't exist there.

It may be wishful thinking to open a PR for this in its current form, but it fixes the exact issue outlined in #12271. I'm happy to modify it if there's a more "correct" fix out there.

Environment

CMX2XM in cargo-issue-repro
❯ \cat ws/Cargo.toml
[workspace]
resolver = "2"
members = ["ws1", "ws2"]

CMX2XM in cargo-issue-repro
❯ \cat ws/ws1/Cargo.toml
[package]
name = "ws1"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

CMX2XM in cargo-issue-repro
❯ \cat ws/ws2/Cargo.toml
[package]
name = "ws2"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ws1 = { path = "../ws1", registry = "a" }

CMX2XM in cargo-issue-repro
❯ \cat leaf/Cargo.toml
[package]
name = "leaf"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ws2 = { git = "file:///Users/jordan/Code/cargo-issue-repro/ws" }

Before

❯ CARGO_LOG=trace cargo check
...
2023-10-11T20:47:59.716458Z  INFO cargo::ops::cargo_read_manifest: skipping malformed package found at `/Users/jordan/.cargo/git/checkouts/ws-a3d765f02ebb7e68/6b8487d/ws2`
...
error: no matching package found
searched package name: `ws2`
perhaps you meant:      ws1
location searched: file:///Users/jordan/Code/cargo-issue-repro/ws#6b8487d6
required by package `leaf v0.1.0 (/Users/jordan/Code/cargo-issue-repro/leaf)`

After

❯ /Users/jordan/Code/cargo/target/debug/cargo check
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s

When depending on crate A from crate B, if crate A declares a `registry`
on a path local dependency, cargo would attempt to resolve the registry
name from crate B's config.toml, even though it would never be used and
likely doesn't exist there.
@rustbot
Copy link
Collaborator

rustbot commented Oct 11, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 11, 2023
@weihanglo
Copy link
Member

Thanks for being interested in this.

For direct dependencies, if the registry configuration is missing, Cargo errors out. It seems a bit unfortunate that the behavior of transitive and direct dependencies can't be consistent after this changes.

I'll propose this to the Cargo team for discussion. Before that, if you have any more thoughts please comment on the issue instead.

@epage
Copy link
Contributor

epage commented Oct 24, 2023

btw you link to #12271 but I think you meant #12272

@weihanglo
Copy link
Member

Close as the current behaviour is expected. See #12271 (comment) and #12272 (comment) for more.

Do let us know if there is something impossible to be resolved by those approaches mentioned. Thank you.

@weihanglo
Copy link
Member

weihanglo commented Oct 25, 2023

Re-opened for #12272. To move forward, we need some more tests. This is how people usually do :

  • The first commit will have tests demonstrating the current bad behavior.
  • The following commits will fix the bad behavior and the tests.

That make the intention clear when reviewing or reading the Git commit history.

You might want to add some new tests around this registry_incompatible_with_git test. Feel free to ping me if you have questions.

@bors
Copy link
Contributor

bors commented Dec 1, 2023

☔ The latest upstream changes (presumably #13080) made this pull request unmergeable. Please resolve the merge conflicts.

@weihanglo
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 28, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2024

☔ The latest upstream changes (possibly 081d7ba) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants