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

fix: correct replacing source name #138

Closed
wants to merge 1 commit into from
Closed

fix: correct replacing source name #138

wants to merge 1 commit into from

Conversation

DCjanus
Copy link

@DCjanus DCjanus commented Jul 28, 2020

fix: #137

@nabijaczleweli
Copy link
Owner

nabijaczleweli commented Jul 29, 2020

This... doesn't look right. Take for example the test you edited: it no longer fully resolves down to tralternative, stopping at the registry it originally resolved the URL/name for; why? What final cargo install invocation are you seeing versus what are you expecting to see?

@DCjanus
Copy link
Author

DCjanus commented Jul 29, 2020

Example config file:

[source.crates-io]
replace-with = "sjtu"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

In this case, origin code, cargo-update would try to cargo install --registry sjtu --version x.y.z my_package, with message Updating registry "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index", which would be failed. Because there is no sjtu registry, it's just a proxy for crates-io.

With this PR, that would be cargo install --registry crates-io --version x.y.z my_package and show me this Updating registry "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index", and works fine in my case.

In fact, registry in cargo install, it means to install package from crates-io or your private registry. And replace-with would not replace registry identity but registry field, which is for public registry proxy.

@DCjanus
Copy link
Author

DCjanus commented Jul 29, 2020

If you are trying to reproduce it, try this:

  1. put my config file in last comment to you cargo home
  2. cargo install --version 3.0.0 cargo-update
  3. cargo install-update cargo-update

@nabijaczleweli
Copy link
Owner

Thanks for the details, they've allowed me to verify the implementation and this seems like a cargo regression from nightly-2019-08-10-x86_64-unknown-linux-gnu, with nightly-2019-09-10-x86_64-unknown-linux-gnu being the first regressed version I found that exhibits this

I'm going to open an issue on the cargo repository and drink now

@nabijaczleweli
Copy link
Owner

I also came across (well, "came across", I wrote multiple comments and a 6-commit implementation, maybe I'm just old) #128 (comment), which was illuminatory:

  • for some time now, cargo install --registry NAME requires registries.NAME.index instead of source.NAME.registry (the documentation was updated on 3 Dec 2019 in rust-lang/cargo@dd8f7d8, but nightly-2019-08-10 works, nightly-2019-09-10 already doesn't),
  • for things to work As Expected, we need to follow the Source Replacement-style overrides in source.NAME.{registry,replace-with} and specify the registry we resolved to, so
  • for cargo to understand what the fuck we're talking about, the registries.NAME.index and source.NAME.registry values need to match.

I saw cargo install --index URL in the cargo source which'd let us avoid the naming and just use the URLs we deal in anyway but it's only 2 months old, so no dice.

I'll write some documentation when I'm less angry and more sober. Thanks again for your testcases, and, mayhap more importantly, persistence.

@nabijaczleweli
Copy link
Owner

Can you try adding this to your config:

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

and running an update operation again?

That's what I documented to work in cef1717, and a test result from you would be great.

@DCjanus
Copy link
Author

DCjanus commented Jul 30, 2020

Sad to say this: this don't work with me.

Here is my config file:

[source.crates-io]
replace-with = "sjtu"

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

I've tried cargo install-update --all, and got this:

Couldn't get registry for cargo-edit: Couldn't find appropriate source URL for https://github.com/rust-lang/crates.io-index in C:\Users\DCjanus\.cargo\config (resolved to "sjtu").

@DCjanus
Copy link
Author

DCjanus commented Jul 30, 2020

Oh, what a mistake I've made!

I've took a wrong title, it should be source replacement rather than alternate registry.

@DCjanus DCjanus changed the title fix: correct alternative registry name fix: correct replacing source name Jul 30, 2020
@nabijaczleweli
Copy link
Owner

Your entire config unfortunately needs to be:

[source.crates-io]
replace-with = "sjtu"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

[registries.sjtu]
index = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

Can you try that instead?

@VitalyAnkh
Copy link

VitalyAnkh commented Jul 30, 2020

Can you try that instead?

I met the same problem with @DCjanus, and when I try this config, after running cargo install-update -a, I got

Couldn't get package repository: Couldn't read /home/vitalyr/.cargo/registry/index/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b (index directory for https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index): No such file or directory (os error 2).

So this config doesn't solve the problem.

Actually there are many guides for replacing the official crates.io-index with sjtu's mirror in Chinese Internet, which guide people to set the same .cargo/config with @DCjanus 's. It' s not a good choice to force users to edit their config to use cargo-update.

cargo-update is really awesome, why not improve it by accepting this pr?

@nabijaczleweli
Copy link
Owner

Because, well, it doesn't actually solve the underlying problem (that being: cargo's stability guarantees are bullshit) (and also it's kinda subtly wrong in what it produces, but that's beside the point).
It works entirely by accident because sources.crates-io is the default and so is registries.crates-io.

What's the output of find .cargo/registry/ -maxdepth 2 -type d for you, @VitalyAnkh? Does running cargo install --registry sjtu lazy_static (ignore the error), then running cargo install-update -a again fix the problem?

@nabijaczleweli
Copy link
Owner

Documentation released in v4.1.0, but I'm open to further troubleshooting if your MIA isn't permanent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source replace broken
3 participants