Stream: platform development

Topic: simple platform 101 docs?


view this post on Zulip Tankor Smash (Sep 17 2022 at 04:47):

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!

view this post on Zulip Thomas (Oct 20 2022 at 08:59):

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.

view this post on Zulip Folkert de Vries (Oct 20 2022 at 09:06):

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

view this post on Zulip Folkert de Vries (Oct 20 2022 at 09:07):

the assumption here is that there is only one specialization of the mainForHost function, so we pick type index 1

view this post on Zulip Folkert de Vries (Oct 20 2022 at 09:07):

we want to automate all of this setup btw

view this post on Zulip Thomas (Oct 20 2022 at 09:09):

That's interesting...

view this post on Zulip Thomas (Oct 20 2022 at 09:22):

@Folkert de Vries do you wanna take a look at my issue in #Writing a platform > Thinking out loud ?
(At the very bottom)

view this post on Zulip Georges Boris (Nov 29 2024 at 12:16):

Hey folks - I'm reviving this topic to know if something like this is currently available somewhere :)

view this post on Zulip Brendan Hansknecht (Nov 29 2024 at 19:01):

Nope, but there are a lot more example platforms and templates


Last updated: Jul 05 2025 at 12:14 UTC