News for hackers. Stuff that matters.
Re:Closing the gap: cross-language LTO between Rust and C/C++ by pornel on Friday September 20, 2019 @10:23AM (#21026979)
The thorny issue is C++ templates, which are instantiated in a complicated way that depends on C++ syntax. You can't "just" compile and link Boost in (as you'd do with a C library). You have to compile a fragment of C++ source code for every line of Rust code that uses a Boost template, and you have to translate Rust code used in template arguments to valid C++ code, so that template substitutions will be valid.

This seems doable for simple cases, but libraries like Boost push templates to their limits, so they're not the easy cases.

Re:Closing the gap: cross-language LTO between Rust and C/C++ by zelly on Friday September 20, 2019 @11:22AM (#21027692)
Yes I realized porting a template library to Rust would basically require implementing a whole new compiler (easily more difficult to implement than all of Rust). Like you said, the only workable way is to link to C++ source code (fully translated units/obj files) compiled by clang. Rust would have to learn how to use C++'s name mangling, data alignment, and calling conventions to be able to invoke C++ functions. See my other post in this thread.

Basically it would be a "extern C++". The FFI to C++ would hopefully have as low overhead as "extern C" while making it easier for C++ codebases to gradually adopt Rust.

Re:Closing the gap: cross-language LTO between Rust and C/C++ by pornel on Friday September 20, 2019 @02:54PM (#21030014)
> Rust would have to learn how to use C++'s name mangling, data alignment, and calling conventions to be able to invoke C++ functions.

This is already supported (via Bindgen).

Re:Closing the gap: cross-language LTO between Rust and C/C++ by zelly on Friday September 20, 2019 @03:55PM (#21030575)
Thanks for pointing me to this. Wow. Looks like I can finish learning Rust.