4 ms·
It’s curious to me the abscence of c++ interop as a focus. I understand there may be more important problems within the Rust community and it’s not yet ready to
by vlovich123 5y ago
It’s curious to me the abscence of c++ interop as a focus. I understand there may be more important problems within the Rust community and it’s not yet ready to take center stage, but there’s soooo much to be gained from being able to piecemeal rewrite c++ code into rust in a low-friction manner or to make Rust as easy an option to reach for as C++ to write new code for an existing c++ codebase (eg a goal could be that all new code in Chrome/Firefox should be being written in Rust). The cxx crate is neat and a good start but it’s still too immature and ultimately you are limited to anything that can be hidden behind thin interfaces.
- bluejekyll 5y agoIsn’t this as much a problem with C++ as it is with Rust? Both tend to need to drop to C for FFI. So you’d need a C++ stable ABI as well as one for Rust.
- vlovich123 5y agoLook at the cxx crate. I don’t care that there’s a C FFI in the middle. Just that it needs to look like magic. In other words, most or all c++ types, including templates, without any real complexity on the part of the user. Conversely Rust types are accessible from c++ without complexity. I think the latter part is mostly true although some patterns need some TLC. The former is still extremely immature.
- deleted 5y ago[deleted]
- mlindner 5y agoDoesn't C++ not have a stable ABI? Doesn't that kind of make it difficult to interop with it? The ABI is an implementation defined thing by the compiler, right?
- vlovich123 5y agoYou don’t need a stable ABI per se if you’re working with source-level interop. Also, while it doesn’t have one in theory, it does in practice on each platform if I recall correctly.
- codeflo 5y agoIf you consider the compiler to be part of the platform, that’s mostly true. I think the hard problem in practice is that headers and templates make for a very fuzzy boundary between library code and client code. Calling C++ from Rust already works fine for traditional OO code, but it’s hard to imagine that anything could ever use modern templated C++ code that isn’t a full superset of C++.
- vlovich123 5y agoIf I'm not mistaken you can mix'n'match shared libraries built by either compiler on Linux. I think that's also true for individual object files within the executable. Same is true for Windows. I can't recall the state on Darwin & I don't know the state of other platforms. I don't think templated C++ code needs to be a full superset of C++. For example, cxx provides bridged implementations for CxxVector. If cxx provided an easy-to-use mechanism to define your own bridging type without a lot of boilerplate, that could open up far more interop than is possible today.