Stream: beginners

Topic: platforms


view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 13:50):

Will/does Roc provide a set of built-in "standard" Platforms? Everything I saw inside examples has the platform alongside it. Are we intending to build / already have binding generators (similar to wasm-bindgen for Rust+JSWasm or zigler for Zig+Elixir) to streamline platform development?

view this post on Zulip Folkert de Vries (Oct 22 2021 at 13:52):

a platform is just a rust/c/zig app. It's unlikely you'd want to expose a raw C api to a roc platform. The whole idea is that the external api is wrapped in a way that is more friendly

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 13:58):

I'm looking at https://github.com/rtfeldman/roc/blob/trunk/examples/hello-rust/platform/src/lib.rs. This is not a "typical" Rust app. This is similar to the situation before wasm-bindgen, when folks wrote webassembly bindings in rust like this: https://dev.to/shritesh/writing-a-brainfuck-interpreter-in-rust-and-webassembly-13f#webassembly. Now it's simply:

#[wasm_bindgen]
pub fn brainfuck(source: String, input: String) -> String {...}

view this post on Zulip Lucas Rosa (Oct 22 2021 at 14:01):

There are two open pull requests for a platform based on SDL and one for a web server that might also give some insight

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:03):

The rust situation is a bit rough because we have to deal with C FFI, which is not hidden at all at the moment. The C FFI turns out to be kind of subtle. We do provide the roc data structures (RocList, RocStr) but even those need to be handled with care

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:04):

so there is room for some macro magic to make the process nicer, but I'm not sure things have crystallized sufficiently to make it worth it to do that now

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:24):

yeah I think binding generators are a good idea at some point, but haven't really thought about the specifics :big_smile:

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

long-term the idea is that application authors get their platforms from the package repo

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

so I just write my app and say platform: rtfeldman/blah and that's it

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

it just feels like another dependency

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:26):

more or less

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:27):

but the package repo doesn't exist yet, so for the moment it's all local filesystem!

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:27):

Are there any in-built platforms right now?

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:28):

no, the plan is not to have any ship with the compiler - with the possible exception of like a "tutorial" one if we have an interactive tutorial built into the editor

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:29):

but I'd like to have all the platforms be sort of on equal footing, give or take author reputation

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:29):

got it. That sounds reasonable.

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:30):

like I wouldn't want someone to think "I have a cool idea for a way to do a CLI platform, but what's the point when everyone's gonna use the builtin one anyway"

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:31):

as opposed to "ok here's the CLI platform made by the people who made the compiler" - it's got that reputation behind it, so it will probably be a safe default choice for anyone, but it's still just another platform in the package repo

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:37):

Agreed. Final question: How does the compiler already know how to compile the current platform examples? I don't see any build scripts or configuration.

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:38):

it's hardcoded for rust/zig/c

view this post on Zulip Folkert de Vries (Oct 22 2021 at 14:39):

just looks for host.c/host.zig and builds them, cargo build when it finds a Cargo.toml

view this post on Zulip Shritesh Bhattarai (Oct 22 2021 at 14:39):

nice. Thanks.

view this post on Zulip Richard Feldman (Oct 22 2021 at 14:57):

we're planning to move that into user space though! Just haven't gotten to it yet. :big_smile:

view this post on Zulip M.T. (Dec 23 2022 at 22:10):

Hello, love the language - are there any resources where I can learn more about the platform concept in Roc ? I would like to try to make a PoC platform for own use, to see if Roc could be used for my own use-case

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 00:34):

Currently most platform documentation comes on the form of examples and people.

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 00:35):

It is still a changing space and not much has been done for documentation.

view this post on Zulip M.T. (Dec 24 2022 at 14:34):

Thanks - I can see some talk about platforms in here, and I will also look at the example code.

view this post on Zulip Brendan Hansknecht (Dec 24 2022 at 15:23):

Feel free to ask any questions you have. I'm sure someone else or I will attempt to answer

view this post on Zulip Christopher Bertels (Jan 30 2023 at 09:50):

Is it possible to use multiple packages and import from multiple platforms in the same app? I seem to trigger an infinite loop in the compiler trying to do so while trying to create a simple custom platform that also uses the basics-cli platform (for things like the Task type). But I might also just be doing this completely wrong :sweat_smile:

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:08):

OK. I got it working. Looks like I was missing an imports in the interface decl for my test platform. adding imports [pf.Task.{Task}] fixed it I think

view this post on Zulip Anton (Jan 30 2023 at 10:37):

Hi @Christopher Bertels, it's strange that this appears to work, we intend the user to only be able to use one platform. Using multiple roc packages/modules is supported however.

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:55):

Hm, yeah not sure if what I said is fully correct, here's the code that seems to work so far: https://github.com/bakkdoor/roc-platform-test/ and I think this line fixed my issues: https://github.com/bakkdoor/roc-platform-test/blob/main/src/TestPlatform.roc#L3

view this post on Zulip Christopher Bertels (Jan 30 2023 at 10:56):

This is the example app using both platforms (or rather just packages?! not sure about the right terminology here): https://github.com/bakkdoor/roc-platform-test/blob/main/examples/TestApp.roc

view this post on Zulip Anton (Jan 30 2023 at 11:04):

Oh I see, you are indeed using only one platform (basic-cli), your TestPlatform.roc is what we call an (interface) module.

view this post on Zulip Anton (Jan 30 2023 at 11:11):

We have a detailed explenation of what a platform is here.

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:15):

Cool thanks! :)

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:16):

Is there any documentation on interface modules?

view this post on Zulip Christopher Bertels (Jan 30 2023 at 11:26):

Are they just "normal" modules that export functions? Or is there more to them?

view this post on Zulip Anton (Jan 30 2023 at 12:24):

Christopher Bertels said:

Is there any documentation on interface modules?

No, not yet

Christopher Bertels said:

Are they just "normal" modules that export functions?

Yes, that pretty much covers it :)


Last updated: Jul 05 2025 at 12:14 UTC