cxx
cxx copied to clipboard
RFC: Cross-bridge dependencies
Currently, there is no way to "communicate" between C++ bridges depending on each other except for static compile-time checks, which verify that the types indeed fulfil the requirements in the dependent bridge (see for example https://github.com/dtolnay/cxx/pull/1181, which verifies that the destination is indeed a RustType
). This works, but of course places an additional burden on the developer (e.g., specifying correct namespace).
The bridge compilation already generates C++ code before generating Rust code and the bridges are compiled/generated in the dependency order.
The idea is to generate an additional piece of information for each bridge with serialized type information, which can be used by dependent bridges to get information about existing types and allow using them directly.
The information would reside in the target
directory somewhere at a well-known location.
The information can then be used in a dependent bridge for example by the means of an use
statement in the bridge, which would load type information from that file.
Although currently there is not much information to pass, we already have further changes to cxx
prepared, which allow value passing of Rust objects to C++. The layout information can then be propagated to dependent bridges using the same mechanism, instead of re-specifying it each time. Likely the same can be done in the other direction (C++ types value-passed to Rust) and likely it would also help greatly simplifying implementation of "standard" C++ types wrapping Rust types (and likely vice-versa) by auto-generating bridge functions instead of manual coding for each type as done today.
Ideas/opinions?