-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New #[pkgid]
-based library naming is problematic
#10922
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
Comments
This is working as designed. Whereas you were controlling the library's name with The rust compiler used to infer the name "liblib-HASH-VERSION" for lib.rs, and does so still, so that behavior hasn't changed at all. I think in this case even the hash ids would have collided assuming the libs didn't have dependencies. You can't have the library be called something different than the package id if we want rustpkg to work in its current form. It uses the pkgid to know where to get what it needs to build. So if you have |
I see how this is troublesome, and as this is going to effect everybody I should have thought through how to transition existing packages to this system. At one point we discussed teaching the compiler to cope with the common repo conventions of "rust-foo" and "foo-rs", but even if we did that, forcing the library to have the same name as the github repo seems limiting (I don't think we've ever resolved the issue of how to have multiple libs in a single repo). Does anybody have any ideas about what we should do here? |
@metajack: Your own blog post recommends The standard way to deal with this in Go is to have the actual library be one level deeper in the repo, i.e. In any case, there are two issues I have with this current implementation:
I do not understand why this change was made. I mean, I fully understand the desire to make hashes computable externally instead of relying on an obscure (from the perspective of external tools) hashing algorithm operating over an unknown collection of metadata. But it seems like that could be accomplished without also making the library name dependent on this same piece of metadata. What's wrong with still using |
@brson: I'm not clear on exactly what limitations rustpkg has for figuring out the library name/hash given a URL. Surely it can't require just the URL, or the version would cause an issue. But assuming the path is still important, the same solution that Go uses could be employed here, in that my library would become That said, I think that making rustpkg happy should not impact rust as a whole. I should be able to use rust without having to worry about rustpkg if I don't want to. And by that I mean I should be able to continue using With this approach, all existing libraries would keep their existing name, and only have their hash change (which is perfectly acceptable). And libraries that ditch link attributes and use just |
Libraries that don't declare their name in lib.rs have always been screwed. That behavior hasn't changed. What has changed is that libraries that used to declare arbitrary names using link metadata now must do this with a different attribute. There is nothing preventing you from using rustpkg also didn't support link metadata, so nothing has really changed here with the choice between using semantically meaningful things and not. The semantically meaningful name is meaningful for use by rustpkg. If you can't use rustpkg, then what that name is seems irrelevant. Since you were using link metadata before, I assume you were not using rustpkg. I am not sure what the best thing to do is; this seemed to be the most logical way to improve from where we are. I probably agree with you about rustpkg's limitations. This patch does not try to change or address those. The only semantic difference introduced by this patch is that the crate hash no longer depends metadata from the crates dependencies. That can lead to more collisions, but how many more is not obvious to me. Is the issue just that you wish link metadata was now disallowed? |
Just to be clear, the reason I didn't disallow link metadata was because I figured it would cause the compile to fail to bootstrap. |
@metajack: I think you're completely missing the point. Actually, missing two very important points. The first is that all existing libraries are now screwed, unless they happened to use their library name as the name for the root rust file. Some libraries do, but a lot don't (and I believe the current recommended convention is to use The second is that In fact, the only reasonable solution I have available to me with this patch is to use a name that's almost my project repo, but with an extra path component at the end containing the real name of my library. This is lying about the package id just to satisfy the rules for library naming, and it feels completely unacceptable to me. The only reason why I should ever use See my response to @brson for how I wish this to work. Link metadata in order to produce a library name seems like the right approach. |
It's not a url since it doesn't start with a protocol, and it's required to be relative (no beginning |
@metajack: Surely you know what I meant by "URL" in that sentence. Does rustpkg allow you to use "#vers" in the import line? And what does it do if you don't specify a version? That's what I meant when I was asking how rustpkg deals with this. Saying |
Yes, rustpkg will downoad and build the correct version and allows it to be specified in the extern mod statement. If you don't specify one it just builds master. Or if you already have it downloaded, it just uses what you have. If you leave out a version from the pkgid, it is infered as 0.0, but the crate hash will be distinct from one with 0.0. I'm not sure if that's a huge issue. I wanted it to be simple to compute without logic for defaults and canonicalization. |
In IRC we came up with a potential solution which is to use |
@metajack: If your worries regarding making link metadata a compile error are still valid, then making it a warning would be better than nothing. |
I saw that @alexcrichton started a new snapshot that has pkgid in it. So we can probably do it once that is done. Maybe it is already :) |
cc me |
Current best candidate is Using the |
@kballard Existing packages are 'screwed' yes, because I'm considering though whether we should revert this and proceed more carefully. |
We could revert this change and just make a smaller, simpler change that just makes the hashes stable (add a command line flag to compute them), then regroup when we figure out what we're going to do with rustpkg. The |
@brson: I think we came up with a decent compromise in IRC today, which is what @metajack summarized here. The problem with existing libraries is more that the link attributes weren't disallowed, which meant existing libraries would compile without any errors or warnings, but would silently produce an unexpected library name. If we disallow the existing link attributes, and then modify |
@metajack: There's been no activity for 3 days, so it seems nobody has any objections to the listed best candidate. |
I am running |
This change extends the pkgid attribute to allow of explicit crate names, instead of always inferring them based on the path. This means that if your GitHub repo is called `rust-foo`, you can have your pkgid set your library name to `foo`. You'd do this with a pkgid attribute like `github.com/somewhere/rust-foo#foo:1.0`. This is half of the fix for #10922.
I believe this is now completely resolved. |
[`redundant_closure_call`]: handle nested closures Fixes rust-lang#9956. This ended up being a much larger change than I'd thought, and I ended up having to pretty much rewrite it as a late lint pass, because it needs access to certain things that I don't think are available in early lint passes (e.g. getting the parent expr). I think this'll be required to fi-x rust-lang#10922 anyway, so this is probably fine. (edit: had to write "fi-x" because "fix" makes github think that this PR fixes it, which it doesn't 😅 ) Previously, it would suggest changing `(|| || 42)()()` to `|| 42()`, which is a type error (it needs parens: `(|| 42)()`). In my opinion, though, the suggested fix should have really been `42`, so that's what this PR changes. changelog: [`redundant_closure_call`]: handle nested closures and rewrite as a late lint pass
This change to using
#[pkgid]
is causing a serious problem. Library names are now completely different. And I don't mean the hash. I mean the actual name on-disk. Not only that, but libraries without a#[pkgid]
will potentially be named completely incorrectly and collide on-disk.The library name on disk is
lib<name>-<hash>...
. Previously,<name>
came from the link args, so#[link(name="foo")];
producedlibfoo-<hash>...
. Now, it's apparently based off of the last path component of the#[pkgid]
. So if my library doesn't have a#[pkgid]
, and the root file is namedlib.rs
, then I'll end up withliblib-<hash>...
. And since the hash is also based off of the#[pkgid]
, then every single non-#[pkgid]
library with the same root source file will result in the same full filename (as both the library name and the hash are identical). That's really bad.If I go ahead and add a
#[pkgid]
, and use the recommended approach of using my github path as the pkgid, then I end up with a library that's potentially named incorrectly. For example, my github.com/kballard/rust-lua library wants to produceliblua-<hash>...
but instead with the#[pkgid]
it's nowlibrust-lua-<hash>...
.The text was updated successfully, but these errors were encountered: