Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/suirad/zig-header-gen
Automatically generate headers/bindings for other languages from Zig code
https://github.com/suirad/zig-header-gen
binding-generator build c comptime cpp golang header-generator nim python rust zig zig-library
Last synced: 3 months ago
JSON representation
Automatically generate headers/bindings for other languages from Zig code
- Host: GitHub
- URL: https://github.com/suirad/zig-header-gen
- Owner: suirad
- License: mit
- Created: 2020-07-09T23:31:09.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T02:13:18.000Z (almost 2 years ago)
- Last Synced: 2024-04-17T07:58:51.996Z (7 months ago)
- Topics: binding-generator, build, c, comptime, cpp, golang, header-generator, nim, python, rust, zig, zig-library
- Language: Zig
- Homepage:
- Size: 78.1 KB
- Stars: 67
- Watchers: 5
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - zig-header-gen🗒️Automatically generate headers/bindings for other languages from Zig code
- awesome-rust-list - suirad/zig-header-gen - header-gen?style=social"/> : Automatically generate headers/bindings for other languages from Zig code. (FFI Bindings)
- awesome-rust-list - suirad/zig-header-gen - header-gen?style=social"/> : Automatically generate headers/bindings for other languages from Zig code. (FFI Bindings)
README
# HeaderGen
`HeaderGen` automatically generates headers/bindings for other languages given
Zig code with exported functions/typesHere are the following supported language binding outputs:
- [x] C Bindings
- [x] Python Bindings
- [ ] Rust Bindings
- [ ] Go Bindings
- [ ] Nim BindingsHere are the following supported Zig language features:
- [x] Extern Functions
- [x] Extern Structs
- [x] Extern Unions
- [x] Extern Enums## Getting started
Given the following Zig code as the file `src/fancylib.zig` and using the C generator:
```zig
const std = @import("std");export fn print_msg(msg_ptr: ?[*]const u8, len: usize) bool {
if (msg_ptr) |raw_msg| {
const msg = raw_msg[0 .. len - 1];
std.debug.print("Msg is: {}", .{msg});
return true;
}
return false;
}const Internal = struct {
a: u64,
};const External = extern struct {
b: u64,
c: [100]u8,
};export fn use_internal_and_external(i: ?*Internal, e: ?*External) void {
// do things...
}
```You will receive the following C header in `headers/fancylib.h`:
```c
#ifndef _fancylib_H#define _fancylib_H
#include
#include
#includetypedef struct External {
uint64_t b;
uint8_t c[100];
} External_t;bool print_msg(uint8_t* arg0, size_t arg1);
void use_internal_and_external(void* arg0, External_t* arg1);
#endif
```## Usage Notes
- Copy from this repo `header_gen.zig` and the folder `generators`;
drop them next to your `build.zig`
- See the `build.zig` in this repo for an example of integration