Hi, I was thinking about tinkering with Roc, but the project I have in mind requires FFI. I understand that Roc compiles to WASM, so calling "exported" WASM functions is okay. Does Roc support this?
Every interaction with a platform in Roc is wrapped in an Effect in Roc, but otherwise, yes, roc has FFI. It is just a more constrained FFI to keep roc pure.
For wasm, it can call other js and wasm functions that are available in to the wasm environment.
As a note, Roc also compiles to native arm and x86. For those, it uses c ffi for communication with the platform.
Nice, is there any docs related to FFI? I have experience in Haskell, Idris, Elm, etc.. so any pointers/similar code would be very appreciated <3
@Brian Carroll any best example for helping someone start with a wasm platform?
We only have one example and it's either hello world or "platform switching", I can't remember which.
The majority of our examples and projects are targeting machine code rather than Wasm.
Is this project targeting the browser? Or running in another wasm interpreter? It makes a big difference to the platform design. The hello world example is for the browser.
I'm working on a virtual DOM platform but there's a long way to go.
The idea is to integrate with an existing Node framework. So I was thinking using Node's wasm capabilities to make Roc interact with it
Node has C interop (I don't know the details, but I know there's some way to do it!)
so that's an option too!
Is there any info on interoperability with Roc? Compiler source code works for me as well, just figuring out which thread to pull
No we don't have any docs on that yet, the only way is to read the source code of the example platforms and talk to people!
Ah ok Wasm on Node makes sense. Nobody has attempted it yet but it would be cool to see how it goes!
examples/virtual-dom-wip
would be the closest thing we have. It doesn't build because of some features that aren't complete in the compiler.
But you can check out host.zig and host.js on the client side.
It's tricky to interface directly from JS to Roc because you need to make sure all the bytes are in the right locations. It's possible in js but it's nicer in lower level languages. So I used Zig for some glue code.
Thanks for the pointers, I really appreciate this!
Last updated: Jul 06 2025 at 12:14 UTC