跳转到内容

基础(v2)

dart_cpp_bridge 是一个 Dart ↔ C++20 桥接库,灵感来自 Flutter Rust Bridge。业务代码只需 写普通 C++ 函数或 stdexec::task<T> / sender 流水线,桥接层负责编解码、 调度、生命周期和 Dart API 生成。

  • 同步BRIDGE_SYNC 直接返回值;
  • 异步BRIDGE_ASYNC 使用 stdexec::task<T> 或受支持 sender, Dart 侧得到 Future<T>
  • NormalBRIDGE_NORMAL 把阻塞工作放到线程池;
  • StreamStreamSink<T> 生成 Dart Stream<T>
  • DartFn — C++ 可以在等待 Dart 闭包回复时挂起;
  • Channelco::oneshotco::mpsc 连接 worker 与协程;
  • Opaque / data class — 生成 handle 和值类型编解码;
  • 跨运行时调度 — 外部事件循环提供普通 stdexec scheduler。
技术
C++ C++20
异步模型 stdexec sender / stdexec::task
内置事件循环 Asio io_context,默认一个 io runner
阻塞工作 Asio thread pool
取消 stop token
Codegen Python 3.13 + libclang-ng,固定版本并校验 hash
构建 CMake 3.25+ 和 Native Assets hook