Are there any docs to explain the basics of how you'd implement a host for a platform? Maybe something like a little guide that says 'to expose a function from the host, make sure it looks like [...]'?
I remember reading a while back that it wasn't a stable API so it wasn't going to get written down, but maybe something has changed in the time since.
https://github.com/roc-lang/roc/blob/d9217caae5153c0427dba3e820bb1bf0faedda73/examples/hello-world/platform/host.c for example has
extern void roc__mainForHost_1_exposed_generic(struct RocStr *string);
, which is associated (somehow) with the platform/main.roc
mainForHost : Str
mainForHost = main
but that's about as far as I can guess. Maybe the 1
is the number of arguments, but I'm not sure about the rest!
From what I can tell, roc__mainForHost_1_exposed_generic is actually hardcoded, and is required. I'm working through building a platform from nothing, and I might try to write an article explaining how to get set up from scratch.
the 1
is the index of the layout. We can have a function like List.single : a -> List a
and use it with multiple types, say Str
and I64
. These functions have the same name, but different type, and to make them distinct we "hash" the type and make it part of the name
the assumption here is that there is only one specialization of the mainForHost
function, so we pick type index 1
we want to automate all of this setup btw
That's interesting...
@Folkert de Vries do you wanna take a look at my issue in #Writing a platform > Thinking out loud ?
(At the very bottom)
Hey folks - I'm reviving this topic to know if something like this is currently available somewhere :)
Nope, but there are a lot more example platforms and templates
Last updated: Jul 05 2025 at 12:14 UTC