Stream: platform development

Topic: Platforms loading Roc apps


view this post on Zulip Luke Boswell (Nov 17 2022 at 23:02):

I'm trying to understand how a platform might dynamically load a Roc app at runtime, i.e. a plugin use-case. I have limited knowledge and experience here so would appreciate any pointers to help me learn more about this. I am assuming this is how a plug-in might be built and used, though I wonder if a plug-in is just .roc interface files instead?

I understand roc build compiles a Roc app into a standalone static binary. One way to use this could be Rust's std::process::Command and then IPC using something like interprocess::local_socket to send data that has been serialised between the platform and plugin.

Or is there a better way? Maybe roc build --lib to build a C library and then use the linker somehow?

view this post on Zulip Brendan Hansknecht (Nov 17 2022 at 23:17):

The theoretical plan for dynamically using a roc app:

  1. Tell roc to build a shared/dynamic library
  2. Have the platform binary find this library (could be select in the UI, loading all in a folder, having it loaded when you do something like import a package, etc)
  3. Have the platform load the shared library
  4. Dispatch calls to the shared library and use it like a normal roc app.

This can all be done at runtime and be dynamic.

view this post on Zulip Brendan Hansknecht (Nov 17 2022 at 23:18):

We already do this for our tests

view this post on Zulip Brendan Hansknecht (Nov 17 2022 at 23:18):

Each case is compiled to a shared library and loaded by the rust test runner.

view this post on Zulip Luke Boswell (Nov 17 2022 at 23:29):

Cool. Thanks for that, I didn't know you could do that. I'll have a closer look.

view this post on Zulip Brendan Hansknecht (Nov 17 2022 at 23:32):

In rust we use: https://docs.rs/libloading/latest/libloading/


Last updated: Jul 05 2025 at 12:14 UTC