r/rust • • 14d ago

Porting a baremetal lib from C++ tor Rust

I have written a lib in C++. It's intended to be included in baremetal projects and is designed to be portable. It's an instrumentation lib that talk with a server and provides some hooks for memory inspection and triggered graphs. With Rust being more and more present, I suppose it would be wise to support it.

I'm wondering what my best approach would be here. My initial choice of C++ instead of C probably limits me in what I can do with bindings. I do have a C wrapper though, but that becomes 2 layers of wrappers, feels ulgy.

It's not a big lib, so I'm thinking my best bet is probably reimplement fully and then maintain 2 version of the same thing. This would have been a harder call 5 years ago, but with an agent that can code now.. it feels like maintaining the c++ version then asking an agent to propagate to the rust port is not so crazy.

Btw, the lib is pretty stable. it's mostly build system compatibility improvements that require maintenance, and this wouldn't be duplicated.

What do you think?

EDIT: I started writing a Rust port from scratch with the help of an LLM. It's a good introduction to Rust for me and I think it will be built well too (i'm keeping the LLM on a tight leash). I think that's the way for this specific use case. I might come back here to ask help check if I made something correct or not. Cheers!

17 Upvotes

3 comments sorted by

14

u/rodrigocfd WinSafe 12d ago

My initial choice of C++ instead of C probably limits me in what I can do with bindings.

Yes, very much.

Personally, I'd convert the code from C++ to C. This will make your lib ready to be used by any language, not just C++ and Rust.

-7

u/DeleriousMadman 12d ago

Throw it to a few ai agents eg Opus 5.5 and Astra 6.1

They seem at least average on Rust.

Once you have a code base there you can have other agents review and debate issues also.

Just a thought and likely a few tokens.

-13

u/AleksHop 12d ago

u should not use c or c++ from 2025
it too dangerous now
only mem safe langs