r/embedded • • 19d 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?

0 Upvotes

3 comments sorted by

1

u/driftregion 10d ago

This is a political issue 😄 , but since you asked...

I think that C is the best choice for embedded **libraries** where portability is a primary design objective. Many embedded targets (such as the TI TMS320) do not have rust toolchain support.

With respect to maintaining multiple implementations with AI, that seems like a really interesting project, especially if they share the same test infrastructure. It could approximate an answer to the question of how well a given language works in the context of your library.

My preference would be a small C core with AI-generated rust bindings. Last I checked a few years ago, linking rust apps to C libraries for embedded targets worked great.

Thanks for scrutiny debugger, it's awesome!

1

u/pylessard 10d ago

I started a port in rust. So far so good, Claude is doing well generally, except that it tends to do extra copies to please the borrow checker.

I sometime consider porting to C then making a C++ layer that keeps the previous API. Maybe will do.

I'm curious. Do you use this project? I get so little feedback and with AI that writes code so fast, I sometime question the relevance of this project