Easy way to write Node.js module using Rust

Overview

node-bindgen

Easy way to write native Node.js module using idiomatic Rust

Features

  • Easy: Just write idiomatic Rust code, node-bindgen take care of generating Node.js FFI wrapper codes.
  • Safe: Node.js arguments are checked automatically based on Rust types.
  • Async: Support Async Rust. Async codes are translated into Node.js promises.
  • Class: Rust struct can be accessed using Node.js classes.
  • Stream: Implement Node.js stream using Rust
  • N-API: Use Node.js N-API, which means you don't have to recompile your module.

Compatibility with Node.js version

This project uses the v7 of Node N-API. Please see following compatibility matrix.

Following OS are supported:

  • Linux
  • MacOs
  • Windows

Why node-bindgen?

Writing native node-js requires lots of boilerplate code. Node-bindgen generates external "C" glue code from rust code, including native module registration. node-bindgen make it writing node-js module easy and fun.

Getting started

CLI Installation

Install nj-cli command line, which will be used to generate the native library.

cargo install nj-cli

This is one time step.

Configuring Cargo.toml

Add two dependencies to your projects' Cargo.toml.

Add node-bindgen as a regular dependency (as below):

[dependencies]
node-bindgen = { version = "4.0" }

Then add node-bindgen's procedure macro to your build-dependencies as below:

[build-dependencies]
node-bindgen = { version = "4.0", features = ["build"] }

Then update crate type to cdylib to generate node.js compatible native module:

[lib]
crate-type = ["cdylib"]

Finally, add build.rs at the top of the project with following content:

fn main() {
    node_bindgen::build::configure();
}

Example

Here is a function that adds two numbers. Note that you don't need to worry about JS conversion.

use node_bindgen::derive::node_bindgen;

/// add two integer
#[node_bindgen]
fn sum(first: i32, second: i32) -> i32 {
    first + second
}

Building native library

To build node.js library, using nj-cli to build:

nj-cli build

This will generate Node.js module in "./dist" folder.

To build a release version:

nj-cli build --release

Watching ./src for Changes

While developing your native module, you may want to watch for file changes and run a command when a change occurs, for example cargo check or cargo build.

For this, we can use nj-cli watch.

nj-cli watch installs [if it does not exist] and passes arguments to cargo watch. By default, nj-cli watch will run cargo check against your ./src files.

To see all available methods for nj-cli watch, run the following command:

nj-cli watch -- --help

Using in Node.js

Then in the Node.js, rust function can be invoked as normal node.js function:

$ node
Welcome to Node.js v14.0.0.
Type ".help" for more information.
> let addon = require('./dist');
undefined
> addon.sum(2,3)
5
>

Features

Function name or method can be renamed instead of default mapping

#[node_bindgen(name="multiply")]
fn mul(first: i32,second: i32) -> i32 {
    first * second
}

Rust function mul is re-mapped as multiply

Optional argument

Argument can be skipped if it is marked as optional

#[node_bindgen]
fn sum(first: i32, second: Option<i32>) -> i32 {
    first + second.unwrap_or(0)
}

Then sum can be invoked as sum(10) or sum(10,20)

Callback

JS callback are mapped as Rust closure.

#[node_bindgen]
fn hello<F: Fn(String)>(first: f64, second: F) {

    let msg = format!("argument is: {}", first);

    second(msg);
}

from node:

let addon = require('./dist');

addon.hello(2,function(msg){
  assert.equal(msg,"argument is: 2");
  console.log(msg);  // print out argument is 2
});

Callback are supported in Async rust as well.

Support for Async Rust

Async rust function is mapped to Node.js promise.

use std::time::Duration;
use flv_future_aio::time::sleep;
use node_bindgen::derive::node_bindgen;


#[node_bindgen]
async fn hello(arg: f64) -> f64 {
    println!("sleeping");
    sleep(Duration::from_secs(1)).await;
    println!("woke and adding 10.0");
    arg + 10.0
}
let addon = require('./dist');

addon.hello(5).then((val) => {
  console.log("future value is %s",val);
});

JavaScript class

JavaScript class is supported.

struct MyClass {
    val: f64,
}


#[node_bindgen]
impl MyClass {

    #[node_bindgen(constructor)]
    fn new(val: f64) -> Self {
        Self { val }
    }

    #[node_bindgen]
    fn plus_one(&self) -> f64 {
        self.val + 1.0
    }

    #[node_bindgen(getter)]
    fn value(&self) -> f64 {
        self.val
    }
}
let addon = require('./dist');
const assert = require('assert');

let obj = new addon.MyObject(10);
assert.equal(obj.value,10,"verify value works");
assert.equal(obj.plusOne(),11);

There are more features in the examples folder.

Windows + Electron Support

When using node-bindgen with electron on Windows, nj-build must compile a C++ file, win_delay_load_hook.cc, and therefore it is required that the development environment has a valid C/C++ compiler.

If your machine does not have a valid C/C++ compiler, install Microsoft VSCode.

In the future, this file will be re-written in Rust, removing this dependency.

Contributing

If you'd like to contribute to the project, please read our Contributing guide.

License

This project is licensed under the Apache license.

Comments
  • Async functions without return values are resolved immediately

    Async functions without return values are resolved immediately

    opened by nickbabcock 19
  • Enum support for TryIntoJs, structured errors from Result

    Enum support for TryIntoJs, structured errors from Result

    As the title says, this adds support for auto-conversion of enums into JS. Representation used is the same as the default one in Serde. I took the same choices when it comes to unit variants' representation: they are represented by strings with the value being the variant name in PascalCase. Unit structs are also supported, and represented by nulls (see examples/json for a hands on outline of different representation possibilities).

    There is one somewhat breaking change buried in here. The representation of TryIntoJs for Result<T, E> no longer demands E: ToString, but requires E: TryIntoJs. This allows the user to read structured errors in JS, no longer having to rely on just their string representation. If you see a way of achieving the same thing without introducing a breaking change, let me know in the review.

    opened by mkawalec 15
  • Derive TryIntoJs for structs

    Derive TryIntoJs for structs

    This implements https://github.com/infinyon/node-bindgen/issues/147, without the bonus points.

    I am fairly unhappy about the fact that we demand fields to be Clone. Because try_into_js takes ownership of Self, I am unsure how to run it for each of the struct's fields without cloning. Please do let me know if there is a way of making the borrow checker happy without cloning, it feels like there should be one.

    Added a TryIntoJs instance for usize by casting it to u64. I don't think we expect this code to run on architectures wider than 64 bits, so the conversion should be a safe one.

    opened by mkawalec 15
  • Crashing on MacOS and electron.

    Crashing on MacOS and electron.

    It seems like no matter what I do I can't seem to stop MacOS from crashing on electron. I'm simply trying to make something similar to iohook, but whenever an electron app is using the module, and it exits, after about 2 minutes it spits out a crash report. message.txt. This is my code,

    use std::sync::RwLock;
    
    use device_query::{DeviceQuery, DeviceState};
    use lazy_static::lazy_static;
    use node_bindgen::derive::node_bindgen;
    use rayon::iter::{IntoParallelIterator, ParallelIterator};
    
    lazy_static! {
        static ref SHOULDSTOP: RwLock<bool> = RwLock::new(false);
    }
    
    #[node_bindgen]
    async fn raw<F: Fn(Vec<String>)>(returnjs: F) -> bool {
        let device_state = DeviceState::new();
        let mut prev_keys = vec![];
        loop {
            let keys = device_state.get_keys();
            if *SHOULDSTOP.read().unwrap() {
                return true;
            } else if keys != prev_keys {
                let returnkeys: Vec<String> = keys
                    .clone()
                    .into_par_iter()
                    .map(|x| format!("{}", x))
                    .collect();
                returnjs(returnkeys);
            }
            prev_keys = keys;
        }
    }
    
    #[node_bindgen]
    fn unload() {
        *SHOULDSTOP.write().unwrap() = true;
    }
    

    I'm out of ideas. please help

    electron triage 
    opened by StratusFearMe21 15
  • Implement JsValue to str.

    Implement JsValue to str.

    Happy New Year!

    This may be a terrible idea to begin with, but if someone can help me figure out why it doesn't work, that would be awesome!

    https://doc.rust-lang.org/std/ffi/struct.CStr.html#implementations

    It's returning some bytes in the neighborhood of the right memory location! :)

    I suspect the correct solution, assuming there is one, is a much simplified version likely using different NAPI APIs that I'm not familiar with.

    opened by mattcollier 11
  • [Merged by Bors] - Automatically serialize uuids

    [Merged by Bors] - Automatically serialize uuids

    Behind an optional feature flag. Curiously enough it looks like I've found a cargo bug where having a feature named exactly the same as an optional crate, fails to pull in the optional crate. Fixed through a roundabout feature name on core.

    opened by mkawalec 10
  • electron + windows issue; aka `win_delay_load_hook` issue

    electron + windows issue; aka `win_delay_load_hook` issue

    Issue

    It will be happen if we want to use electron with node-bindgen on Windows:

    error: linking with `link.exe` failed: exit code: 1181
      |
    (...abbr...)
      = note: LINK : fatal error LNK1181: cannot open input file 'win_delay_load_hook.obj'
    

    Reference

    • https://www.electronjs.org/docs/tutorial/using-native-node-modules
      • https://www.electronjs.org/docs/tutorial/using-native-node-modules#a-note-about-win_delay_load_hook

    Coping method in neon

    • https://github.com/neon-bindings/neon/pull/435

    Note

    Using dherman/electron-build-env makes it easy to prepare a workspace for repro.

    1. In the ./native directory, prepare a cdylib project use node-bindgen.
    2. In the ./ directory, prepare a package.json with electron-build-env and nj-cli in the devDependencies. And prepare "electron-build-env nj-cli build" in scripts such as experiment0.
    3. Run yarn experiment0.
    electron 
    opened by usagi 9
  • Make it possible to regenerate bindgen work

    Make it possible to regenerate bindgen work

    Currently this is hardcoded as https://github.com/infinyon/node-bindgen/blob/master/nj-sys/src/binding.rs with no docs/build.rs to redo it. It either needs some instructions on how to regenerate it, or ideally it gets rebuilt at build time.

    opened by palfrey 9
  • Request: Windows support

    Request: Windows support

    This project is really excellent✨ But, in now, it would not work in Windows environment. I'm looking forward to support Windows.

    For now, I got these errors using nj-cli build in Windows:

    PS C:\Users\usagi\tmp\node-bindgen\examples\function> nj-cli build
       Compiling flv-future-aio v1.0.0
    error[E0433]: failed to resolve: could not find `unix` in `os`
     --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:3:14
      |
    3 | use std::os::unix::io::RawFd;
      |              ^^^^ could not find `unix` in `os`
    
    error[E0433]: failed to resolve: could not find `sys` in `nix`
     --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\zero_copy.rs:7:10
      |
    7 | use nix::sys::sendfile::sendfile;
      |          ^^^ could not find `sys` in `nix`
    
    error[E0432]: unresolved import `nix::Error`
     --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\zero_copy.rs:8:5
      |
    8 | use nix::Error as NixError;
      |     ^^^^^^^^^^^^^^^^^^^^^^ no `Error` in the root
    
    error[E0412]: cannot find type `RawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:11:9
       |
    11 |     fd: RawFd,
       |         ^^^^^ not found in this scope
    
    error[E0412]: cannot find type `RawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:18:20
       |
    18 |     pub fn new(fd: RawFd,position: u64,len: u64) -> Self {
       |                    ^^^^^ not found in this scope
    
    error[E0412]: cannot find type `RawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:34:25
       |
    34 |     pub fn fd(&self) -> RawFd {
       |                         ^^^^^ not found in this scope
    
    error[E0405]: cannot find trait `AsRawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:42:6
       |
    42 | impl AsRawFd for AsyncFileSlice {
       |      ^^^^^^^ not found in this scope
    
    error[E0412]: cannot find type `RawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\fs\file_slice.rs:44:28
       |
    44 |     fn as_raw_fd(&self) -> RawFd {
       |                            ^^^^^ not found in this scope
    
    error[E0405]: cannot find trait `AsRawFd` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\zero_copy.rs:46:26
       |
    46 | pub trait ZeroCopyWrite: AsRawFd {
       |                          ^^^^^^^ not found in this scope
    
    error[E0425]: cannot find value `ft` in this scope
      --> C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\flv-future-aio-1.0.0\src\zero_copy.rs:93:9
       |
    93 |         ft.await
       |         ^^ not found in this scope
    
    error: aborting due to 10 previous errors
    
    Some errors have detailed explanations: E0405, E0412, E0425, E0432, E0433.
    For more information about an error, try `rustc --explain E0405`.
    error: could not compile `flv-future-aio`.
    
    To learn more, run the command again with --verbose.
    thread 'main' panicked at 'copy failed: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', C:\Users\usagi\.cargo\registry\src\github.com-1ecc6299db9ec823\nj-cli-0.1.2\src\main.rs:69:13
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    Please let me know if you know a workaround. I'm not hurry but I really expecting to success of the project. 👍

    Installation platform/windows 
    opened by usagi 9
  • [Merged by Bors] - Remove global initialization of logger

    [Merged by Bors] - Remove global initialization of logger

    • fixes #134
    • Provide macro to run code on initialization without introducing additional direct dependencies to client projects.
    • without this global initialization applications need to setup their own logging infrastructure at startup
    • Adapted function example with the use of a custom logger
    opened by marcmo 8
  • Allow to configure a custom logging backend

    Allow to configure a custom logging backend

    It's currently not possible to configure a custom logging backend. What is needed is a way to use a custom logger along with some guidance of where to initialize it (since we do not have a main where this is done for applications.

    enhancement nj-derive 
    opened by marcmo 8
  • Bump electron from 11.5.0 to 18.3.7 in /examples/electron

    Bump electron from 11.5.0 to 18.3.7 in /examples/electron

    Bumps electron from 11.5.0 to 18.3.7.

    Release notes

    Sourced from electron's releases.

    electron v18.3.7

    Release Notes for v18.3.7

    Fixes

    • Fixed WCO not responding to touch events on windows. #35177 (Also in 19, 20)
    • Fixed webContents.getUserAgent() incorrectly returning an empty string unless previously set. #35130 (Also in 17, 19, 20)
    • Fixed an issue in which calling setBounds() after e.preventDefault in a 'will-move' or 'will-resize' event wouldn't change the window's shape until the mouse button was released. #35082 (Also in 19, 20)
    • Fixed context menu not showing all items on macOS when dock is not hidden. #35198 (Also in 19)
    • None. #35171 (Also in 19, 20)

    Other Changes

    • Fixed page size always being restricted to 4k on Linux arm64. #35184
    • Security: backported fix for CVE-2022-2478. #35099
    • Security: backported fix for chromium:1334864. #35097

    electron v18.3.6

    Release Notes for v18.3.6

    Fixes

    • Fixed a crash when calling BrowserWindow.setEnabled(). #34973 (Also in 19, 20)
    • Fixed a potential crash when changing window settings after initializing WCO with an invalid titleBarStyle. #34873 (Also in 17, 19, 20)
    • Fixed alwaysOnTop BrowserWindow option for X11 Linux. #34911 (Also in 19, 20)
    • Fixed an issue where BrowserWindows on macOS were incorrectly marked as resizable. #34907 (Also in 19, 20)
    • Fixed an issue where Windows Control Overlay buttons did not respect maximizable/minimizable/closable states of a BrowserWindow. #34720 (Also in 17, 19, 20)
    • Fixed an issue where calling BrowserWindow.setRepresentedFilename on macOS with titlebarStyle: 'hiddenInset' or titlebarStyle: 'hidden' inadvertently moves the traffic light location. #34847 (Also in 19, 20)
    • Fixed an issue where some BrowserWindows opened from new links wouldn't properly load URLs. #34910 (Also in 19)
    • Fixed an issue where the minimize button with WCO enabled would incorrectly be highlighted in some cases. #34838 (Also in 17, 19, 20)
    • Fixed an issue with background colors being improperly applied to BrowserViews on Windows. #33478 (Also in 16)
    • Fixed empty app_id when running under wayland. #34877 (Also in 19, 20)
    • Fixed missing Sec-CH-UA headers and empty navigator.userAgentData. #34758 (Also in 17, 19, 20)
    • Fixed symbol generation on 32-bit Windows release builds. #35096 (Also in 19, 20)
    • Prevent brief display of "Ozone X11" in window title on Linux. #34943

    Other Changes

    • Backported fix for CVE-2022-2294. #34882
    • Security: backported fix for 1287804. #35102
    • Security: backported fix for 1333333. #34689
    • Security: backported fix for 1335054. #34687
    • Security: backported fix for 1335458. #34685
    • Security: backported fix for 1336014. #35004
    • Security: backported fix for 1339844. #35002
    • Security: backported fix for 1340335. #35000
    • Security: backported fix for 1340654. #34998
    • Security: backported fix for CVE-2022-2162. #34714
    • Security: backported fix for CVE-2022-2295. #34881

    electron v18.3.5

    Release Notes for v18.3.5

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies javascript 
    opened by dependabot[bot] 0
  • fix CI for windows

    fix CI for windows

    Regression introduced in: https://github.com/infinyon/node-bindgen/pull/197.

    https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true.

    error: failed to run custom build command for `nj-example-function v0.0.0 (D:\a\node-bindgen\node-bindgen\examples\function)`
    [587](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:588)
    [588](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:589)
    Caused by:
    [589](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:590)
      process didn't exit successfully: `D:\a\node-bindgen\node-bindgen\examples\target\debug\build\nj-example-function-4b753c1df0bfd246\build-script-build` (exit code: 101)
    [590](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:591)
      --- stdout
    [591](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:592)
      downloading nodejs: https://nodejs.org/dist/v16.15.1
    [592](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:593)
      /win-x64/node.lib to: "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\node-v16.15.1.lib"
    [593](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:594)
    [594](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:595)
      --- stderr
    [595](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:596)
      thread 'main' panicked at 'Download node.lib file failed: Parse(StatusErr)', D:\a\node-bindgen\node-bindgen\nj-build\src\lib.rs:35:14
    [596](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:597)
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    [597](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:598)
    warning: build failed, waiting for other jobs to finish...
    [598](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:599)
    mingw32-make[2]: *** [makefile:4: build] Error 101
    [599](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:600)
    mingw32-make[2]: Leaving directory 'D:/a/node-bindgen/node-bindgen/examples/function'
    [600](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:601)
    mingw32-make[1]: *** [makefile:25: test-function] Error 2
    [601](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:602)
    mingw32-make[1]: Leaving directory 'D:/a/node-bindgen/node-bindgen/examples'
    [602](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:603)
    mingw32-make: *** [makefile:18: test-examples] Error 2
    [603](https://github.com/infinyon/node-bindgen/runs/7245525951?check_suite_focus=true#step:8:604)
    Error: Process completed with exit code 1.
    
    platform/windows CI regression 
    opened by sehz 0
  • Expecting compiler error when using &str as parameter

    Expecting compiler error when using &str as parameter

    Hi,

    we recently started using node-bindgen in our project https://github.com/esrlabs/chipmunk and noticed the following:

    Using a parameter with the type &str results in the compiler not complaining and building completely fine. As soon as the function is called on the Javascript side, a huge error log is being printed from which it is hard to tell what the actual issue is.

    The following code shows a minimal example of the issue:

    // lib.rs
    use node_bindgen::derive::node_bindgen;
    
    #[node_bindgen]
    fn hi(name: &str) {
        println!("Hello {}", name);
    }
    
    // main.js
    let addon = require("../dist");
    addon.hi("Hello");
    

    Running the main.js file results in the following error log:

    $ node main.js 
     [4556]: c:\ws\src\node_buffer.cc:246: Assertion `val->IsArrayBufferView()' failed.
     1: 00007FF69DDB013F v8::internal::CodeObjectRegistry::~CodeObjectRegistry+112495
     2: 00007FF69DD3F396 DSA_meth_get_flags+65526
     3: 00007FF69DD3F751 DSA_meth_get_flags+66481
     4: 00007FF69DD60F28 node::Buffer::Data+168
     5: 00007FF69DD7004F napi_get_buffer_info+79
     6: 00007FF905A53119 nj_core::convert::impl$17::convert_to_rust+137 [C:\Users\Pepe\.cargo\registry\src\github.com-1ecc6299db9ec823\nj-core-4.3.0\src\convert.rs]:L239
     7: 00007FF905A510B7 nj_core::basic::impl$12::convert_arg_at<str>+183 [C:\Users\Pepe\.cargo\registry\src\github.com-1ecc6299db9ec823\nj-core-4.3.0\src\basic.rs]:L816
     8: 00007FF905A512BA nj_core::basic::JsCallback::get_value_at<str>+186 [C:\Users\Pepe\.cargo\registry\src\github.com-1ecc6299db9ec823\nj-core-4.3.0\src\basic.rs]:L688
     9: 00007FF905A5187A something::napi_hi::closure$0+202 [C:\Users\Pepe\Desktop\Something\src\lib.rs]:L3
    10: 00007FF905A513FC something::napi_hi+76 [C:\Users\Pepe\Desktop\Something\src\lib.rs]:L3
    11: 00007FF69DD7E7C7 node::Stop+36391
    12: 00007FF69E62C3B6 v8::internal::Builtins::code_handle+172694
    13: 00007FF69E62BFA9 v8::internal::Builtins::code_handle+171657
    14: 00007FF69E62C26C v8::internal::Builtins::code_handle+172364
    15: 00007FF69E62C0D0 v8::internal::Builtins::code_handle+171952
    16: 00007FF69E6FF4E1 v8::internal::SetupIsolateDelegate::SetupHeap+494673
    17: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    18: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    19: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    20: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    21: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    22: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    23: 00007FF69E69198E v8::internal::SetupIsolateDelegate::SetupHeap+45310
    24: 00007FF69E68FB9C v8::internal::SetupIsolateDelegate::SetupHeap+37644
    25: 00007FF69E68F79B v8::internal::SetupIsolateDelegate::SetupHeap+36619
    26: 00007FF69E570471 v8::internal::Execution::CallWasm+1521
    27: 00007FF69E56FD5F v8::internal::Execution::Call+191
    28: 00007FF69E652DFC v8::Function::Call+508
    29: 00007FF69DD7166E node_api_get_module_file_name+3038
    30: 00007FF69DD752B7 node::Start+983
    31: 00007FF69DD75668 node::Start+1928
    32: 00007FF69DDDC099 node::LoadEnvironment+89
    33: 00007FF69DCF7AB3 cppgc::internal::NormalPageSpace::linear_allocation_buffer+53811
    34: 00007FF69DD74FBD node::Start+221
    35: 00007FF69DB988CC RC4_options+348108
    36: 00007FF69EBF08F8 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+14472
    37: 00007FF950517034 BaseThreadInitThunk+20
    38: 00007FF952502651 RtlUserThreadStart+33
    

    It took me many hours to figure out where the problem was. I guess it would make sense to point to this error during the build to avoid other users getting stuck on this kind of error.

    opened by fur-gan 0
  • JS namespaces (modules)

    JS namespaces (modules)

    Hello, Is it possible to define somehow module/namespace on JS level? Let's say I have:

    mod features {
        #[node_bindgen]
        pub fn feature_a() -> Result<...> { .... }
    }
    
    mod tools {
        #[node_bindgen]
        pub fn tool_a() -> Result<...> { .... }
    }
    

    On js level I would like to see it as:

    let rustcore = require('rustcore.node');
    rustcore.features.feature_a();
    rustcore.tools.tool_a();
    

    Sorry if question is trivial, but didn't find any kind of solution for that.

    opened by DmitryAstafyev 1
  • Bump minimist from 1.2.5 to 1.2.6 in /examples/electron

    Bump minimist from 1.2.5 to 1.2.6 in /examples/electron

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
InfinyOn
InfinyOn
Python module implemented in Rust for counting the number of one bits in a numpy array.

bit-counter Package for counting the number of one bits in a numpy array of uint8 values. Implemented as a Python module using Rust, providing high pe

Andrew MacDonald 3 Jul 9, 2022
Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts

gm_cpreprocessor Another cursed Garry's Mod module. This time, it adds the C preprocessor to Lua scripts. It works by detouring RunStringEx and overri

William 6 Aug 14, 2022
Mod_wasm - an extension module for the Apache HTTP Server (httpd) that enables the usage of WebAssembly (Wasm).

mod_wasm is an extension module for the Apache HTTP Server (httpd) that enables the usage of WebAssembly (Wasm). This module will allow to execute certain tasks in the backend in a very efficient and secure way.

VMware  Labs 67 Dec 21, 2022
WASM bindings for React - enables you to write and use React components in Rust

This library enables you to write and use React components in Rust, which then can be exported to JS to be reused or rendered.

Yichuan Shen 55 Dec 24, 2022
Rust bindings for writing safe and fast native Node.js modules.

Rust bindings for writing safe and fast native Node.js modules. Getting started Once you have the platform dependencies installed, getting started is

The Neon Project 7k Jan 4, 2023
Benchmark over Node.js binding frameworks in Rust

Benchmark over Node.js binding frameworks in Rust

LongYinan 7 Dec 28, 2022
Rust Blake hash bindings for Node.js.

@napi-rs/blake-hash Node.js binding for https://github.com/BLAKE3-team/BLAKE3. High performance, and no postinstall scripts. Support matrix node12 nod

LongYinan 35 Aug 12, 2022
🚀 Fast and simple Node.js version manager, built in Rust

Fast Node Manager (fnm) ?? Fast and simple Node.js version manager, built in Rust Features ?? Cross-platform support (macOS, Windows, Linux) ✨ Single

Gal Schlezinger 9.8k Jan 2, 2023
lzma-rs binding to Node.js via napi-rs.

@napi-rs/lzma lzma-rs binding to Node.js via napi-rs. ?? Help me to become a full-time open-source developer by sponsoring me on Github Install yarn a

LongYinan 8 Aug 16, 2022
Native webview bindings for Node.js

webview-native Native webview bindings for Node.js Installing webview-native Installing webview-native requires a supported version of Node and Rust.

SnowflakeDev Community ❄️ 7 Nov 16, 2022
Node.js bindings to the ripgrep library, for fast file searching in JavaScript without child processes!

ripgrepjs ripgrepjs: Node.js bindings to the ripgrep library, for direct integration with JS programs without spawning an extra subprocess! This proje

Annika 1 May 10, 2022
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.

Lz4 Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex. Install this package yarn add lz4-napi API export function compress:

Antonio Musolino 34 Nov 22, 2022
Node.js bindings to Lua

Node.js bindings to Lua

Connor Brewster 6 Dec 19, 2022
Libsodium for Node.js

Libsodium for Node.js

Tomio 7 Oct 30, 2022
A simple library to allow for easy use of python from rust.

Rustpy A simple library to allow for easy use of python from rust. Status Currently this library has not received much love (pull requests welcome for

Luke 74 Jun 20, 2022
ruby-build is a command-line utility that makes it easy to install virtually any version of Ruby, from source.

ruby-build ruby-build is a command-line utility that makes it easy to install virtually any version of Ruby, from source. It is available as a plugin

null 3.7k Jan 5, 2023
Squirt is a easy-to-use programming language.

Squirt is a easy-to-use programming language.

QuqqU 5 Nov 30, 2022
Rust-ffi-guide - A guide for doing FFI using Rust

Using unsafe for Fun and Profit A guide to traversing the FFI boundary between Rust and other languages. A rendered version is available here. This gu

Michael Bryan 261 Dec 1, 2022
Safe Rust <---> GraalVM Polyglot bindings using procedural macros

The class macro is the primary way to generate bindings to Java types; it will generate a struct (with generics if specified) that implements Pass and Receive and has all the methods you give stubs for. The methods generated can be used like normal rust methods, however mutability is not enforced. The fully-qualified type name should precede a block containing method and constructor stubs. Java primitives like char, int, and byte are aliased to corresponding Rust types.

Alec Petridis 33 Dec 28, 2022