logoalt Hacker News

abbefaria27yesterday at 6:30 PM6 repliesview on HN

What’s the story for Rust-C++ interoperability these days? That’s what kills adoption. Most C++ devs I know like the idea of Rust, but no one is going to go rewrite 30 years of working code. It needs to be something you can incorporate gradually.


Replies

afdbcreidyesterday at 6:52 PM

There's an interop initiative by the Rust Foundation, there is a project goal to map the problem space, there was an effort to introduce an attribute (`#[rustc_splat]`) to allow calling overloaded functions, and there are various community-generated tools for more or less automated bindings generation.

uncle_kostyatoday at 6:28 AM

What we do at work is defined a clear boundary and use extern "C" functions in Rust to make them callable from C++, and the same for callbacks.

Required some effort but we're happy with the result.

nicoburnsyesterday at 7:30 PM

There's a huge push for this from the big companies adopting Rust. Google has been developing https://github.com/google/crubit. The older cbdingen is still usable if more limited (it's what Firefox uses for some pretty involved interop).

estebankyesterday at 10:39 PM

You might want to take a look at https://github.com/hkalbasi/zngur

Calling Rust from C++ seems to be more technically straightforward than the reverse.

kibwenyesterday at 7:09 PM

Rust's raison d'être is to improve the confidence of the security-critical parts of your system. You don't need to rewrite all 30M lines of code to benefit from it, you just need to identify the 1% of your codebase with the greatest attack surface (e.g. any internet-facing string parser), cordon that part of the codebase off with a C ABI, and then convert that part to Rust. This is similar to how Firefox incorporates bits of Rust into its own C++ codebase over time (e.g. for parsing URLs).

drop_staryesterday at 6:32 PM

ya our codebase is 30m lines of c++