-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Move universal libc types to the root #1244
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
While this refactoring is correct for the targets that we currently have implemented, it isn't necessary correct for all targets that we might want to support. Also, types like So I don't know. I think I'd prefer for If we are going to add this, I'd prefer if this was "feature gated", e.g., behind a
I do think that this is a real problem, and that this problem is worth solving. I would prefer to move all the ctype definitions into a separate crate, and for Still, if the plan here is for |
@gnzlbg your concerns make sense. I'll refactor this to use a
I would think about this a little differently, while there are some (extremely obscure) platforms that do not support C's
This is interesting (I couldn't find anything online about CHARI). I think it means that there are three fundamental categories of mandatory C types at play here.
I'll change this PR to have (1) defined unambiguously in the libc root, and put (2) and (3) behind the
This seems like the best ultimate solution. |
There is a crate called |
That sounds reasonable, it delivers value now, and it is forward compatible with re-exporting the types from the |
@gnzlbg please take a look. Is this what you were looking for? |
fa2d19f
to
ca956e1
Compare
Looks good. Would you mind removing the rustfmt commit ? As you might have discovered, libc does not support that yet. I prefer to do that as part of a clean up PR afterwards. |
cc @japaric , @alexcrichton Also see #375 , which pretty much was closed with the decision to leave libc empty for unsupported platforms, and the recommendation that platforms that only want to use generic ctypes (because that's the only thing they need, or because there is no libc for that platform) should use the This PR is different from what was discussed on that issue in that it only exposes these "generic" types behind a feature flag, instead of unconditionally. Still, once we land this, removing the feature and the types exposed would be a breaking change, so we should be sure that this is the direction in which we want to go. I'm still unconvinced of the advantage of doing this here instead of the |
Also cc @SimonSapin @sfackler |
NB: SGX and Switch can just use the generics
7008170
to
f14059b
Compare
Done, and ya I figured it out when I couldn't just run
This change (as opposed to using
Agreed, I think before we stabilize we should make sure that we are correctly getting the types for |
I know 😆 But that change addressed a real issue. Every time we added a new target to Rust, all that libc functionality was instantaneously stabilized for that target, independently of whether it was correct, whether it made sense (e.g. whether the target actually had a system / platform to bind to), etc. This was useful and convenient when the functionality was correct - add a new target to Rust, some minimal functionality is instantaneously available in libc automatically - but an issue when it wasn't: fixing the functionality after it had already been added was always a technical breaking change (although loosely speaking, we are allowed to do breaking changes that fix things that were already broken anyways). I don't see a problem with this being opt-in for now, and I doubt we'll ever support targets for which these definitions don't apply. If that were to happen, we can always do a breaking change to fix those. From a design pov, this solves a problem for targets "without libc", so to me the question that still needs to be resolved is whether we want to support those in libc as well, or whether as #375 mentioned, if these crates only need some generic ctypes for these targets, why aren't they using the EDIT: I admit that adding a libc dependency unconditionally is more convenient than switching between libc and cty depending on the target. So there is value in supporting these in libc itself. Although with this PR one would still need to enable the "generic_ctypes" feature depending on the target, so ideally we would avoid that once we are sure that this is where we want to go. |
Ahhhhh... Ok I can definitely see why that would be a major pain. One final question to address is if we should be exporting the category (1) types in the libc root unconditionally like discussed here: #1244 (comment) those definitions can never be wrong, so I think it's fine.
Actually the feature can be enabled unconditionally, it only does something on unknown platforms. |
Sorry there's a lot of discussion here and I haven't reviewed all of it just yet, I wanted to clarify the ctypes-in-libc point. We can add c types in libc at any time so long as there's a definition of what they should actually be. For example if there's a C compiler that defines these types, we match that. If there is no C compiler for a target and/or no definition of what the types could be, then we're not in the business of defining the types ourselves. |
The problem here is that we don't know the target, so we don't know if there is a C compiler for it, and the question is whether we should expose anything in this case. |
Right now all rustc Clang also supports
|
☔ The latest upstream changes (presumably #1247) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@josephlr thank you for the PR, I'm going to close this for the time being, since this discussions has been moved to the Basically, the same open questions that we had here are being discussed there, and once we resolve them, we'll move the cty crate into this repo, and hopefully this issue will be resolved. |
I forgot. Really, thank you for working on this, and let me know if you'd like to work on moving the |
Per @alexcrichton's comment here, we should move the truely universal types back into the crate root. Let me know if you think some of these types are not universal (I've never seen a C-compiler use any definitions except the ones below).
This allows for crates like ring to use the libc crate while still supporting custom/unsupported targets (like
x86_64-unknown-uefi
).Specifically the following code was moved from
::{unix, windows, cloudabi, redox, fuchsia, sgx, switch}
to::
.This change also makes sure that all basic C types are referred to like
::c_int
, this will make moving this code around in the future much easier.