dart_cpp_bridge 2.2.0 copy "dart_cpp_bridge: ^2.2.0" to clipboard
dart_cpp_bridge: ^2.2.0 copied to clipboard

Dart ↔ C++20 bridge (FRB-like). Dart FFI session layer; Native Assets build hooks for Android, iOS, Linux, macOS, and Windows.

dart_cpp_bridge #

pub package

Dart/Flutter ↔ C++20 binding generator, inspired by flutter_rust_bridge.

Write normal C++ code and call it from Dart/Flutter, with sync, async, stream, and Dart-closure reverse calls.

What's this? #

  • Write plain C++20 functions and classes — no hand-written FFI boilerplate
  • Codegen generates Dart API + C++ wire dispatch from annotated headers
  • Built-in runtime based on Asio + stdexec senders and coroutines
  • Supports Android, iOS, Windows, Linux, and macOS

Runtime model and compatibility #

The package uses the stdexec-based runtime. It contains a broad C++ async/concurrency migration from the legacy async-simple model. The Dart API, C ABI, wire protocol, generated file layout, and method-ID contracts remain stable, but C++ async business code is not source-compatible with the legacy runtime. See the version guide before copying C++ async examples or migrating existing code.

When migrating from the legacy runtime:

  • Use stdexec::task<T> or another stdexec sender instead of async_simple::coro::Lazy<T>.
  • Migrate Executor / .via(...) and Signal / Slot to stdexec schedulers, current sender operations, and stop tokens.
  • Regenerate bindings with the matching dcb_gen_tool release; do not mix legacy generated native code with current runtime headers or tooling.
  • Build native code as C++20 and link the vendored stdexec target. Keep blocking work off the single-threaded I/O scheduler.

Quickstart #

See the documentation for a complete quickstart:

Show me the code #

C++

#include <dart_cpp_bridge/annotate.h>
#include <stdexec/execution.hpp>
#include <string>

BRIDGE_SYNC int32_t add(int32_t a, int32_t b) { return a + b; }

BRIDGE_ASYNC
stdexec::task<std::string> greet(std::string name) {
  co_return "Hello, " + name;
}

Dart

import 'package:my_app/src/native_gen/api/api_fn.dart';

void main() async {
  await DcbLib.init();

  print(add(a: 1, b: 2));            // 3
  print(await greet(name: 'World')); // Hello, World
}

Documentation #

Acknowledgments #

  • Flutter Rust Bridge — architecture and product shape inspiration
  • Asio — event loop and asynchronous I/O
  • stdexec — sender/receiver and scheduler foundation
  • MPMCQueue — lock-free bounded MPMC queue (strict FIFO), the buffer of co::mpsc::bounded channels
  • Dart / Flutter team — FFI, Isolate, NativeFinalizer, and the broader Dart native ecosystem

License #

MIT — see LICENSE.

0
likes
140
points
787
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

Dart ↔ C++20 bridge (FRB-like). Dart FFI session layer; Native Assets build hooks for Android, iOS, Linux, macOS, and Windows.

Homepage
Repository (GitHub)
View/report issues

Topics

#ffi #native #interop #cpp

License

MIT (license)

Dependencies

code_assets, ffi, hooks

More

Packages that depend on dart_cpp_bridge