Stream: contributing

Topic: glue & std lib for C++


view this post on Zulip Brian Carroll (Dec 09 2023 at 10:59):

In the roc repo we have a Rust implementation of the Roc standard library data structures, at crates/roc_std/
I've been working on a C++ version at https://github.com/brian-carroll/roc-std-cpp
One of the reasons C++ is useful is that we can build on it to expand our bindings for Node and Ruby.
After discussing with @Richard Feldman I'm going to make a PR to move this into the roc repo. It may eventually get moved somewhere else.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:09):

I'm wondering how to organise it though.
There is no glue yet, just the std lib: Str, List, Dict, Box, and Result.
It has a src and test directory, and a Makefile.
So where to put this stuff?
It's not a "crate" because it's not Rust. So maybe not in crates/roc_std? Or maybe it does go there because it logically implements the same thing?
We have a Zig version of the std lib because that's part of the real std lib! And that lives in crates/compiler/builtins.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:10):

So we don't really have a pattern that generalises at the moment.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:10):

This is the first time we've had an implementation in a "truly foreign" language that isn't used to actually build Roc itself.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:13):

One possibility would be to make it a subdirectory of crates/glue because that's kinda what we need it for.
I think longer term we probably will have a CppGlue.roc that will import the C++ header files as strings and write them into a final roc_glue.h.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:43):

When we do get around to generating C++ glue, we'll have to decide whether it generates two files (.cpp and .h) or one (a header-only library). Or maybe you could let the user configure that? I don't work with C++ at all so I'm not very familiar with the pros and cons.

view this post on Zulip Brian Carroll (Dec 09 2023 at 11:46):

Maybe we could detect that from the output filename. If you specify .cpp then you get .h as well. If you specify .h then that's all you get.

view this post on Zulip Richard Feldman (Dec 09 2023 at 12:15):

Brian Carroll said:

One possibility would be to make it a subdirectory of crates/glue because that's kinda what we need it for.
I think longer term we probably will have a CppGlue.roc that will import the C++ header files as strings and write them into a final roc_glue.h.

yeah I think that's the most logical place! :+1:

view this post on Zulip Brian Carroll (Dec 09 2023 at 12:25):

Cool. I opened a PR there.
Now I'm off to my stag (bachelor) party :partying_face:

view this post on Zulip Richard Feldman (Dec 09 2023 at 12:58):

awesome, enjoy!!! :cowboy:

view this post on Zulip Pearce Keesling (Dec 09 2023 at 18:09):

Love that someone is working on cpp support. Something I've been loosely considering is trying react native turbo modules in roc (probably way lower overhead than doing a wasm build), and bridging through to rust was gonna be a hassle

view this post on Zulip Brian Carroll (Dec 17 2023 at 11:10):

Coming back to this after a while...
The PR is failing CI with a mysterious bug that only seems to happen when compiling with Clang 11.1, which, for some reason, is what we are using in Nix.
So I'm wondering - why are we on such an old version of Clang? This seems to imply that we have two different LLVM versions in Nix, which seems a bit heavy.

view this post on Zulip Brian Carroll (Dec 17 2023 at 11:14):

It would certainly be nice to support old C++ compilers at some point. I'm sure they are still in use. But I am not keen to bundle that work into this first PR. The intent was just to copy stuff across from my own repo to the Roc repo. I don't have time to do more work on this at the moment. And I have not been able to isolate or fix this issue by changing the source code.

view this post on Zulip Richard Feldman (Dec 17 2023 at 12:05):

my guess is just that it's not intentional, and upgrading clang versions would be fine :big_smile:

view this post on Zulip Brian Carroll (Dec 17 2023 at 12:26):

Yeah that's what I thought

view this post on Zulip Anton (Dec 18 2023 at 09:42):

I'll try to upgrade today


Last updated: Jul 06 2025 at 12:14 UTC