suirad
zig-header-gen
Zig

Automatically generate headers/bindings for other languages from Zig code

Last updated Feb 20, 2026
91
Stars
12
Forks
4
Issues
0
Stars/day
Attention Score
9
Language breakdown
No language data available.
Files click to expand
README

HeaderGen

HeaderGen automatically generates headers/bindings for other languages given Zig code with exported functions/types Here are the following supported language binding outputs:
  • [x] C Bindings
  • [x] Python Bindings
  • [ ] Rust Bindings
  • [ ] Go Bindings
  • [ ] Nim Bindings
Here 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:
const std = @import("std");

export fn printmsg(msgptr: ?[*]const u8, len: usize) bool {
    if (msgptr) |rawmsg| {
        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 useinternaland_external(i: ?Internal, e: ?External) void {
    // do things...
}
You will receive the following C header in headers/fancylib.h:
#ifndef fancylibH

#define fancylibH
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

typedef struct External {
   uint64_t b;
   uint8_t c[100];
} External_t;

bool printmsg(uint8t* arg0, size_t arg1);

void useinternalandexternal(void arg0, Externalt 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
🔗 More in this category

© 2026 GitRepoTrend · suirad/zig-header-gen · Updated daily from GitHub