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.
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
.
So we don't really have a pattern that generalises at the moment.
This is the first time we've had an implementation in a "truly foreign" language that isn't used to actually build Roc itself.
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
.
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.
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.
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 aCppGlue.roc
that will import the C++ header files as strings and write them into a finalroc_glue.h
.
yeah I think that's the most logical place! :+1:
Cool. I opened a PR there.
Now I'm off to my stag (bachelor) party :partying_face:
awesome, enjoy!!! :cowboy:
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
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.
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.
my guess is just that it's not intentional, and upgrading clang versions would be fine :big_smile:
Yeah that's what I thought
I'll try to upgrade today
Last updated: Jul 06 2025 at 12:14 UTC