Skip to content
项目

jhugman/uniffi-bindgen-react-native

在 GitHub 查看

关于

使用 Rust 构建 React Native Turbo Modules

网站与应用开发

这些数字如何统计

可以做什么

  • with JSI C++ to call Rust from TypeScript and back again, and
  • a Turbo-Module that installs the bindings into a running React Native library.
  • with a WASM binding crate
  • with the @ubjs/node N-API runtime, loading your compiled Rust cdylib at runtime. See the Node.js reference.

实测星标增长

24小时
0
7天
+1
15天
+2
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

CI Compatibility (nightly matrix) Compatibility (PR gate)

🦀 uniffi-bindgen-react-native

uniffi-bindgen-react-native is a tool that generates TypeScript bindings for Rust code, making it usable in React Native apps, web pages, and Node.js. It builds on UniFFI, Mozilla's bindings generator ecosystem.

With this tool, you can write your business logic once in Rust and access it seamlessly from TypeScript, whether you're developing for mobile platforms, the web or servers.

UniFFI provides procedural macros to describe your API, prioritizing expressivity and memory safety. This makes it ideal for portability.

Packages

  • uniffi-bindgen-react-native (npm) — CLI (ubrn), tooling, and the legacy-named runtime that older generated code imports from.
  • @ubjs/core (npm) — same runtime bytes, new identity. New generated code imports from here. See typescript/README.md.
  • @ubjs/node (npm) — N-API runtime backend; required for Node and Bun consumers of generated bindings. See runtimes/napi/README.md.

✨ Features

It provides tooling to generate safe and performant TypeScript to access Rust from:

  • 📱 React Native
    • with JSI C++ to call Rust from TypeScript and back again, and
    • a Turbo-Module that installs the bindings into a running React Native library.
  • 🌐 Web pages
    • with a WASM binding crate
  • 🖥️ Node.js (new)

All using the same proc macros: you annotate your Rust once, and build for Android, iOS, the Web, and Node.js.

Javascript hosts the Rust library, and uniffi-bindgen-react-native and uniffi facilitate the communication between the two:

  • Same thread calling across the FFI from Javascript to Rust.
  • Async calls from Javascript to Rust
  • Same thread callbacks from Rust to Javascript
  • Async callbacks from Rust to Javascript
  • Pass by Reference (for "Objects")
  • Pass by Value (for "Records")
  • Enums and tagged unions

Why use uniffi-bindgen-react-native instead of wasm-bindgen?

  • uniffi-bindgen-react-native generates a wasm-bindgen crate, from uniffi annotations.
  • when you come to use your Rust crate in another context (say, from Python, or Kotlin, or React Native), then you can generate FFIs for those platforms, all with the same uniffi annotations.

🚀 Getting Started

If you're ready to start, then begin with a step-by-step tutorial to make a Rust turbo-module and then run it in web page with WASM.

If you're new to UniFFI, then the UniFFI user guide or the UniFFI examples are interesting places to start.

🤔 Why uniffi-bindgen-react-native?

  • 🧩 Spend more time writing TypeScript and Rust, less time hand-writing FFIs
  • 🌍 Your Rust SDK is portable across multiple languages

Who is using uniffi-bindgen-react-native?

Prior art and related projects

Notice

Now uniffi-bindgen-react-native supports WASM, the React Native no longer seems appropriate. In the near future, we'll change the name to uniffi-bindgen-javascript. Backwards compatibility will be ensured.

Contributing

If this tool sounds interesting to you, please help us develop it! You can:

Code of Conduct

This project is governed by Mozilla's Community Participation Guidelines.

Funding

uniffi-bindgen-react-native is led by James Hugman, with deep collaboration from the Filament engineering team, funded by:

License

MPL-2.0

探索相关项目

加载中…