-
Notifications
You must be signed in to change notification settings - Fork 4
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
Run bindgen on linux uapi? #2
Comments
I think because it's really sparsed over headers. Right now I'm using https://github.com/rust-lang/libc for the types. but having this autogenerated would be much more fool proof. |
I saw that, which is what made me wonder this. I thought it's the wrong way around, after all, libc provides a wrapper over the kernel API which is often different from the API itself. |
Yep. one simple example is rust-lang/libc#1561. |
Another problem. (I actually just tested exactly this and bindgen worked suprisingly well and gave me |
Right, assuming the cbindgen "wrapper" file is made to include the headers in the right way, it should be correct. It is supposed to handle that in the same way C does.
Absolutely. Normally the real only clients of uapi are C libraries, and low-level platform specific software such as mesa. If you're not going to implement graphics drivers in rust, you can skip all the
True, it doesn't provide any kind of rust-friendly binding, the output is very raw. But it's good to include from in more friendly bindings, often. |
Feel free to look at a first try at that https://github.com/elichai/syscalls-rs/tree/linux-sys |
Nice! seems a good step towards |
I'm a bit scared to use these without a serious review (I'm not sure if it also uses my system headers for some of the includes which will kinda ruin the whole thing) but i'll keep working on it |
for example. just by adding also |
Good point. Isn't there a bindgen flag to ignore system headers? Linux uapi headers are more or less self-sufficient and not depend on any libc headers or anything else installed on the system. Possibly, doing this properly is going to require patching bindgen 😨 |
I think i've found the right solution :) |
Pushed an update to https://github.com/elichai/syscalls-rs/tree/linux-sys EDIT: Should this live on a separate git? |
Here it's both a blessing and a curse that bindgen will use types such as
That's up to you. There doesn't have to be a one-to-one crate to git repository relationship, and it's often the case that the |
I was involved in that discussion in the past. it's kinda stuck (people don't want OS/arch specific stuff in libcore) Anyhow, there's still some problems i'm seeing with bindgen, specifically rust-lang/rust-bindgen#1665 |
Same. Just filed a PR for RISC-V support, should be good to go: japaric/cty#16 |
Ugh. That'd be really hard to detect and convert on the bindgen side. We should make sure that |
I think it mostly depends on if llvm tokenizes ifdefs, or the preprocessor runs before codegen. how can we define macros like i386? aren't they builtins? |
I suppose bindgen only runs the preprocessor, so they could be manually defined? If not, we kind of need a Edit: but at least we understand now why |
hehe yeah. |
is the linux uapi supposed to be sufficient?
|
Sadly no. |
Huh I didn't know. Looks like uapi is still a work in progress, of untangling the internal headers from userspace interface ones. |
I can try to take a few constants and send a patch to the linux mailing list and see how people react to that idea. |
The |
The |
So there are implicit definitions in the C ilbrary headers that just happen to match the value the kernel implementation expects? That's worse than I thought, I assumed it was selective inside the Linux kernel where headers get installed from. But so some headers are completely external. Even worse, I suppose, if these definitions can differ per platform. I can't really use the |
You can use the Anyhow. yeah. I hope the diff between kernel headers and libc headers isn't that big. that we can compensate for it by maintaining our own stuff and slowly upstreaming (or even using the |
Looks like the only sane way to do this that will also handle the ifdefs is via build time rust-lang/rust-bindgen#1665 (comment) EDIT: that's how that looks like: https://github.com/elichai/syscalls-rs/tree/linux-sys2/linux-sys |
What I've noticed is that none of the Rust syscall projects run bindgen on Linux's uapi headers. The uapi headers define the interface between user space and kernel space:
Maybe I'm missing something, but I don't understand why not—I suppose it's no help with the syscalls or numbers themselves (it declares no functions), but would give structures and constants, at least.
Tried to look around but there's no
linux-sys
crate. There is input-linux-sys though. Maybe it's just too much?The text was updated successfully, but these errors were encountered: