This project builds a Node.js package, for the rgb-lib Rust library, which is included as a git submodule. The bindings are created using the rgb-lib C++ bindings, which are located inside the rgb-lib submodule, and Swig.
First install the package:
npm install rgb-lib
Then import it as:
const rgblib = require("rgb-lib");
⚠️ Warning: memory will be leaked if not taken care of manuallyCheck the example to see how you can manually avoid memory leaks
In order to build Node.js bindings, first clone the project
(git clone https://github.com/RGB-Tools/rgb-lib-nodejs --recurse-submodules
),
enter the project root (cd rgb-lib-nodejs
) and finally follow the In
docker or Local instructions.
The procedure will internally build rgb-lib C++ bindings and use them to generate the Node.js ones.
Both instructions will generate the following files:
librgblibcffi.so
inrgb-lib/bindings/c-ffi/target/debug/
rgblib.hpp
inrgb-lib/bindings/c-ffi/
swig_wrap.cxx
in the project root
- install dependencies: docker
- from the project root, run:
npm run docker-build
As a tip, to speed up development builds you can add the following volumes in the compose file:
- ./docker-registry-cache:/usr/local/cargo/registry
- ./docker-target-cache:/rgb-lib-nodejs/rgb-lib/bindings/c-ffi/target
- install dependencies: Node.js v18, Swig 4.1
- from the project root, run:
npm run build
To try the generated library, build the package then, from the project root, run:
npm install
mkdir data
npm run regtest_start # to start regtest services
node example.js
npm run regtest_stop # to stop regtest services
To format the code, install the package then, from the project root, run:
npm run format
To publish the package on the npm registry, from the project root, run:
npm run docker-build
npm publish