No description, website, or topics provided.
C++ Rust JavaScript Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
build-scripts
src
.gitignore
Cargo.toml
README.rst
binding.gyp
index.js
package.json

README.rst

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:

void, bool, c_int, c_double (JS float), *c_char (JS string), Struct (JS object), *c_int (JS numeric array)

What's inside:

  • 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

Installing

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 dependencies:

> npm install

Building

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.

Running

> node index.js

Links

Disclaimer

These examples are possibly unsafe due to my insufficient competence in subject. However they should be useful for beginners.