tree: 0447fc15a2a06bc4bab1cdc4ce25e9b267e4b053 [path history] [tgz]
  1. meta/
  2. src/
  3. blobstore.h
  4. BUILD.gn
  5. main.cc
  6. main.rs
  7. README.md
  8. run_and_compare_output.rs
src/lib/fuchsia-cxx/examples/basic/README.md

Basic CXX example

This example is a slightly modified version of the demo from https://github.com/dtolnay/cxx, adapted to demonstrate usage of cxx within the Fuchsia tree.

It also includes both a Rust and C++ implementation of the toy main() that exercises the FFI to demonstrate how to use the generated FFI from either direction.

For general information about using cxx, see https://cxx.rs and https://docs.rs/cxx.

Files

  • BUILD.gn - Definitions of GN build targets showing how to use Fuchsia's rust_cxx_ffi_source_set template and how to use such a target in downstream Rust and C++ targets.
  • src/lib.rs - Contains the #[cxx::bridge] module which defines the type and function signatures for both the Rust and C++ sides of the FFI boundary, as well as implementations of types and functions on the Rust side.
  • src/blobstore.cc - Implementations of types and functions on the C++ side.
  • blobstore.h - Declarations of types and functions on the C++ side.
  • main.rs - Source for a Rust binary that exercises the BlobstoreClient FFI defined in the above files.
  • main.cc - Source for a C++ binary that also exercises the BlobstoreClient FFI, and has equivalent behavior to main.rs.