ityonemo
Zigler - Zig nifs for Elixir
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir.
https://github.com/ityonemo/zigler
The idea here is to make the zig NIFs be “embedded” in the elixir code, much like an “asm” call in C. It also makes the bridge between the zig function call and the elixir “basically transparent”. Several adapters are provided: i64, f64, string (as a c string or a zig slice), i64 arrays, f64 arrays. Of course it’s not terribly hard to do the unmarshalling of the erlang terms yourself inside the NIF.
Haven’t started documenting yet, but if you want to see how it works, the test/ directory has quite a few instructive examples which are all passing as of zig 0.4.0
Comments and criticism appreciated!
Most Liked
ityonemo
Updated to 0.8.1
Zig version is bumped to 0.8.1
https://hexdocs.pm/zigler/Zig.html
Major highlights:
- Supports cancellation of threaded and yielding nifs by killing the owning process.
- When compiled with debug symbols, zig “error return traces” are merged with elixir exception stacktraces.
- Supports idiomatic "std.testing.*’ zig stdlib functions for running zig tests
ityonemo
Zigler version 0.10.1 is released, with a redone API, fully updated documentation and guides.
Big highlight is “easy_c” which lets you mount a c library (or supplied c code) and allows you to integrate C libraries as nifs in an intuitive fashion without having to write error-prone glue code by hand.
ityonemo
Version 0.9.1 is released!
Zig version updated to 0.9.1:
Major highlights: Support for c and c++ compilation using the sources option:
https://hexdocs.pm/zigler/Zig.html#module-compiling-c-c-files
ityonemo
https://hexdocs.pm/zigler/0.3.0-pre/Zigler.html
Version 0.3.0-pre has landed with support for Zig 0.6.0. Support for “Long Nifs” which are Nifs that run in their own OS thread is currently disabled (pending investigation of most effective use of Zig async methodology). Other major improvements include a completely overhauled Zig Parser and support for Resources. Full, correct documentation and fixing long nifs will be released with the proper 0.3.0 release, but I wanted to spin up a few demos that leverage the Zig 0.6.0 standard library first.
The couple of demos I intend to write are:
- ICMP ping library for elixir
- Fast, safe (flushes the JSON binary from the shared binary memory) JSON parser using arena allocation and builtin BEAM allocator.
I would like to compare the performance JSON parser to an equivalent package made with rustler, so if anyone knows of the preferred Rust JSON parser that would be appreciated. Or, if anyone would like an easy demo, I can try my hand at it.
Things to look forward to:
I’m thinking about releasing Nerves support in the v0.3.0 series where the native cross-compilation capabilities of Zig are used to allow you to seamlessly cross-compile NIF modules in to your nerves releases.
ityonemo
Updated to 0.7.1
Zig version is now bumped to 0.7.1
Now supports threaded, yielding, and dirty nifs. Consult the documentation guides on how to use these different long-running nif methods:
Regression: nerves is (temporarily) not supported until the arm32 architecture becomes tier 1. If you would like to use zig with nerves, consider using v0.3.2.







