I would like to help with the zig glue. But I don't know, how to start. If you could point me to the right direction, I could give it a try. (But I am not sure,if I can succeed.)
Probably to start would be to look at RustGlue.roc in the repo. The new file would be very similar but generating zig code. It will probably a 1 type at a kind thing. Where you start with a super simple platform that just returns and int and then work outwards with most branches crashing to being with
Your roc-wasi platform is actually perfect for this.
I was thinking of starting by getting ZigGlue.roc to just vendor or copy the builtins that we need from crates/compiler/builtins/bitcode/src
. I think we can just import the files as bytes directly and write them out.
Or maybe starting with like a single Error tag union in the platform (maybe to represent a couple of IO errors) without payload and then generate the zig for that tag. We can use this for the openFile effect instead of just passing a U8 back to Roc.
in preparation a cleanup of the existing RocGlue.roc might also be useful. The code quality on that is not great
especially consistency between the tag union flavors is hard to judge
also it has known bugs, like deriving Hash or Eq when that is invalid
I don't know any rust. I tried it once and thought, that this is above my skills. This is the reason, I use zig for my platforms.
Currently, there is the directory glue/src/
with the file RustGlue.roc and some .rs
files. Should the ZigGlue.roc
file and all the .zig
files be in the same directory, or should they be separated by language?
PR #6211 makes a start on this. I think it would be acceptable to merge this and then add additional functionality, or perhaps we want to get further along on a branch before adding to main? @Oskar Hahn what do you think?
One other question: should we put this not in the roc
repo? I know that long term we theoretically want these to be community maintained and to live elsewhere. Rust is special because it is an example for other to look at and we use it for roc itself.
I think that makes sense in future, but for now I don't have any concerns with it being in the repo. If anything, I think it supports us maturing glue itself by having two independent implementations. We can always move it at a later time. It's buried rather deep and all.
yeah that works for me too, as long as the expectation is clear that we'll move it in the future :thumbs_up:
Luke Boswell said:
PR #6211 makes a start on this. I think it would be acceptable to merge this and then add additional functionality, or perhaps we want to get further along on a branch before adding to main? Oskar Hahn what do you think?
Perfect. I will have a look
12 messages were moved here from #compiler development > Casual Conversation by Oskar Hahn.
I played around a bit with the ZigGlue and was able to generate the glue file for my AoC platform: https://github.com/ostcar/aoc2023/blob/with-glue/platform/glue.zig
https://github.com/roc-lang/roc/compare/main...ostcar:zig-glue
There are some things, that I don't understand or that would be helpful:
dbg
and crash
do not work in theroc glue
spec. It is hard understand the given arguments, when there is no way to inspect them. Would it be possible to add support for this?Part
in roc. But the value of the TagUnion Enumeration {name}
is U1
. Is there a way to get the string Part
for U1
?zig fmt
. This makes it much easier to write good looking zig-code.Oskar Hahn said:
- My simple example only has one tagunion that is called
Part
in roc. But the value of theTagUnion Enumeration {name}
isU1
. Is there a way to get the stringPart
forU1
?
Oh, this was my mistake. I did not give the tagunion any name in roc. I only used [Part1, Part2]
. I get it, that it would be very hard for roc glue
to give it a name :big_smile: After adding (and using) Part : [Part1, Part2]
, it works.
I had a look at dbg
, it's easy enough to add to the platform by adding the following to crates/glue/src/lib.rs
. But I suspect roc is stripping out dbg
or ignoring these so this isn't being called for some reason. Requires further investigation, but it's getting late for me.
#[no_mangle]
pub unsafe extern "C" fn roc_dbg(loc: *mut roc_std::RocStr, msg: *mut roc_std::RocStr, src: *mut roc_std::RocStr) {
eprintln!("[{}] {} = {}", &*loc, &*src, &*msg);
}
You have to call roc glue --dev ...
Woo, teamwork FTW :octopus:
It doesn't quite work for me because the dev backend isn't complete on arm64, so I hit an assertion, but it definitely looks like its trying. So I think we should be able to change something somewhere so the dbg's are called when using roc glue
oh yeah those should definitely Just Work with no flags needed or anything...I think it's just that nobody's ever tried to use dbg
in glue before :big_smile:
Last updated: Jul 26 2025 at 12:14 UTC