Transition C/C++ Codebase to Rust


#1

Greetings,

I ask your help because I could not find information relating to this topic via search engine:

How to gradually transition a large existing codebase written in C or C++ over to Rust?

Bonus Points: If the transition can be done in an object by object, source file by source file etc. fashion, possibly keeping the project compilable?

I have seen an interesting approach done in the Nim language, a language with similar goals to Rust IMO. A developer took the old Unix v6 sources and rewrote it in Nim. Fair piece of work, but why not.

Somewhere in the middle he realized that he could do the same, but doing it source file by source file, thus gradually replacing all of the C with Nim, while having a compilable code base all the time during the process.

How to do a similar gradual transition with Rust without having to rewrite everything at once in Rust? ie. mixed existing C/C++ code base and part already rewritten in Rust?

Would appreciate any ideas :slight_smile:


#2

I would split off libraries, implement them in Rust, and then expose a C ABI from the Rust, so the rest of the code doesn’t even realize.

The above is the exact approach Firefox is taking. There’s only a bit of code so far, but it’s growing…