Stream: compiler development

Topic: Getting Roc signatures from platform code


view this post on Zulip Lua (Jun 23 2024 at 08:13):

I'm writing a Swift glue package for Roc platform development, and I'm working on autogenerating safe bindings between the languages in a way that would essentially work like a mixed language target. What would be the best way to get types (and their layouts) and signatures from the Roc side to have something I could generate the bindings from? I would also need to know how these translate to C signatures

Swift would get access to declarations provided by the Roc side, and Roc would get access to everything annotated with an @roc attached macro (which could conveniently generate the ffi and raise compile errors if required). In theory it would be completely safe and seamless, and not introduce any overhead vs writing the ffi manually :smile:

view this post on Zulip Lua (Jun 23 2024 at 09:34):

So for instance how would I expose a generic function across ffi? for example:

@roc func append<T: RocType>(_ element:  T, to list: RocList<T>) -> RocList<T> { ... }

What would the generated C ABI signature have to look like?

view this post on Zulip Luke Boswell (Jun 23 2024 at 09:53):

Does @Folkert de Vries 's answer here help? https://roc.zulipchat.com/#narrow/stream/395097-compiler-development/topic/Glue.20Types.20Specification/near/445787553

view this post on Zulip Luke Boswell (Jun 23 2024 at 09:53):

I made a glue.roc script that generates a types.json file with the types provided from roc compiler. I found playing with a super simple platform, and tweaking the type of mainForHost I could see how the glue types changed. But I'm not sure if this helps you much?

view this post on Zulip Luke Boswell (Jun 23 2024 at 09:54):

This sounds like a great project, I wish I could be of more assistance.

view this post on Zulip Luke Boswell (Jun 23 2024 at 09:59):

You can run that glue script using roc glue glue.roc host/ platform/main.roc

view this post on Zulip Lua (Jun 25 2024 at 09:40):

Luke Boswell said:

Does Folkert de Vries 's answer here help? https://roc.zulipchat.com/#narrow/stream/395097-compiler-development/topic/Glue.20Types.20Specification/near/445787553

I was hoping there would be something like https://github.com/swiftlang/swift/blob/main/docs/ABI/TypeLayout.rst#fragile-struct-and-tuple-layout where I could find a brief overview of the abi. I know Rust, though not as well as Zig or Swift, but hopefully I will be able to get the information I need from the source code instead :smile:

Luke Boswell said:

I made a glue.roc script that generates a types.json file with the types provided from roc compiler. I found playing with a super simple platform, and tweaking the type of mainForHost I could see how the glue types changed. But I'm not sure if this helps you much?

It might. I definitely need a way to get the types somehow, but I am not sure this will have all the information I need. I tried to see how the lsp is getting type information but it seems to be reusing code from the compiler — I'm using Zig not Rust so I can't do that.

Luke Boswell said:

This sounds like a great project, I wish I could be of more assistance.

Thank you :smile:


Last updated: Jul 06 2025 at 12:14 UTC