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?
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
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 {...}
There are two open pull requests for a platform based on SDL and one for a web server that might also give some insight
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
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
yeah I think binding generators are a good idea at some point, but haven't really thought about the specifics :big_smile:
long-term the idea is that application authors get their platforms from the package repo
so I just write my app and say platform: rtfeldman/blah
and that's it
it just feels like another dependency
more or less
but the package repo doesn't exist yet, so for the moment it's all local filesystem!
Are there any in-built platforms right now?
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
but I'd like to have all the platforms be sort of on equal footing, give or take author reputation
got it. That sounds reasonable.
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"
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
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.
it's hardcoded for rust/zig/c
just looks for host.c/host.zig and builds them, cargo build
when it finds a Cargo.toml
nice. Thanks.
we're planning to move that into user space though! Just haven't gotten to it yet. :big_smile:
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
Currently most platform documentation comes on the form of examples and people.
It is still a changing space and not much has been done for documentation.
Thanks - I can see some talk about platforms in here, and I will also look at the example code.
Feel free to ask any questions you have. I'm sure someone else or I will attempt to answer
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:
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
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.
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
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
Oh I see, you are indeed using only one platform (basic-cli), your TestPlatform.roc is what we call an (interface) module.
We have a detailed explenation of what a platform is here.
Cool thanks! :)
Is there any documentation on interface modules?
Are they just "normal" modules that export functions? Or is there more to them?
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