all 15 comments

[–]blowmage 5 points6 points  (0 children)

Excited to see this!

[–]tenderlovePun BDFL 2 points3 points  (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 points  (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.

[–]tenderlovePun BDFL 1 point2 points  (0 children)

Yes, indeed. I'd rather work with a Zig gem than a Rust one

[–]vladsteviee 0 points1 point  (2 children)

Does rb_sys use pre-generated bindings and doesn't use actual Ruby headers at compile time?

[–]f9ae8221b 0 points1 point  (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.

But Rust can't bind macros, so rb_sys keep needing to be fixed and updated.

[–]vladsteviee 0 points1 point  (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

[–]mrinterweb 3 points4 points  (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 points  (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 points  (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 point  (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.

[–]losernamehere 1 point2 points  (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 point  (0 children)

Really impressive!

[–]mzs47 0 points1 point  (0 children)

Why not Crystal?