Stream: beginners

Topic: How to call C/C++/Rust from Roc?


view this post on Zulip Undefined Behavior (Mar 21 2025 at 05:01):

as title. is there a Foreign Function Interface (FFI)?

view this post on Zulip Brendan Hansknecht (Mar 21 2025 at 06:22):

No

view this post on Zulip Brendan Hansknecht (Mar 21 2025 at 06:22):

Roc is completely pure except for platform interactions

view this post on Zulip Brendan Hansknecht (Mar 21 2025 at 06:23):

The platform theoretically could expose generic ffi (though it would be a bit of a hassle)

view this post on Zulip Jonas (Nov 12 2025 at 22:44):

Brendan Hansknecht said:

The platform theoretically could expose generic ffi (though it would be a bit of a hassle)

Ain't Plattforms FFI's?

view this post on Zulip Jonas (Nov 12 2025 at 22:45):

Can i load multiple platforms, for example from Rust?

view this post on Zulip Hannes (Nov 13 2025 at 00:14):

Jonas said:

Ain't Plattforms FFI's?

Kinda, but not in the same way that most people think of FFI, like Python has C FFI where you can write arbitrary C code and just call it from Python, but it's not obvious to me how to achieve FFI like that in Roc (but I trust Brendan when he says it's possible :sweat_smile:)

view this post on Zulip Brendan Hansknecht (Nov 14 2025 at 00:29):

Can i load multiple platforms, for example from Rust?

A roc app depends on exactly one platform. That platform can be written in anything that can speak C FFI. So platforms are a form of FFI. They are just really restricted. If you use the roc-wasm4 platform, you can't send a web request. You can't print to the console except for debug logging. You have extreme limitation. As a roc app, there is no escape hatch. You are just stuck with the limitations that the platform exposes.

When folks ask if roc has FFI, they generally are thinking of python style C FFI. At any point in a python app, I can call any C code that I want. It is completely unrestricted. Roc does not have this form of FFI. So I think it is best to say that roc does not have FFI. Otherwise you just confuse folks.

view this post on Zulip Richard Feldman (Nov 14 2025 at 01:54):

we have a FAQ entry on this! :smiley:

https://www.roc-lang.org/faq#multiple-platforms

(it's a very frequently asked question!)

view this post on Zulip Brendan Hansknecht (Nov 14 2025 at 02:15):

Ah yeah. I should remember to just link the faw for some of these


Last updated: Dec 21 2025 at 12:15 UTC