-
Notifications
You must be signed in to change notification settings - Fork 667
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
Would it be possible for nix to use bindgen instead of depend on libc ? #978
Comments
Nope. This is indeed a big problem. It's even worse in the BSD world than it is in Linux. Unfortunately, Nix can't simply switch to rust-bindgen, because that would break cross-compilation in all of Nix's consumers. It could also theoretically cause runtime breakage in certain situations. If you've found a new example of a Linux structure that changed between two Rust-supported kernel versions, please raise it in libc's issue tracker here: rust-lang/libc#570 |
@gnzlbg In many cases, you are compiling once for a variety of systems so you won't know what features are supported until runtime anyway. I think the right way to handle this is to get all system calls exposed and have them bubble up errors from the OS if a syscall/ioctl/whatever isn't supported at runtime. If you have a specific example of incompatibility between kernel versions as a case study, I would be interested to take a look. |
On MacOSX the values of some |
Then submit a PR to remove them from libc. libc can't generate correct code for bindings that change value between versions. |
We can't remove stuff from libc, we can at best deprecate it, and all platforms do backwards incompatible changes when they do "major" version bumps, which happens every couple of years :/ |
No, libc can remove stuff if it's broken. Buildtime failures are better than runtime failures. But we should discuss it on libc's issue tracker, not Nix's.
Not true for well-behaved C libraries. A well-behaved C library never makes backwards incompatible changes. Backwards compatibility is maintained by bumping the .so version (Like ncurses did for 6.0), using ELF symbol versioning (like FreeBSD does frequently), or never changing public symbols (like glibc does). |
The problem is it isn't broken, on some platform version, and people rely on it working on that platform. |
But libc is used on more than one platform version. And libc is designed to be always cross-compilable. So such a symbol can't be used correctly. |
The problem remains: they work correctly for the platform they were added to, so removing them is a backwards incompatible change :/ i'm not arguing that this is a nice situation to be in, it isn't, but some constants are very basic :/ platforms just shouldn't break them, but they do :/ |
No, they don't work correctly, because those symbols don't match the environment where the application runs. For example, if the system headers expose a symbol called `#define _POSIX_VERSION 201512" and an application uses that symbol to determine what version of the POSIX standard is supported by its operating system, then it will be wrong whenever it's run on a different version of the OS. Such a symbol simply can't be correctly used by a cross-compiled program. |
You seem to be trying really hard to not understand what I am saying: yes, the symbols are broken on all OS versions except for one, but the people who added them are using them on precisely that OS version, they do work there, and that OS version is the one that The logic of your argument: " That is, removing these symbols from Does this mean that the design of I opened this issue here because There are a couple of things that, with tied hands, |
Observing this conversation it does seem like you two are talking past each other. I however think that both of your points are valid: However, I think there is room for a |
Actually, libc makes no claim about which OS versions it supports. But since it's included in libstd, it must support at least as many versions as libstd does. Right now libstd supports OSX 10.7+, Linux 2.6.18+, Windows 7+, and unspecified versions of other OSes. https://forge.rust-lang.org/platform-support.html . Nor is libc written for one specific version. Since different symbols are added by different users, it ends up getting a mix: rust-lang/libc#570 (comment) |
Yes, this is a big oversight in the
Note that just because this is written down somewhere doesn't mean it's true. As you have realized, it isn't. In particular, the claim that all OSX versions >= 10.7 are supported is extremely suspicious. Some commonly used What happens in practice is that
What we could do is instead guarantee that the "default" targets, e.g., So essentially what would happen is that different ABI incompatible versions of each platform become different targets, so we can still use This would be a lot of work, for an unpredictable amount of gain. Arguably, if this was a real problem, people would already be working on it. I think the effort would at least be initially be better spent making
I'd like to apologize to @asomers , it's my fault that the discussion got heated. I understand the points that you are making, and I do think that they are real problems worth solving. The reason things got heated on my side is that I've got a bit frustrated about how the discussion is going. We have many open and approved PRs to |
The values of constants in the system's C headers, the layout of types like structs, etc. vary across kernel versions. The only way to get these always right is to parse the C system headers, and generate Rust bindings for them automatically.
This is something that
libc
does not do. Inlibc
, the value of a constant is hardcoded to whatever its value is in the kernel version than its Docker containers use.Would it be possible for
nix
to do better thanlibc
here ?The text was updated successfully, but these errors were encountered: