← Back to context

Comment by goeiedaggoeie

2 months ago

I write a fair bit of rust/c for my day job. Do you find zig easier than the ffi interface in Rust?

I maintain auto-generated Rust and Zig bindings for my C libraries (along with Odin-, Nim-, C3-, D- and Jai-bindings), and it's a difference like night and day (with Zig being near-perfect and Rust being near-worst-case - at least among the listed languages).

> Do you find zig easier than the ffi interface in Rust?

Yes, but it's mostly cultural.

Rust folks have a nasty habit of trying to "Rust-ify" bindings. And then proceed to only do the easy 80% of the job. So now you wind up debugging an incomplete set of bindings with strange abstractions and the wrapped library.

Zig folks suck in the header file and deal with the library as-is. That's less pretty, but it's also less complicated.

I've somehow avoided Rust, so I can only comment on what I see in the documentation.

In Zig, you can just import a C header. And as long as you have configured the source location in your `build.zig` file, off you go. Zig automatically generates bindings for you. Import the header and start coding.

This is all thanks to Zig's `translate-c` utility that is used under the hood.

Rust by contrast has a lot more steps required, including hand writing the function bindings.