-
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
Cargo allows you to have a different name in [lib]
and [package]
when publishing
#6827
Comments
Overall I've always found the |
I think it is fairly common, I found about 569 crates on crates.io which do this. An additional 476 crates only differ in It might be worthwhile to peruse that list to get a better understanding why some people do this. I fear some of them are done because of crates.io namespace collisions.
This isn't always true. Things such as crate renaming can use different names. Crate renaming should also provide a workaround to avoid the multiple rlib candidate error. I'm wondering if there would be a way to provide a better error message? |
I use this infrequently but to what I consider desirable effect.
|
Right, but that kinda makes it worse, since the impression given off by this feature is that "the package name is the crate name, unless you explicitly rename it", which isn't true. The lib name is the crate name, unless you explicitly rename it.
Hmm, this seems to be a valid use case. We should at least warn in cases where it's more than just underscores, though. |
@ehuss do you happen to still have the code that generated this list...? asking for a friend |
I don't remember for sure, but I have the source for all the crates.io crates extracted locally. I then have a small rust script which uses Here, I'll just recreate it real quick: |
Thanks a ton! |
I wonder if we should try and fix this sooner rather than later to avoid more of it happening. At least with a warning. It might also help to just improve diagnostics around this situation. |
Just wanted to chime in that the "package.name != lib.name" is useful when you're dealing in both rlib and cdylib; if my package is called
|
I recently ran into this and found it useful to have different package and lib names. In this case it turns out possum was already taken, but there's no reason not to use possum as the lib name but possum-db for the package. https://crates.io/crates/possum-db |
As a user, I find it confusing when maintainers do not match package names to lib names and would consider it a bad practice that should only be used in exception cases, like what dtolnay said above. This is more common in the python ecosystem (since you have to explicitly state both) and I have appreciated that its not done in the Rust community as a general rule. There isn't much we can do about this now because of compatibility but I think once we have #12235, we should have a warning discouraging this practice for general use. |
Problem
In Cargo, currently the crate name you use in
[dependencies]
marks where the crate is supposed to come from; it matches thepackage.name
key in the dependency'sCargo.toml
.The crate name you use in
extern crate foo
orfoo::
has to match the actual on-disk compiled artifact name. This is not the package name, but is instead thelib.name
key in the dependency'sCargo.toml
.If these don't match, you can have unexpected behavior (being unable to use crates by the name you'd expect them to use) as well as nonlocal bugs where one transitive dependency can break another by choosing the same
[lib]
Steps
package
keys but the samelib
keymultiple rlib candidates
error:Possible Solution(s)
I'm not actually sure if this is a bug: Having this ability doesn't seem completely useless. And for unpublished git/path packages the
lib
name does matter.It may be worth forbidding crates with a
lib.name
that doesn't matchpackage.name
from being published, after checkingcrates.io
for any offenders. https://github.com/messense/rustc-test is one (and is how I discovered this bug, we've been confused about a libtest thing for a while and it seems like this crate is the culprit)Notes
Output of
cargo version
: cargo 1.34.0-nightly (5c6aa46 2019-02-22)The text was updated successfully, but these errors were encountered: