-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Clean up crate type names to fix dylib vs staticlib confusion #153863
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-cargoRelevant to the cargo team, which will review and decide on the PR/issue.Relevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-cargoRelevant to the cargo team, which will review and decide on the PR/issue.Relevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
FCP merge

Rust supports a number of crate types to control whether we are building a binary or a library, and what kind of library. The
dylibandstaticlibcrate types are named very similarly, so it is easy to assume that they also behave in a similar way, with the only difference between dynamic vs static linking. However, this is far from true:staticlibcreates a C-style static library that can be deployed as an artifact and linked without any further rustc involvement;dylibis basically a dynamicrlib, i.e., it still needs a bunch of Rust-specific processing until it becomes a regular C-style dynamic library (or static library, or binary). The dynamic-linking equivalent tostaticlibiscdylib. Overall, the main library crate types are arranged as follows:rlib*dylibstaticlibcdylib(* @bjorn3 points out that
rlibisn't fully the same as a Rust-stylestaticlib, so take this table with a grain of salt... it may be a good thing thatrlibis not calledrstaticlib.)Needless to say, this is quite confusing. See https://rust-lang.github.io/rfcs/1510-cdylib.html for some history of how we got here. Also note that
libis essentially an alias forrlib(but not deprecated). The documentation just says that it's the most suitable library format for the current target, which makes sense -- it's thebinvslibdistinction. In that sense, the most confusing name among them all isstaticlibas it is the only one where the lack of ac/rprefix somehow means "C-style". OTOH, in the "do what I want" sense,dylibis confusing for the reasons spelled out in the RFC. Ultimately I think the only recourse here is to be more explicit: if you care about the actual linking details (and not just about "bin" vs "lib"), then please just spell out whether you want something that behaves like a normal C-style library (cdylib,cstaticlib) or not. In practice, you'll almost certainly want a C-style library, but due todylibexisting (and to a lesser extent due tolibexisting), that can't be the meaning of "no prefix".I think we should clean this up, by renaming
dylibtordylibandstaticlibtocstaticlib. (We did a straw poll for whether we should do only some of the renames, and the results were fairly clear, see Zulip.) Concretely, the plan would be:rdylibbehaves like the existingdylib, and the new namecstaticlibbehaves like the existingstaticlib.dylib, for the reasons spelled out above and in the aforementioned RFC.cstaticlibonly exists for consistency. So maybe we should only warn againstdylib. I don't think we have to fully commit to a concrete plan for this yet, it's going to be at least a year until we actually deprecate anything anyway.With all of this done, the table would look like
rlib*rdylibcstaticlibcdylibMuch better :)
This is a pretty big change so I expect it will need FCP (with t-compiler and t-lang).