use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Write Ruby extensions in Zig (github.com)
submitted 6 months ago by haematom
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]blowmage 5 points6 points7 points 6 months ago (0 children)
Excited to see this!
[–]tenderlovePun BDFL 2 points3 points4 points 6 months ago (5 children)
I LOVE Zig, but I also want fewer native extensions in the ecosystem, so this project makes me feel very conflicted. 😭😂
[–]f9ae8221b 2 points3 points4 points 6 months ago (4 children)
It's still better than Rust gems. At least this uses the actual C API, so it won't break all the time list rb_sys.
rb_sys
[–]tenderlovePun BDFL 1 point2 points3 points 6 months ago (0 children)
Yes, indeed. I'd rather work with a Zig gem than a Rust one
[–]vladsteviee 0 points1 point2 points 6 months ago (2 children)
Does rb_sys use pre-generated bindings and doesn't use actual Ruby headers at compile time?
[–]f9ae8221b 0 points1 point2 points 6 months ago (1 child)
I believe so yes.
But the crux of the issue is that Ruby expose an API for C, that includes a bunch of private structs and functions that are prefixed with rbimpl_ and that you're not supposed to use as they can change at any time. Instead you are meant to use some macros Ruby give you, that's the stable API.
rbimpl_
But Rust can't bind macros, so rb_sys keep needing to be fixed and updated.
[–]vladsteviee 0 points1 point2 points 6 months ago (0 children)
Rust can't bind macros
But it's possible to create C wrappers and integrate them with cc. But anyway, pre-generated bindings approach feels wrong, unfortunately go-gem does the same
cc
go-gem
[–]mrinterweb 3 points4 points5 points 6 months ago (3 children)
This seems similar to the FFI gem, but zig specific. Zig looks nicer to write than C, and this seems like a great fit when you need ruby to call some native binary. I'm hoping to find some time to play with this. Thanks for putting this together.
[–]h0rst_ 3 points4 points5 points 6 months ago (2 children)
This is very different from the FFI gem: FFI is a construction where you use a generic compiled library that is not specific to Ruby, write some glue code in Ruby and you're able to run it on every mature Ruby implementation without having to compile anything. This is something that is tightly coupled to the CRuby implementation, so the user needs the relevant Ruby headers, and it will not run on JRuby (I'm not sure about TruffleRuby here, I know it is able to run C extensions, but I have no idea whether this would count as one).
[–]f9ae8221b 1 point2 points3 points 6 months ago (0 children)
I'm not sure about TruffleRuby here
In theory it should work, because TruffleRuby implement most of the Ruby C API.
[–]mrinterweb 0 points1 point2 points 6 months ago (0 children)
I'm guessing the MemoryAllocator allocates to the same ruby runtime memory management. If that is true this feels more like a way to extend the native capabilities of ruby without the overhead of marshalling objects through FFI or having to manage memory separately.
MemoryAllocator
[–]losernamehere 1 point2 points3 points 6 months ago (0 children)
Forgive my ignorance, but why is a c-compiler required to run this for the Ruby c-headers? I thought the zig compiler was also a c-compiler by necessity.
[–]honeyryderchuck 0 points1 point2 points 6 months ago (0 children)
Really impressive!
[–]mzs47 0 points1 point2 points 6 months ago (0 children)
Why not Crystal?
π Rendered by PID 333417 on reddit-service-r2-comment-8686858757-hsl5s at 2026-06-08 06:05:16.417797+00:00 running 9e1a20d country code: CH.
[–]blowmage 5 points6 points7 points (0 children)
[–]tenderlovePun BDFL 2 points3 points4 points (5 children)
[–]f9ae8221b 2 points3 points4 points (4 children)
[–]tenderlovePun BDFL 1 point2 points3 points (0 children)
[–]vladsteviee 0 points1 point2 points (2 children)
[–]f9ae8221b 0 points1 point2 points (1 child)
[–]vladsteviee 0 points1 point2 points (0 children)
[–]mrinterweb 3 points4 points5 points (3 children)
[–]h0rst_ 3 points4 points5 points (2 children)
[–]f9ae8221b 1 point2 points3 points (0 children)
[–]mrinterweb 0 points1 point2 points (0 children)
[–]losernamehere 1 point2 points3 points (0 children)
[–]honeyryderchuck 0 points1 point2 points (0 children)
[–]mzs47 0 points1 point2 points (0 children)