Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCreate a separate libc_types crate for basic C types #1783
Conversation
sfackler
reviewed
Nov 3, 2016
| # Drawbacks | ||
| [drawbacks]: #drawbacks | ||
| - Adds an additional crate to the standard library. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Amanieu
Nov 3, 2016
Author
Contributor
Both in a sense, since libc is a (hidden) dependency of the standard library. But you are right, from a user's point of view this is just another crate on crates.io.
petrochenkov
reviewed
Nov 3, 2016
| pub type uint8_t; | ||
| pub type uint16_t; | ||
| pub type uint32_t; | ||
| pub type uint64_t; |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Nov 3, 2016
Contributor
Are fixed-width C types ever useful in Rust?
It's always more convenient to write native Rust uN instead of uintN_t.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
petrochenkov
Dec 20, 2016
Contributor
I expected this, but I thought may be there was some other reasons.
This comment has been minimized.
This comment has been minimized.
zackw
Jan 25, 2017
Contributor
In the hypothetical future situation where Rust knows how to talk directly to a C++ library instead of going through C wrapper functions, it will be necessary to match the mangled names of the C++ functions, and that is likely to involve making a distinction between uNN and uintNN_t, because in C land the uintNN_t types are "just" typedefs for whichever of the unpredictably-sized primitive integer types is the right match, and the name mangling uses the primitives, so for instance the mangled name of
extern "C++" foo(x: libc::uint64_t);
is _Z3foom on x86_64-linux but _Z3fooy on i686-linux.
steveklabnik
added
the
T-libs
label
Nov 3, 2016
This comment has been minimized.
This comment has been minimized.
|
I'm not really sure I quite understand the motivation for specifically the crate split itself here. Presumably crates could just use the I guess put another way, I'm not particularly clear on what the downsides of using libc are today. Could you clarify in the RFC what these downsides are? As a side note, as well the drawbacks and alternatives sections here are particularly bare, and the alternatives section doesn't seem to have a lot of thought put into it. Perhaps these sections could be fleshed out a bit more with some more information? For example "adds an additional crate to the standard library" to me is a pretty massive drawback as an incredibly large hammer. Why not crates.io? Why not part of libcore? Why not in libc itself? (for example...) |
This comment has been minimized.
This comment has been minimized.
|
The main motivation is being able to use the C types without linking to libc. This allows them to be used in environments that cannot use libc (kernels) or don't have a libc implementation (bare metal). As mentioned in the comment above, it seems that I didn't word the drawback correctly. Like |
nagisa
reviewed
Nov 4, 2016
| pub type c_longlong; | ||
| pub type c_ulonglong; | ||
| pub type intmax_t; | ||
| pub type uintmax_t; |
This comment has been minimized.
This comment has been minimized.
nagisa
Nov 4, 2016
Contributor
In case intmax_t is some primitive type not supported by rustc, what happens (i.e. what’s the behaviour of current liblibc)?
This comment has been minimized.
This comment has been minimized.
|
I would really like this to happen and my exact usecase for such a split is the Currently I prefer using |
This comment has been minimized.
This comment has been minimized.
comex
commented
Nov 4, 2016
|
What happened to
|
This comment has been minimized.
This comment has been minimized.
|
@comex Ah, nice catch, I seem to have forgotten about
As for the other types, they simply aren't currently supported by Rust. |
This comment has been minimized.
This comment has been minimized.
I don't fully agree with the motivation behind this point, depending on what's happening. If libc is available, there's no detriment linking against it. It'll get stripped if it's not used. If libc is not available, however, then you're on a whole separate target, in which case the libc crate itself can just give you a different API (because no library exists). That is, in my mind libc doesn't link to the actual libc for any platform that doesn't have one, so this problem wouldn't exist.
These are just type definitions, why would it need to be included in the standard library? Why not ship a
Technically, this is incorrect. If you have a crate that binds a C API crate, then that native library requires libc, so that dependency needs to be expressed. If the liblibc crate is "too big", then that's a problem that needs to be solved. |
This comment has been minimized.
This comment has been minimized.
FenrirWolf
commented
Nov 5, 2016
•
|
I think the motivation here is that the Let's say your target has a toolchain based on a minimal version of libc like newlib. If you try to link the crate solely for its type definitions, you will fail at compile-time if The case above is one that I'm personally familiar with, and perhaps that particular case could be addressed with explicit newlib support in the
I think what he means is that
That's what he's proposing. |
This comment has been minimized.
This comment has been minimized.
|
I'd like to see this as well, for building core-only programs with no libc that have FFI calls between Rust and C. As a minor nit/bikeshed, can we call it something shorter than |
This comment has been minimized.
This comment has been minimized.
|
Is this different from |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin Yes, this is basically a |
This comment has been minimized.
This comment has been minimized.
|
Hm so I may not quite be being clear here, so let me try again! The purpose of the Comments have been made about how libc today "requires too many libraries" or "pulls in too many symbols". This is not an inherent limitation to libc, but rather because libc is being lied to about its platform. The libc crates has been ported to a set of platforms, and it provides absolutely no guarantee of working on any other platform. If you've got a platform that doesn't have libc/librt/libutil then libc has not yet been ported to your platform. If such a platform masquerades as The intent of the libc crate design was specifically to avoid crates like Does that make sense? This is what I mean by the alternative above of just emptying libc of function declarations and just having types for these sorts of platforms. For example I could imagine an alternative to this RFC along the lines of:
That is, if
It does indeed! I explained this above, but to reiterate here this is not a limitation of the libc crate. The libc crate has only been ported to platforms with libraries like glibc/musl, it just hasn't been ported to any other platforms (but it certainly can be!)
These problems are all indicative of the work has not been done to port libc. That work can certainly be done, and it can be done at any time in the libc crate. Attempting to masquerade as a different platform and then seeing failures to me isn't a reason to abandon the libc crate entirely.
To clarify, this crate is being proposed to ship with the distribution, not on crates.io. Shipping a crate on crates.io doesn't require an RFC. |
This comment has been minimized.
This comment has been minimized.
|
I would argue that the The idea of
Not exactly. What I am proposing here is a crate on crates.io, however it is important that libc re-exports these types instead of using its own to avoid conflicting definitions of |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton so does this mean |
This comment has been minimized.
This comment has been minimized.
parched
commented
Nov 18, 2016
|
@Amanieu I think @alexcrichton's proposal sounds fine if you replace |
This comment has been minimized.
This comment has been minimized.
My point is that the purpose of My idea of
Indeed! |
This comment has been minimized.
This comment has been minimized.
|
@Amanieu if you could blacklist the relevant hosted features/scenarios/whatever for libc, that would solve the problem, right? |
This comment has been minimized.
This comment has been minimized.
What if you need |
This comment has been minimized.
This comment has been minimized.
jmesmon
commented
Nov 30, 2016
|
In the case where the types are mixed into the |
This comment has been minimized.
This comment has been minimized.
|
@cuviper I would assert that those are two separate targets, not one. In that sense libc would compile itself separately for both targets. @jmesmon there shouldn't be any reason to not want functions from libc. If functions don't exist on a platform then libc was miscompiled (or not ported). If the functions do exist then there's no cost to compiling them in. |
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Dec 15, 2016
•
|
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Dec 15, 2016
I disagree. It is useful to document statically in a toolchain-enforced way that no C library functions are being used by a crate, when that is the case. When looking at just the dependencies of a libc-based crate, one cannot tell whether it depends on C library functions or not. This matters for some embedding use cases. |
briansmith
referenced this pull request
Dec 15, 2016
Closed
Replace `ring::c` with use of the upcoming standard ctypes crate #380
This comment has been minimized.
This comment has been minimized.
To me the mixed ownership of the definitions of int, short, long etc between C, the cpu arch, and the OS, is nothing but a big legacy mess to avoid in the clean-slate systems I like to toy with in Rust.
Once can use |
This comment has been minimized.
This comment has been minimized.
I agree with your comment, personally. I'm not sure how to make progress on this RFC. In particular, there's a disconnect between the stated motivations, the mechanisms proposed, and the additional motivations being discussed on this thread. Partly because of this, the discussion is starting to go in circles. I think we need to narrow our focus. To my mind, the most immediate pain point in the discussion that requires some kind of structural change to fix is the Would a proponent of defining |
Ericson2314
referenced this pull request
Jan 8, 2017
Open
Check dependencies for no_std crates #38509
This comment has been minimized.
This comment has been minimized.
briansmith
commented
Jan 19, 2017
|
I tried to code up something for this, but IMO there's no good way to define a |
This comment has been minimized.
This comment has been minimized.
|
See also #1861 |
This comment has been minimized.
This comment has been minimized.
|
In particular, if we go this route---#1861 (comment), then std and libc can just alias that. I feel a lot better about putting that in core---it has nothing C specific in its name, and practically the effect is the same. |
This comment has been minimized.
This comment has been minimized.
|
These types should be in libcore. They're not really (or not only) C types, they are FFI/ABI types, which may also be used without libc. update (two months later): C types are complex. You can't simply define/declare them in several lines of code. For example, |
aturon
self-assigned this
Feb 13, 2017
This comment has been minimized.
This comment has been minimized.
|
The libs team discussed this RFC again during triage yesterday. The current consensus is to offer a canonical way of producing an "unknown, opaque type" (a better Once we make such a move, we'll be in a position to (1) redefine As such, I'm going to propose to close this RFC for the time being, and encourage further discussion on #1861. We can reopen the avenue proposed by this RFC if the opaque type direction doesn't pan out. @rfcbot fcp close |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 29, 2017
•
|
Team member @aturon has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
Can we move #1861 into FCP as well then? There hasn't been any on-topic activity there in over a month. |
emilio
referenced this pull request
Apr 11, 2017
Closed
use_core option to imply nostd and deny any ::std:: #628
rfcbot
added
the
final-comment-period
label
Apr 15, 2017
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Apr 15, 2017
|
|
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Apr 25, 2017
|
The final comment period is now complete. |
This comment has been minimized.
This comment has been minimized.
|
Looks like nothing new came up during FCP, so closing. |
alexcrichton
closed this
Apr 25, 2017
This comment has been minimized.
This comment has been minimized.
I’m late to the party, but |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin we already have different incompatible definitions of Edit: Although that last part might not be possible because of what you mentioned. Which means we'd need yet another breaking |
jethrogb
referenced this pull request
Jul 19, 2018
Open
Tracking issue for RFC 1861: Extern types #43467
This comment has been minimized.
This comment has been minimized.
|
New RFC to propose moving |
This comment has been minimized.
This comment has been minimized.
|
For people still following this thread: #2521 is now in FCP. |
jethrogb
referenced this pull request
Aug 26, 2018
Merged
Unify std::os::raw::c_void and libc::c_void via libcore #2521
elichai
referenced this pull request
Feb 18, 2019
Open
Tracking issue for RFC 2521, "Unify std::os::raw::c_void and libc::c_void via libcore" #53856
This comment has been minimized.
This comment has been minimized.
elichai
commented
Feb 18, 2019
|
I know this is pretty old and was argued to death. |
Amanieu commentedNov 3, 2016
Rendered