G'day all, hand rolling types can be tricky sometimes. So I made a simple script using roc glue
which prints out the fields in a struct so you can know what order they should go in.
For example this type isn't necessarily obvious how it should be represented in C.
Command : {
program : Str,
args : List Str, # [arg0, arg1, arg2, arg3, ...]
envs : List Str, # [key0, value0, key1, value1, key2, value2, ...]
clearEnvs : Bool,
}
So using this script in roc-glue-code-gen you can do;
$ roc glue examples/alignment.roc examples/test/ examples/platform.roc
🎉 Generated type declarations in:
examples/test/
$ cat examples/test/types.txt
{id: (@TypeId 2), name: "args"}
{id: (@TypeId 2), name: "envs"}
{id: (@TypeId 1), name: "program"}
{id: (@TypeId 3), name: "clearEnvs"}%
Which translates in Rust to
#[repr(C)]
#[derive(Debug)]
pub struct Command {
pub args: RocList<RocStr>,
pub envs: RocList<RocStr>,
pub program: RocStr,
pub clearEnvs: bool,
}
I should probably put a roc CLI app at the top level of that repo to make this kind of thing easier to use... :idea: not a priority RN, I'd like to finish a few other things
I wish I saw this sooner! I'll be sure to use this going forward as I'm pretty much 100% hand rolling the glue now for my roc-iced platform
Last updated: Jul 06 2025 at 12:14 UTC