ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.67k stars 2.47k forks source link

Provide a way to automatically extract OS constant definitions #6808

Open koachan opened 3 years ago

koachan commented 3 years ago

Manually copying constant definitions is a very time-consuming and error-prone process. It'd be very nice if we can automate the process, somehow. This would greatly ease porting efforts to new CPU architectures, I believe.

Any ideas on how to do this? Perhaps a simple design would be having a list of per-OS constants and what C header is it defined, then we can make a small script that will pull the values for each platform it supports.

(Sparked from the discussion in this PR)

FireFox317 commented 3 years ago

translate-c can also handle macro's, so why not use that? Another extra benefit of trying to make it work with translate-c is that you can add more functionally to it, which is a win-win situation.

mrakh commented 3 years ago

translate-c can also handle macro's, so why not use that? Another extra benefit of trying to make it work with translate-c is that you can add more functionally to it, which is a win-win situation.

Just checked, and yep, it can handle macros, even following #includes to do so. Deleted my original post.

koachan commented 3 years ago

So, the solution is to write a C file that loads all the constants then convert it with translate-c?

koachan commented 2 years ago

Apparently #11447 will help with generating Linux syscall constants, at least. That's pretty nice.

nektro commented 2 years ago

something akin to https://github.com/ziglang/fetch-them-macos-headers for linux would be a nice approach