Stream: beginners

Topic: Adding functions to a platforms


view this post on Zulip souf (Jun 16 2026 at 05:59):

@Luke Boswell I'm following up on this #ideas > Standardized HTTP interface for Roc @ 💬. On how to add new functions to a platform, and the fact that there is no documentation yet.

I was taking a look at your rust platform template at https://github.com/lukewilliamboswell/roc-platform-template-rust and I'm trying to understand how things work.

I understand that the file platform/main.roc is where are defined signature of functions provided by the platform.

I see that the the file src/lib.rs is where you write the actual platform implementation.
I see that some functions have the naming roc_[function_name] (i.e. roc_alloc), it seems to be how you define default roc's requirement in the platform, right?

I also see that the functions you've defined in main.roc seem to follow the convention roc_[function_name]_line, i.e. roc_stdin_line. Is that how you define the custom platform function, by adding _line at the end?

Is there anything else notable to know to get started?

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:06):

There are kind of two different things, the entrypoints are the functions that the host will use to call into roc ... and then the hosted effects are the functions the host provides that roc will call.

The platform/main.roc header requires section specifies the entrypoints, and the hosted section specifies the effects.

You then use roc glue ... which will code gen all the interfacing parts and should give you an idiomatic bindings for your host library to use.

view this post on Zulip souf (Jun 16 2026 at 06:13):

in roc glue <path-to>/RustGlue.roc ./src/ platform/main.roc where does RustGlue.roc come from?

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:14):

https://github.com/roc-lang/roc/blob/main/src/glue/src/RustGlue.roc

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:14):

I think glue even generates default allocators like roc_alloc etc for you

view this post on Zulip souf (Jun 16 2026 at 06:19):

Got it, I totally missed the "roc_stderr_line": Stderr.line!, in the hosted section, makes a lot more sense now, thanks!

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:24):

Yeah the symbols can be named anything now... it's kind of a legacy thing from way back when there was a naming convention and linking was more automatic. Those days were more "magic" around platform dev and the lessons we rolled into the new zig compiler changed platform authoring a lot. Things are now very explicit, like way more strict than other languages. You will find the linking side of things really strict too. This enables us to provide a really nice user experience for app authors (but slightly more complicated for platform authors).

Specifically, you should be able to cross-compile a roc app from any target to any target with nothing but roc cli

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:26):

This means e.g. you can compile a wasm module on any machine, or a statically linked linux executable (arm or amd) for uploading to the cloud (assuming the platform supports that target)

view this post on Zulip souf (Jun 16 2026 at 06:38):

I dont find it to be complicated at a first sight though, I was thinking it's quite elegant actually :smile:

view this post on Zulip Luke Boswell (Jun 16 2026 at 06:40):

Thats good to know.

view this post on Zulip souf (Jun 16 2026 at 06:46):

and because the rust code (for the rust platform) is just plain rust, it's supposed to be easy to use the LSP or any rust debugging tools to figure things out


Last updated: Jul 23 2026 at 13:15 UTC