ityonemo

ityonemo

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!

Showing Posts 56 to 47

venkatd

venkatd

We’ve been using Zigler/Zig in production and I love how seamless the experience is.

We opted for Zig over Rust for personal preferences. I think Zig is closer to C while Rust is closer to C++. We’re more C-kind of personality.

It also comes in handy when trying to integrate with 3rd party C libraries.

zookzook

zookzook

Many thanks for the great work on Zigler — it really opens up exciting new possibilities!
Up to now, I’ve been using Rustler and Rust to offload certain tasks.
Rust is powerful, but I often found it a bit tricky and more complicated than I’d like.
That’s why I recently started exploring Zig and Zigler.
As a little learning exercise, I built an IPv4 trie in Zig. It can be used in Phoenix, for example, to block or allow specific host addresses.
Here’s the link to the repo: ZigDemo

jeremy_c

jeremy_c

Just a FYI, when I tried the pub usingnamespace trick, I get:

** (KeyError) key :pub not found
    (zig_parser 0.1.9) lib/zig.parser.ex:272: Zig.Parser.put_opt/3
    (zig_parser 0.1.9) lib/zig.parser/top_level_decl.ex:5: Zig.Parser.TopLevelDecl.post_traverse/5
    (zig_parser 0.1.9) Zig.Parser."TopLevelDecl__22"/6
    (zig_parser 0.1.9) Zig.Parser."ContainerDeclarations__4"/6
    (zig_parser 0.1.9) Zig.Parser."ContainerMembers__0"/6
    (zig_parser 0.1.9) Zig.Parser."Root__4"/6
    (zig_parser 0.1.9) Zig.Parser.parser__1/6
    (zig_parser 0.1.9) Zig.Parser.parser/2
    (zig_parser 0.1.9) lib/zig.parser.ex:179: Zig.Parser.parse/1
    (zigler 0.10.3) lib/zig/compiler.ex:85: Zig.Compiler.compile/4
    (zigler 0.10.3) expanding macro: Zig.Compiler.__before_compile__/1

It’s OK if the feature is coming in 0.11. Thanks for giving it a shot!

ityonemo

ityonemo OP

actually in the meantime, you can probably (haven’t tried it, kinda guessing) get the result you want by doing:

~Z"""
pub usingnamespace @import("file-to-import.zig");
"""
ityonemo

ityonemo OP

It was an oversight that I didn’t build it in 0.10. this feature will come in 0.11

jeremy_c

jeremy_c

It seems that with that method, you write your code in a .zig file, but then still have to wrap every function you wish to expose to Elixir in that external .zig file within the Elixir module?

I was looking for a method that didn’t require that duplication of effort. Or did I misunderstand how it works?

krasenyp

krasenyp

Very quick search in the docs tell me you can - Zig — zigler v0.16.0.

jeremy_c

jeremy_c

Is there a way to write the zig code in a .zig file so I can get all the goodness of an editor w/LSP, syntax highlighting, etc… for my zig code?

ityonemo

ityonemo OP

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.

https://hexdocs.pm/zigler/6-c_integration.html

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews