Stream: beginners

Topic: Runtime compilation and execution of Roc scripts


view this post on Zulip GamerZero (Jul 17 2024 at 22:45):

Hi! Is it possible to compile and run Roc on a host at runtime? I've only seen mentions of building native binaries using C-ABI as a glue. Does it always have to be pre-built and linked statically to the host binary?

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 22:49):

Roc can build a shared library with --lib or an object file with --no-link

view this post on Zulip GamerZero (Jul 17 2024 at 22:53):

Brendan Hansknecht said:

Roc can build a shared library with --lib or an object file with --no-link

So the way that i can do something like hot reloading for Roc scripts in my runtime is calling to roc compiler binary, then dynamically linking to the output object?

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 23:00):

Yeah, roughly that.

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 23:00):

just dlopen and replace the shared library

view this post on Zulip GamerZero (Jul 17 2024 at 23:06):

Brendan Hansknecht said:

just dlopen and replace the shared library

Honestly that sounds kinda tough when host/runtime is not already implemented in C, C++ or Rust. Are there any plans on making wrappers around that so it is possible to run dynamic Roc scripts easily?

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 23:11):

I mean, I think hot reloading in general is complex and error prone. So probably best done in lower level languages.

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 23:12):

For general use, whatever cffi tool the higher level language has should work for interacting with roc. That said, a c/c++/zig/rust shim can make life easier.

view this post on Zulip Brendan Hansknecht (Jul 17 2024 at 23:13):

As the ecosystem matures, it would be nice to expand the support for more automation here, but past supporting glue (binding generation) generically, nothing concrete is thought out.

view this post on Zulip GamerZero (Jul 17 2024 at 23:17):

That clears things up a bit. Thanks.


Last updated: Jul 05 2025 at 12:14 UTC