Stream: beginners

Topic: combining roc with rust libraries


view this post on Zulip Drewry Pope (Nov 03 2025 at 05:08):

i understand the new code to be using zig, i want to use iroh with roc, iroh is a rust library. how feasible is using roc from rust at this point? I'm guessing you would use ffi against the c bindings? I'm also guessing it might be easier to make c bindings for a rust lib and then call those from roc, does that seem like the right way to go about it? I figure calling rust from zig will be easier since the roc compiler has its own processes and expects zig.

view this post on Zulip Hannes (Nov 03 2025 at 05:51):

Roc has no FFI, so to integrate Roc with any language, you would need to write a Roc platform in that language. Platforms can be in any language, so the Zig rewrite of the compiler won't affect this. The platform is compiled and linked with a Roc app, then the combined platform+app will run the host code (e.g. some Rust code that uses iroh) and call your Roc code.

Someone else will come along and explain this better than me and guide you to resources on writing a platform. :sweat_smile:

view this post on Zulip Niclas Ahden (Nov 03 2025 at 09:30):

+1 to what Hannes said. Here's a resource to learn more: https://www.roc-lang.org/platforms

Platforms isn't the easiest thing to get into right now as most contributions are made toward moving the language itself forward first. However, if you're up for some experimentation and tinkering you'll have fun :)

An easy way to get started is to extend an existing platform like basic-cli or basic-webserver. Perhaps you just need to add a few dependencies and functions in there and you're done?

The new compiler will change the language, and how platforms are built, so if you go into it expecting changes along the line you'll be fine :)

view this post on Zulip Brendan Hansknecht (Nov 03 2025 at 20:25):

Roc has no FFI

A better way to word this might be that all FFI in roc is controlled by the platform. By default, this tends to mean that to expose something via FFI is to extend a platform or create a new one.

A platform technically could expose raw bindings to libFFI. If it did so, it would enable roc apps to have total control for FFI to any library.

view this post on Zulip Brendan Hansknecht (Nov 03 2025 at 20:26):

I don't know enough about iroh to give any concrete suggestions here though.

view this post on Zulip Drewry Pope (Nov 03 2025 at 20:38):

thank you both :slight_smile: I'll play with it and see how it goes


Last updated: Nov 09 2025 at 12:14 UTC