Fix offset of fields represented as opaque blobs of bytes.

Crubit represents some C++ fields as opaque blobs of bytes in the
generated Rust structs.  Today this happens for `[[no_unique_address]]`
fields.  In the future, this may also happen for fields of an otherwise
unsupported C++ type.

The opaque blobs of bytes intentionally have no alignment (to precisely
control their size).  Unfortunately, the offset of such fields may
depend on the alignment - the tests added by this CL illustrate the
scenarios where the offset of the generated Rust field might not match
the offset of the original C++ field.

This CL inserts an additional `__padding<N>` field as needed to fix the
offset of fields represented as opaque blobs of bytes.

PiperOrigin-RevId: 449354029
12 files changed
tree: 4eaf1c4a0aa58cdd0812d6ecaa4d7e8de40c998a
  1. cc_template/
  2. common/
  3. docs/
  4. lifetime_annotations/
  5. migrator/
  6. rs_bindings_from_cc/
  7. BUILD
  8. CODE_OF_CONDUCT
  9. CONTRIBUTING
  10. LICENSE
  11. README.md
README.md

Crubit: C++/Rust Bidirectional Interop Tool

Extremely experimental interop tooling for C++ and Rust.

Please don‘t use, this is an experiment and we don’t yet know where will it take us. There will be breaking changes without warning. Unfortunately, we can't take contributions at this point.