-
Notifications
You must be signed in to change notification settings - Fork 21
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
Roadmap: move cty into the libc repo #14
Comments
Have you considered the alternative of just adding those types to |
Not much, yet. The bar for adding those to I suspect that once we get this right for the Implementation-wise, we probably want to avoid duplicating the maintenance of all of this. So what will happen is that |
What do you think about moving Then whitelisted targets can implicitly reexport (or override some of them) types from the submodule, and users of not-supported targets will have to explicitly specify the types from Eventually, in order to achieve a complete concistency:
Later we can go deeper and let a user build only "the C types" out of the |
|
… and has been stabilized aiming for 1.64. |
I talked with @japaric on Discord, and we agreed on moving the
cty
crate into thelibc
repo. This should get it the same kind of testing aslibc
, and get some more hands maintaining this crate (e.g. adding support for new targets in a backwards compatible way).We could stop there.
However, there have been a couple of issues open in the past about addressing the use case of just using C types, without bringing in the whole
libc
(rust-lang/rust#36193 , rust-lang/rust#47027, rust-lang/libc#881, rust-lang/libc#375 , rust-lang/libc#1244 ).For libraries doing this, it would be great if these types were also the same C types that
libc
uses, so that if they expose them in their API, a dependency that does uselibc
internally can just use them to interface withlibc
(andstd::raw
, etc.).This is something that would require review by the libs team, because:
cty
as the way to obtain C types,cty
would become a dependency oflibstd
via thelibc
crate.Iff we were to do that, there is one aspect of
cty
's design that differs fromlibc
s and that is worth calling out:libc
is empty on unsupported platforms, whilecty
is not.The
cty
crate provides some types on all platforms, past, present, and future ones. This seems like a no brainer for, e.g.,int16_t
. C implementations do not need to provide this type, so one design would be to only conditionally provide it. But if a C implementation provides this type, there is only one way in which it could be provided AFAICT, and that istype int16_t = i16;
[0]. So the design decision of always providing this type, which is whatcty
does, seems fine to me.However,
cty
also provides other C types on all platforms, likessize_t
(#13 ) orintptr_t
(see CHERI comments by @gankro and @Amanieu : rust-lang/unsafe-code-guidelines#52 (comment)), where the argument that there is only one single way in which C could provide this is less clear.If we make
cty
a dependency oflibc
, it would be unfortunate to have to perform a breaking change in thecty
crate (and thereforelibc
), if we ever add a platform in which some of these default types are incorrect. We might be able to get away with this breaking change then, because the platform wasn't officially supported before, therefore we would be breaking something that was unstable. But if, for example, we decide to not providessize_t
by default anymore on unsupported platforms, we will probably end up breaking a lot of people usingxargo
to build unsupported platforms as a consequence.The safest design is to make
cty
empty on unsupported platforms, that is, we would need to manually vetto new platforms intocty
support. However, some users want "reasonable" C types in unsupported platforms (e.g. rust-lang/libc#1244). In that PR, my recommendation was to allow that behind some cargo feature. That is, when the user enables a feature incty
, if the platform is unsupported, we would expose some "reasonable" C types (depending on arch, etc.) instead of having the crate be empty.cc @SimonSapin @denzp
[0] I suppose that if the platform has padding bits or trap representations in the
int16_t
type, theni16
would probably do so as well - I'm not 100% sure what we guarantee about this in the Rust side.The text was updated successfully, but these errors were encountered: