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
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.
- Clone down this repository
- Run
cargo install --path . uniffi-bindgen-nodeshould be in~/.cargo/bin- make sure this is part of yourPATH.
Run uniffi-bindgen-node -- <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.
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