Stream: platform development

Topic: ✔ How do I generate glue with roc glue?


view this post on Zulip Rene Mailaender (Apr 15 2023 at 09:58):

Hey,
I'm working on adding the possibility to run child processes from within a roc program: github
currently the roc and rust code communicate over a commandRun : Str, List Str -> Effect ( Result (List U8) (List U8) ) with each other, which serves as a wip only of course.

I'd rather like to have something similar to what @Agus Zubiaga achieved for his InternalTcp.roc, but i'm struggling a little figuring out how roc glue works. :/

I couldn't figure it out with the examples and zulip discussions alone unfortunately. :(

view this post on Zulip Luke Boswell (Apr 15 2023 at 12:34):

Yeah glue just changed very recently to a plugin model. It now accepts a .roc file, and unfortunately there isn't much documentation or examples anywhere yet that I have found. I think the focus has been on bringing it back up to parity with the previous implementation. I think this is the file you are looking for. If you figure out how to use it, can you please share how you did it? I've had a go at using the new version but haven't managed to use it yet. I thought it might be good to convert one of the examples like static-site-gen over to using it, but got stuck and haven't touched it again. I've just been focussed on Json and making more examples for now.

view this post on Zulip Agus Zubiaga (Apr 15 2023 at 14:42):

I don't really know much about glue but this how I pulled it off: https://github.com/roc-lang/basic-cli/pull/29#issuecomment-1496005933

view this post on Zulip Agus Zubiaga (Apr 15 2023 at 14:44):

As @Luke Boswell, glue's model changed right after and at first try I couldn't figure out how we are supposed to use it, but you might be able to use the same nightly I used or compile 6714ada from source.

view this post on Zulip Agus Zubiaga (Apr 15 2023 at 14:51):

Happy to help if you get stuck at any point!

view this post on Zulip Agus Zubiaga (Apr 15 2023 at 14:51):

Also if someone knows an easier way to do this with the new glue please chip in

view this post on Zulip Rene Mailaender (Apr 15 2023 at 14:57):

thank u both. :)
ah i hoped the change came right before u pulled it of. ^^

Since I still have a lot other todos on my list, I guess I postpone it for a few days, in case someone who knows the new solution joins in. that way we also might get it documented here. :) otherwise I'll sure come back to you. thx :)

view this post on Zulip Agus Zubiaga (Apr 15 2023 at 15:01):

Sounds good :handshake:

view this post on Zulip Brendan Hansknecht (Apr 15 2023 at 15:29):

Oh, i guess we never made a write up about this and it is only talked about in some of the previous roc monthly gatherings.

view this post on Zulip Brendan Hansknecht (Apr 15 2023 at 15:29):

Once I have access to a computer I'll add more of a write up here.

view this post on Zulip Rene Mailaender (Apr 15 2023 at 15:30):

thank you :)

view this post on Zulip Brendan Hansknecht (Apr 15 2023 at 16:28):

So roc glue now uses a roc plugin to decide what to generate (this enables support for multiple languages and any developer being able to write a plugin). An example plugin for rust (not 100% functional but has a solid amount of types) can be found in the repo as crates/glue/src/RustGlue.roc. This is the GLUE_SPEC. So if you want to generate rust code for a platform you would type roc glue crates/glue/src/RustGlue.roc /path/to/output/directory /path/to/platform/main/to/gen. The output is a directory now and in the rust case, it would generate a module with sub-modules for each architecture (re-exporting only the architecture currently used). As a concrete example, in the repo, you can run roc glue crates/glue/src/RustGlue.roc /tmp/roc_type crates/glue/platform/main.roc and then look at the output in /tmp/roc_type. Currently, I think there are only a rust glue and a typescript glue. Rust being much much farther along.

Extra note: given the plan is to remove all hosted modules and effects, it does not generate anything for effects. That is why you have to use the workaround Agus mentioned above. I should probably start converting platforms to the new format. I think we have all of the pieces to make that work now.

view this post on Zulip Brendan Hansknecht (Apr 15 2023 at 16:36):

I think Richard's talk form the march gathering may also give some more useful context. He talks about writing the typescript glue and the pieces it takes. Linked here. I think it is the second talk in the recording.

view this post on Zulip Rene Mailaender (Apr 15 2023 at 16:40):

thank you a lot! i tested

roc glue crates/glue/src/RustGlue.roc /tmp/roc_type crates/glue/platform/main.roc

really quick and it worked! Nice.
later i'll dive deeper and try to get it running for my basic-cli fork. :working_on_it:

view this post on Zulip Notification Bot (Apr 15 2023 at 16:40):

Rene Mailaender has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC