Skip to content

Latest commit

 

History

History
97 lines (90 loc) · 7.74 KB

File metadata and controls

97 lines (90 loc) · 7.74 KB

Rust/C++ Interop Tool Support

This document is an initial, partially reviewed draft

This table describes how various Rust/C++ interop use cases and problems are supported by major interop tooling, including the Rust compiler:

  • Crubit auto-generates a wide range of supported Rust and C++ interop bindings. Glue code and customisation is in the original source code, and the build system. Currently depends on the bazel build system, but they are actively working on cargo integration.
  • cxx: auto-generates supported safe Rust and C++ interop bindings. Glue code is in the original source code, customisation and recent language features are limited. Compatible with multiple build systems, including cargo.
  • Zngur: auto-generates a wide range of declared Rust and C++ interop bindings, focusing on accessing Rust from C++. Glue code is in C++, as the more expressive language. Declarations and customisation are in .zng IDL files. Compatible with multiple build systems.

Key:
⛔ No Support
🔁 In progress
◓ Basic or Partial Support
✅ Good Support
? Needs Analysis
blank Out of Scope

Use Case or Problem Statement rustc Crubit cxx Zngur
Async C++/Rust Interop
Basic Types rustc Crubit cxx Zngur
Compatible type layouts
Create a vector containing FFI types
Call C++ Iterators from Rust
Use FFI string types
Match standard library type layouts
Lossless FFI integer type mappings 1
Convert Rust & C++ Result types
Unify C++ forward decls to Rust types
Advanced Types rustc Crubit cxx Zngur
Init C++ objects in-place in Rust 🔁2
Passing non-POD types
Use a prefix of the full Rust/C++ type 🔁3 ?
Rust Traits for C++ Types ◓?
Rust dyn traits from C++ ?
Cross-language class inheritance
C++ templates with Rust types
Define a C++ enum from Rust 4
Safety rustc Crubit cxx Zngur
Cross-language object ownership
Lifetimes in C++ code
FFI thread safety ? ?
Rust & C++ unwinding compatibility
Skip non-null pointer null checks ?
Allocator FFI compatibility 🔁5
Overloading rustc Crubit cxx Zngur
Call an overloaded C++ function from Rust 🔁6
Type-dependent C++ call safety 🔁7 ?
Building & Linking rustc Crubit cxx Zngur
Add Rust to existing C/C++ builds 8
Link Time Optimisation (LTO) Interop

Footnotes

  1. ffi_11 crate

  2. Rust project goal

  3. Rust compiler experiment, requires a Rust UnsafeCell to wrap C++ mutable class members

  4. Rust nightly lang experiment

  5. Rust Zulip discussions

  6. Rust compiler experiment

  7. Rust RFC

  8. Rust stabilisation RFC