-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Accept hyphen in crate name in place of underscore #2775
Comments
Cargo is somewhat agnostic between I'd personally prefer to not accept both |
Makes sense, and I don't have a strong preference myself. I saw this comment from @steveklabnik and figured this would be a step toward tooling that reflects the conventions we would like developers to use. Is there a rationale for crates.io vs cargo behaving differently from each other?
Fair, but I would rather see |
I don't really know why crates.io is agnostic, it wasn't originally and I think that was a patch added after the fact, would have to track that down. Yeah it's easier to not have to remember, but to me it's more of a downside as it's disguising what's actually happening under the hood. |
The crates.io change was rust-lang/crates.io@89bc5dd. |
The current behavior of crates.io is defined by RFC 940:
|
I'd like to re-open this issue, I think this is a bug and we should fix it. (Maybe we can talk about it in a cargo meeting).
At first glance, this makes sense, but I think it doesn't hold as much water when you consider:
In contrast, users who accidentally add |
Reopened. I have also come to feel much more strongly about this in the past year. |
I also agree this is worthwhile to fix. Implementation-wise this won't be easy though, I think, as it'll require changes to the crate index. The changes in Cargo itself after that, though, are likely nominal. |
@alexcrichton That would be a problem, why isn't it sufficient to change how we match the dependency name against the index file to be neutral to underscores (e.g. retry if there's no file with the characters swapped)? (It'd be better if the index were normalized, but that seems quite challenging). |
Right now we don't load the entire index in-memory and we currently also don't try to browse the entire index, rather given a crate we drill into exactly which file it's supposed to be. If we have |
Makes sense, so I think what we should do:
Is a divergence between the name in the lock and the toml going to be a problem? EDIT: Also I'd like to write the PR for this to get more acquainted with cargo's codebase :) |
Yeah that sounds like it could work! I think we'll have to maek sure that a |
Is there a better way of doing this then brute force? With out changing the index in ways that brack older cargos / exiting projects? |
Brute force take an exponential |
Make index lookup robust to _ vs -, but don't let the user get it wrong. This does a brute force search thru combinations of hyphen and underscores to allow queries of crates to pass the wrong one. This is a small first step of fixing #2775 Where is best to add test?
Why not go further and normalise all names to use hyphens |
Because the index wuld need to have both names so that pre-normalise cargo and post-normalise cargo can find it, and that makes for 2 sources of truth. |
No it wouldn't if deployed via a new version of Cargo. Unfortunately this would not be backwards compatible (i.e. old versions of Cargo would require correct |
A much nicer solution would have been to restrict crate names to a whitelist of characters that contains only one of those two symbols from day 1. Alas, time travel is not really an option. |
The "workaround" is incredibly simple: you can do |
Since crates.io already does not accept two packages with just TL;DR: Why do we have to care if ignoring doesn't lead to problems? In fact, it is even feasible to force change everything existing to BTW, I'm a bit confused. Are we talking about crate names or package names, or are they the same thing? |
That is the goal, and we've solved the problem in both rustc and crates.io but not in cargo, which is why this issue is open. |
One complication is Alternative Registries, the existing RFC allows registries to have packages that only differ by Even if we decide to break such (niche) uses of Alternative Registries, we will want a grace period. Some time where it will build with the wrong If someone has a way to make this work, I am open to helping make it happen. |
I don't think we want crates.io to allow packages that only differ by |
I've posted https://internals.rust-lang.org/t/pre-rfc-unify-dashes-and-underscores-on-crates-io/13216/13. It's becoming more clear to me that this doesn't need an RFC, but I've posted the pre RFC anyway. I don't actually think the exponential growth for names with a large number of separators is a problem. In those cases we can traverse the index trie, looking for both separators whenever there is one, and splitting the search if both exist. Note that this will not cause exponential growth unless there actually are crates with that combination of separator: it's unlikely that |
10 minutes? |
there isn't one with the underscore name. crates.io does not accept an underscore name if there is already one with the hyphen name. |
If this helps the discussion, I'm a new user to Rust as well and coming from other languages, the ability for a package name and the source code referring to that package name within the same context to differ without being explicit is baffling (at least until you google it and end up in a thread like this one). Moving around in a large project where rust might exist alongside many languages, having to remember that particular quirk about Rust libraries is definitely going to be exhausting in the long term. |
Since there are so many popular crates with On the other hand it would forbid it in using in context like |
Aren't we heading to an overkill here? Perhaps package name conversion to underscore is not something you would realize immediately, but it would be the responsibility of the package developer anyway. Packages can always specify I don't know what's the original rationale of allowing underscores, but if we were to start all over, it might be more reasonable to have cargo only take the substring before the first hyphen as the lib crate name (hence the futures-preview case). But now that we are already at this (and it is almost idiomatic to suffix binding crates with |
By the way, should we rename this issue to package name instead of crate name? |
Just for reference, Python Package names can also differ in In fact, they take this quite a bit further: Any arbitrary sequence of |
I would think "Python does this" is pretty strong evidence that it's a terrible idea, given how awful Python's packaging story is! |
Hey now, we don't language bash here. It's all tradeoffs. |
Crates.io currently accepts hyphens for crates that use underscores, both in the web interface and in the API.
Cargo does not, but should.
The text was updated successfully, but these errors were encountered: