Rust in node examples
Experimenting with adding Rust extension into NodeJS/V8 crossplatformingly via C++ native addon with help of C ABI interface.
Entirely the same approach works for Electron framework, with a little nuance that you should put your plugin into node_modules and do electron-rebuild.cmd -w youraddonname -f
Experimented parameter and return types:
- Rust dynamic library in ./src/embed.rs (linked with mylib.cc)
- Native NodeJS C++ addon ./src/addon.cc using ./src/embed.rs library
Tested on Windows, Ubuntu and OS X
NON npm dependencies:
- node-gyp installation recommendations fulfilled properly properly for your platform
- Rust and Cargo (I did not check older version, but I think it should work with Rust 1.6+). I, personally use multirust-rs and nightly target
> npm install
Build whole addon:
> npm run build
Rebuild Rust only (keep addon.node as it is)
> npm run rebuild-rust
Please refer to package.json for more details.
> node index.js
These examples are possibly unsafe due to my insufficient competence in subject. However they should be useful for beginners.