Expand description
§AutoZig - Safe Rust to Zig FFI
AutoZig enables safe, ergonomic interop between Rust and Zig code.
§Architecture
AutoZig follows a three-stage pipeline inspired by autocxx:
- Parsing Stage: Extract Zig code from
autozig!macro invocations - Build Stage: Compile Zig to static library (.a) and generate C headers
- Binding Stage: Generate safe Rust wrappers around raw FFI
§Example
use autozig::prelude::*;
autozig! {
// Zig implementation
const std = @import("std");
export fn compute_hash(ptr: [*]const u8, len: usize) u64 {
const data = ptr[0..len];
var hash: u64 = 0;
for (data) |byte| {
hash +%= byte;
}
return hash;
}
---
// Rust interface (Safe wrapper)
fn compute_hash(data: &[u8]) -> u64;
}
let data = b"Hello AutoZig";
let hash = compute_hash(data); // Safe call, no unsafe needed!
println!("Hash: {}", hash);Modules§
- prelude
- Common imports for using AutoZig
- types
- Placeholder for Zig type wrappers
- zero_
copy - Zero-copy buffer passing between Zig and Rust (Phase 4.2)
Macros§
- autozig
- Re-export the procedural macros Main autozig! procedural macro
- include_
zig - include_zig! macro for referencing external Zig files