@Luke Boswell I'm following up on this . 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?
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.
in roc glue <path-to>/RustGlue.roc ./src/ platform/main.roc where does RustGlue.roc come from?
https://github.com/roc-lang/roc/blob/main/src/glue/src/RustGlue.roc
I think glue even generates default allocators like roc_alloc etc for you
Got it, I totally missed the "roc_stderr_line": Stderr.line!, in the hosted section, makes a lot more sense now, thanks!
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
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)
I dont find it to be complicated at a first sight though, I was thinking it's quite elegant actually :smile:
Thats good to know.
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