Rust FFI: XXX Call Rust & Rust Call XXX
hhstore opened this issue · 9 comments
hhstore commented
hhstore commented
Rust + FFI 方案
- Rust 是非常非常适合做 core lib 层的跨平台方案.
- Flutter 适合 UI 层(交互层) 的跨平台方案.
- Rust + Flutter 是非常完美的架构组合方案, 兼顾效率和性能.
- FFI
1. 主调方(as Caller): Rust call C/C++
- ✅ 见⬇️
2. 被调方(as Callee): C/C++ call Rust
- ✅ 见⬇️
3. 双向桥: rust vs c++
- ✅ https://github.com/dtolnay/cxx
- ⭐⭐⭐⭐⭐
- rust + c++ 双向桥
- https://cxx.rs/index.html
4. 其他:
- ✅ https://github.com/shekohex/flutterust
- ✅ https://github.com/TimNN/cargo-lipo
- ✅ https://github.com/rodrimati1992/abi_stable_crates
参考:
搜索包:
hhstore commented
Rust FFI: C/C++ Call Rust
🔥 工具链:
uniffi-rs
- ✅ https://github.com/mozilla/uniffi-rs
- ✅ https://github.com/NordSecurity/uniffi-bindgen-go
- ✅ https://github.com/NiallBunting/uniffi-rs-dart
cbindgen
其他
🔥 示例项目:
sled-native
- https://github.com/spacejam/sled/tree/main/bindings/sled-native
- https://github.com/spacejam/sled/blob/main/bindings/sled-native/src/lib.rs#L18
💡 参考:
- ✅ Rust FFI 编程 - cbindgen 工具介绍
- ✅ Rust FFI 编程 - cbindgen 使用示例
- ✅ https://guonaihong.github.io/post/call-c-dynamic-library-in-rust-bingen-2/
- ✅ 案例: https://github.com/lesterli/rust-practice/blob/master/ffi/example_03/cbindgen.toml
- ⭐⭐⭐⭐⭐
# 安装:
cargo install --force cbindgen
# 生成:
cbindgen --config cbindgen.toml --crate my_rust_library --output my_header.h
教程:
- https://rustcc.cn/article?id=9219a366-84d3-49c8-b957-dfbade1257fc
- https://stevenbai.top/rustbook/book/interoperability/rust-with-c.html
- https://github.com/bitcoin-core/secp256k1
- binding: https://github.com/rust-bitcoin/rust-secp256k1
- https://doc.rust-lang.org/nomicon/ffi.html#calling-rust-code-from-c
- https://wiki.jikexueyuan.com/project/rust-primer/ffi/compiling-rust-to-lib.html
- 使用Rust加速你的Python代码
hhstore commented
Rust FFI: XXX Call Rust
- TODO
hhstore commented
Rust FFI: Rust Call C/C++
工具链:
- https://github.com/rust-lang/rust-bindgen
- https://github.com/adetaylor/rust-bindgen
- ⭐⭐⭐⭐⭐
- 有用的 fork
- https://github.com/google/autocxx
- ⭐⭐⭐⭐⭐
- Google 项目
- https://github.com/rust-qt/ritual
- ⭐⭐⭐⭐⭐
示例参考项目:
- https://github.com/rust-bitcoin/rust-secp256k1/blob/master/secp256k1-sys/build.rs#L31
- ⭐⭐⭐⭐⭐
- https://github.com/fitzgen/bindgen-tutorial-bzip2-sys
- 官方示例
- https://github.com/lesterli/rust-practice/tree/master/ffi/secp256k1-sys
👿 Mac M1 兼容性问题:
- rust ffi 在 MacOS M1 下, 有一些兼容性问题.
- rust-lang/rust#73908
- rust-bitcoin/rust-secp256k1#283
教程:
hhstore commented
Rust FFI: Flutter Call Rust
🔥 工具链
- https://github.com/brickpop/flutter-rust-ffi
- 使用方式
- https://github.com/fzyzcjy/flutter_rust_bridge
- ⭐⭐⭐⭐⭐
- 已经支持除 web, 所有平台. web 支持在开发ing.
- 使用示例: https://github.com/fzyzcjy/flutter_rust_bridge/blob/master/frb_example/with_flutter/rust/src/lib.rs
- web 支持进展: fzyzcjy/flutter_rust_bridge#315
🔥 典型案例:
一个漫画阅读器:
hhstore commented
Rust + FFI + Java(JNI):
hhstore commented
Rust + FFI + Mac M1 问题:
- https://xuanwo.io/2021/10-rust-cross-aarch64/
- 一个可能的解决思路.
- 待尝试.
hhstore commented
1
hhstore commented
1