Skip to content

livekit/uniffi-bindgen-node

Repository files navigation

Warning

uniffi-bindgen-node is no longer being actively developed. It is still in use, and currently the only way to run uniffi enabled Rust on Node, Deno and Bun. But it is incomplete.

The development effort is now shifted towards adding NodeJS support to uniffi-bindgen-react-native which already supports React Native and WASM. Further details on that effort can be found in this issue.

During this transitions, pull-requests on this repo are going to take longer than usual to review and merge, and some may not be merged.

When the uniffi-bindgen-react-native gains NodeJS support it will be renamed to uniffi-bindgen-javascript, and this project will be deprecated.

uniffi-bindgen-node

uniffi-bindgen-node is an experimental uniffi bindgen for node.js. It's heavily inspired by much of the excellent work on uniffi-bindgen-react-native and uniffi-bindgen-cpp. It generates typescript bindings and behind the scenes uses ffi-rs to load the input dynamic library file and call the relevant operations.

Warning

uniffi-bindgen-node is a work in progress, and doesn't yet support the whole uniffi ffi specification.

Implemented features:

  • Records
  • Regular function calling
  • Async function calling
  • Enums (both bare enums and enums with associated fields)
  • Objects (multiple constructors, async + regular method calling)
  • Error enums / exceptions

Currently missing features:

  • Traits (including node -> rust function calls support)
  • Any sort of comprehensive test suite

Differences from uniffi-bindgen-react-native

On the surface, these projects may seem to have similar aims, but there are some important differences. uniffi-bindgen-react-native only supports mobile targets and web targets, and doesn't have explicit node support. In addition, in order to compile the web target, the uniffi rust bindings need to be compiled for wasm32-unknown-unknown, which depending on what the rust end of the bindings are doing, may prove to be difficult given the lack of standard library availability. Also, the uniffi-bindgen-react-native project uses a multi phase build process which fits well into a react native workflow, but is fairly involved. uniffi-bindgen-node aims for a model much closer to the python bindings, where the build code bridges the dynamic library to node.js directly.

Installation

  1. Clone down this repository
  2. Run cargo install --path .
  3. uniffi-bindgen-node should be in ~/.cargo/bin - make sure this is part of your PATH.

Usage

Run uniffi-bindgen-node generate <lib_path>, passing a dynamic library (dylib/dll/so) build to export a uniffi interface. See output/ for the results. For more complicated scenarios, run uniffi-bindgen-node --help.

Development

Historically, local development has consisted of compiling ad hoc dynamic libraries, pointing the bindgen at these, and then writing ad hoc scripts to exercise the resulting api interface.

For the time being, there is no comprehensive test suite. Some of these ad hoc scripts probably could end up being turned into tests.

On mac / linux, a test_bindgen.sh script exists to automate this process. This script will build the bindgen, copy the relevant dynamic library into the proper location, and run your test script against the bindgen. Example script usage: ./test_bindgen.sh path/to/libexample.dylib path/to/test-script.ts

About

Mechanism for generating ffi bindings between node and rust using uniffi

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors