Stream: ideas

Topic: precompiled hosts when integrating in other languages


view this post on Zulip Richard Feldman (Jun 13 2023 at 15:31):

so right now, in order to call a roc function from TypeScript on NodeJS, every time we roc build we also have to run clang (or zig, as it happens, for cross-compilation) to combine the roc output with the NodeJS C glue in order to end up with a binary that can be called from Node

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:31):

I just realized that it doesn't have to be this way

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:31):

and that it's achievable to do roc build and then it Just Works, no need for clang/zig/etc

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:32):

this is because Node defines its modules at runtime; there's a C function we call at runtime that basically says "register this (Roc) function in this module"

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:33):

which in turn means we can have roc glue generate some sort of config file which says "here are all the roc functions in the binary that roc build will have created, and their types"

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:34):

at which point when Node boots up, it can do the following at runtime:

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:35):

so it moves a bit of work from build time to server initialization time, but that's basically a non-issue

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:35):

and then what you get is that nobody doing development needs to be running clang or zig - that can be done once for a generic "run roc functions on Node via a config file you generate with roc glue" and that's it

view this post on Zulip Richard Feldman (Jun 13 2023 at 15:38):

although to be fair, I'm not sure how the cost of clang/zig compares to the cost of generating and loading this config file, since each step in the feedback loop requires doing either all of the former or all of the latter before you have a running server :thinking:

view this post on Zulip Brian Carroll (Jun 13 2023 at 18:29):

Oh interesting!
It sounds like your loader would be doing strictly less work, never more, since it's not compiling. And maybe simpler dependency management?

view this post on Zulip Brendan Hansknecht (Jun 13 2023 at 22:37):

Interesting. You should be able to test all of that by just building a shared library of the roc app. That should be way faster than call zig or c or a regular link process.


Last updated: Jun 16 2026 at 16:19 UTC