Code Monkey home page Code Monkey logo

node-bindgen's People

Contributors

ajhunyady avatar asv7c2 avatar danielhenrymantilla avatar dependabot[bot] avatar digikata avatar dmitryastafyev avatar federico-terzi avatar garyhai avatar jacks0n9 avatar marcmo avatar mattcollier avatar mkawalec avatar morenol avatar nicholastmosher avatar nickbabcock avatar ozgrakkurt avatar palfrey avatar ryanmtate avatar sehz avatar simlay avatar usagi avatar vijaylaxmid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-bindgen's Issues

problem with running api v6 on windows

steps to reproduce:

  • check out branch support_v14 on windows platform
  • cd examples\function
  • make test

this generates:

Finished dev [unoptimized + debuginfo] target(s) in 13.20s
node test.js
make: *** [Makefile:7: test] Error -1073741819

#[node_bindgen] is broken?

Hello,
I have tried to use this library with this test code:

use node_bindgen::derive::node_bindgen;

pub struct MyStruct
{
    pub x: i64,
    pub y: i64,
}

#[node_bindgen]
impl MyStruct
{
    #[node_bindgen(constructor)]
    fn new(x: i64, y: i64) -> Self
    {
        MyStruct
        {
            x: x,
            y: y
        }
    }
    #[node_bindgen]
    fn hello(&self)
    {
        println!("MyStruct hello !");
    }
}

It works with version 1.3.0, but not with version 2.1.1.
On this latest version, I got this error:

  --> src/lib.rs:15:1
   |
15 | #[node_bindgen]
   | ^^^^^^^^^^^^^^^- help: missing `,`
   | |
   | expected one of 8 possible tokens
   |
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

In my case, the error concern the attribute used on the top of "impl MyStruct".
I have followed the examples, I don't know why it doesn't work.
Without this macro, it compiles but MyStruct is not available from nodejs.
Rust version: rustc 1.45.0-nightly (a74d1862d 2020-05-14) (on Linux 86_64)

Thank you !
Valentin CRÔNE

Electron import [module].node is not a valid Win32 application.

Hi,

Is there some idiot proof checklist to get modules built with node-bindgen to work with Electron? I have been trying for the past day to get this to work without success.
I get this error when trying to import it:
Error: node-loader:
Error: E:\dev\electron\serverman.webpack\main/b911d8f8ccebb112db602d3caf3830fd.node is not a valid Win32 application.

However, the module does work from the node command line.

On windows with msvc toolchain and stable rust (1.47.0)
nj-cli v1.0.4
electron-build-env 0.2.0
Electron is v 10.1.3
node-loader v1.0.2

Many thanks

Threads

New to rust, I am trying to have my callback function be passed into my thread, this call back function will be called multiple times. However, it seems I can't have my cb shared between threads. ``F cannot be shared between threads safely

Async/promise is not working on Windows.

Hi,
After updating to the new version, the compilation process was flawless also on Windows.
That said, async/promise examples fail (whereas the others work correctly).

Steps to reproduce

  1. Navigate to the examples/promise folder
  2. Run nj-cli build
  3. Execute node test.js

The following error is reported:

addon.hello(5).then((val) => {
      ^

TypeError: napi call failed InvalidArg
    at Object.<anonymous> (C:\Users\Freddy\Documents\WiseTime\node-bindgen\examples\promise\test.js:5:7)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

Thank you for your work, let me know if you need help to test something on Windows

Feature Request: Generate d.ts definitions

It would be great to also generate .d.ts type definitions so that we'd get TypeScript compile time checking against the native library too.

Thank you for this library, it's great!

add "init" command to nj-cli

The ```init`` command will create a skeleton project to populate a cargo project with

  • Cargo.toml with appropriate dependencies
  • Add build.rs

This should be similar to cargo init commands.

This should make it easier to start with node-bindgen.

Rust replacement for N-API

N-API is ok for now. However, there are some limitations with N-API.

  • It can't create new class with existing Rust struct
  • Doesn't work with Deno
  • No interface to raw binding V8

It maybe we can create new abstraction that will make easier to integrate Rust and Node.js (Deno)

Build CI pipeline

First decided on GitHub Action or Travis.

Ability to build and test for following configuration:

  • OS: Mac, Windows, Linux
  • Node: Current version and LTS

Other considerations:

  • Flexible
  • Easier to extend
  • Performant

support for typed array buffer

Support Buffer typed objects. This allow passing arbitrary Rust boxed object to Node.js. The buffer is managed by Node.js. When buffer is garbage collected, node-bindgen need to deallocate from heap memory. This approach is same as handling data for threaded function.

re-enable electron test

electron test were disable due to Node security issue.
Update npm libraries and re-enable electron test

Use custom AST for procedure macro

Currently, procedure macro use AST from Syn crate directly. However, this make it hard to encode custom state which make it harder to maintain.

Instead, use bindgen specific AST which has following benefits:

  • can pass back compiler error
  • code can be lots of simpler

Return "Failed to connect to server" instead of the 'panic' below.

14:44:27.027 ERROR nj_core::basic > error executing napi call PendingException
thread '' panicked at 'napi call failed: napi call failed PendingException', <::std::macros::panic macros>:5:6
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

Need the ability to pass arbitrary JSON

I need the ability to pass arbitrary number of parameters to an API:

var leader =

Option 1:
leader.consume( {offset: true, maxBytes: 1024} );

Option 2:
leader.consume( {offset: true} );

Option 3:
leader.consume( );

`nj-cli build` failed in a link-time with node-bindgen-2.1.1 and the latest toolchains

Abstract

Repro.

  1. $ cargo install nj-cli
  2. $ cargo new --lib e1; $ cd e1
  3. Edit: Cargo.toml
    • Append: In [lib], crate-type = ["cdylib"]
    • Append: In [dependencies], node-bindgen = "2.1.1"
    • Append: In [build-dependencies], node-bindgen = {version = "2.1.1", features = ["build"]}
  4. Edit: src/lib.rs
use node_bindgen::derive::node_bindgen;
/// add two integer
#[node_bindgen]
fn sum(first: i32, second: i32) -> i32 {
 first + second
}
  1. $ nj-cli build ( to be failed on Windows )

Additional infromations

  • Windows 10 Version 2004 (OS Build 19041.330)
  • powershell 7.1.0-preview.5
  • rust:
    • toolchain stable-x86_64-pc-windows-msvc, nightly-x86_64-pc-windows-msvc
    • rustc 1.44.1 (c7087fe00 2020-06-17), 1.46.0-nightly (0c03aee8b 2020-07-05)
  • node-bindgen:
    • [dependencies]/[build-dependencies] 2.1.1
    • nj-cli fluvio 0.2.0
  • Note: The same project be works fine on Arch Linux environment (rust-toolchain=stable/nightly-x86-64-unknown-linux-gnu).

Replace nj-cli build with build.rs script?

I noticed that all nj-cli currently does is call cargo build and then copy and rename the output library. As far as I can work out, it also currently only copies the debug output.

Currently I cannot use nj-cli to build --release or for any other arch/platform/toolchain because it calls cargo build for me.

Would it be better if the copy/rename output was as a function that users called from their build.rs? That way users could call cargo build --release --whatever-else and it would work the same as `nj-cli.

Way to call a napi function not implemented in core crate

I want to call a napi cleanup routine method napi_add_env_cleanup_hook(). This method gives a hook to perform any cleanup before a page is refreshed or is being navigated away. It is available in the bindings.rs but not implemented yet in the core crate. Is there a way to use the napi_call_result! macro directly to call this method from my lib ? Or do you plan to implement all the methods eventually ?

Thanks a lot 😊

Cannot give same name to getter and setter

    /// JS Setter
    /// Js:  obj.flag = 10;
    #[node_bindgen(setter, name = "flag")]
    fn set_flag(&mut self, val: bool) {
        self.flag = val;
    }

    /// JS getter
    /// Js:  let y = obj.flag;
    #[node_bindgen(getter, name = "flag")]
    fn get_flag(&self) -> bool {
        self.flag
    }

Same name failed to assign both setter and getter. It change getter name to "flag1", it works fine.

Can I await javascript promise from rust?

Hi. I'm the author of swc and I'm considering switching from neon to node-bindgen.

Can I store js function on struct and call it from other threads?
Neon supports it via EventHandler.

Also, I need to wait for js promises to be resolved from rust code. Is it possible?

If these features are on the roadmap, please let me know.

Need support for bool

async fn consume<F: Fn(String, String)>(&self, cb: F, from_beginning: bool) {
...
}

cannot find type bool in this scope
not found in this scoperustc(E0412)

Support non-macos UNIX like environments such as Linux

I tried in Arch Linux(WSL2), then I got the error at the link time:

DESKTOP-23J4GUA /mnt/c/Users/usagi/tmp/node-bindgen/examples/function
nj-cli build                                                                                                                  [master]    Compiling nj-example-function v0.0.1 (/mnt/c/Users/usagi/tmp/node-bindgen/examples/function)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.1plu1aizwm7h41xf.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.1progr7jjycth69a.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.2foz6gpnzq6x4dgw.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.2uy1y1dbmyx7lyr2.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.35crmuiytjj33dn3.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.38eifmv1o8w0n8um.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.4jkq1kwx9h81b77e.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.53zezas2ikrokfrd.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.571mbz0hd53i0as1.rcgu.o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.5bhj80ysgmm1b488.rcgu.o" "-o" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnj_example_function.so" "-Wl,--version-script=/tmp/rustcl8ZxKO/list" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/nj_example_function.4picu4ypvee4siyu.rcgu.o" "-Wl,--gc-sections" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps" "-L" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnode_bindgen-c88558a0f0a08fc3.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnj_build-657032ddd08c061e.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnj_core-3b8228b8c25d7cf4.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libinventory-b30a2ed465ba5d74.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libflv_future_aio-aa63baf408fba40b.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libflv_util-82cd489eb24b91ca.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libenv_logger-ad84da57d9d843e0.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libregex-d66ff5705b01c7c0.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libthread_local-ec2df0dc2322d6e3.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libregex_syntax-9a7e2faf19be8aa0.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libaho_corasick-a577d11fc968730b.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libatty-6e1e1fea8a5d62f0.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libhumantime-83717637f6273b66.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libquick_error-176100eb91c5b0e2.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libtermcolor-d62dab0e400ac85d.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libchrono-2ea1d15a9a9a5ab1.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnum_integer-db574b95dd8a90eb.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnum_traits-6cd29aa10d830df5.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libtime-3968cc3664126749.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libbytes-64754c1b943feae6.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnix-c955b9c1361cddcd.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libvoid-e89a742128a696d6.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libbitflags-4418706d8e04366e.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libmemmap-5cc4582832462ee9.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libasync_std-21777964fb7f40d2.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnum_cpus-f719cc56c25ed06c.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libasync_task-c22ec9b927b5f9fe.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libcrossbeam_channel-20eeba254032bfc1.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libcrossbeam_deque-8c396613886d2c04.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libcrossbeam_epoch-25fe52462694da67.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libmemoffset-d44ad16de69394ca.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libkv_log_macro-1c5d0ac570cc0478.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libbroadcaster-6cdc4c03890989d7.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libparking_lot-cecc9b1a12d68a20.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libparking_lot_core-3ee8803fc4df87b8.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libsmallvec-a84ae020f9f5632a.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/liblock_api-ea983c64296fd5d8.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libscopeguard-eb8dd0cdbbdfdb1d.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libmio_uds-cf7ac51c18457b74.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libmio-46c647e5f36d654e.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnet2-f6c81bb635fd4684.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libiovec-14c5c061ee204105.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libonce_cell-a864a6be48da38f8.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_timer-210cc0552ba176b7.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libcrossbeam_utils-c2fa904cb1d95d66.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/liblazy_static-e05d0e890267c067.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libpin_project_lite-f7334d5a66f70ac6.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures-9eedf06cce414810.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_executor-9481ce095806e3d6.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_util-2054521cc1b9c334.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libmemchr-a02502857378b0e2.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libproc_macro_nested-e723c5a5d02290ea.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_io-f79abe82dc32c480.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libslab-e7f4a65a3ffe299d.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_channel-37ac46b8a0bc9203.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_sink-39fc63e02d3775b8.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_task-e210e5a326854333.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libpin_utils-18ed1bd964321ab3.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libfutures_core-626686bcaf2b87f1.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libnj_sys-44e43dddabda4120.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/liblog-4599c5707a85552e.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/libcfg_if-0e1e8f4027183cb7.rlib" "/mnt/c/Users/usagi/tmp/node-bindgen/examples/target/debug/deps/liblibc-5be3e73aea9f39a6.rlib" "-Wl,--start-group" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-c32b051c3aafd36c.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-eabf8b29c0a244dd.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-5c336cc1b5ec2048.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-c7631f762b1ba6d9.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-db0f6c539591c951.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-32c2dc6fbc292c9c.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-84e9c510dc249620.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-13bc027534de0b4c.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-b3c13ecda1794c6c.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-72dc11de859645e9.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-a78b04f112feb31a.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-29469f6c53ac35f8.rlib" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-0eb3c513c640c4a6.rlib" "-Wl,--end-group" "/home/usagi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-0b278345638bce90.rlib" "-Wl,-Bdynamic" "-lutil" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil" "-shared" "-undefined" "dynamic_lookup"
  = note: cc: error: dynamic_lookup: No such file or directory


error: aborting due to previous error

error: could not compile `nj-example-function`.

To learn more, run the command again with --verbose.
thread 'main' panicked at 'copy failed: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/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

I think, it's a simple macos specific reason. I'll fix it and PR soon, maybe.

callback: handle more cases

this fails to compile. Currently this is commented out in the examples/cb

#[node_bindgen] 
fn sum<F: Fn(i32) -> String>(cb: F,second: i32) -> String {        
     let message = cb(second*2);
     format!("my message: {}",message)
 }

Support for Buffer / Uint8Array Arguments

Poking at node-bindgen, it appears that there is no way to write a function that accepts a nodejs buffer or Uint8Array.

Use case, hash some bytes either via:

#[node_bindgen]
fn hash(data: Vec<u8>) {}

or

#[node_bindgen]
fn hash(data: &[u8]) {}

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. 👍

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

Coping method in neon

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.

Tracking Issue: complete N-API

Following N-API wrapper need to be created for JsEnv.
For each of the API, example/test code must be added to verify it works in the node environment.

  • napi_create_arraybuffer
  • napi_create_buffer
  • napi_create_buffer_copy
  • napi_create_date
  • napi_create_external
  • napi_create_external_arraybuffer
  • napi_create_external_buffer
  • napi_create_symbol
  • napi_create_typedarray
  • napi_create_dataview
  • napi_create_uint32
  • napi_create_bigint_int64
  • napi_create_bigint_uint64
  • napi_create_bigint_words
  • napi_create_string_latin1
  • napi_get_array_length
  • napi_get_arraybuffer_info
  • napi_get_buffer_info
  • napi_get_prototype
  • napi_get_typedarray_info
  • napi_get_dataview_info
  • napi_get_value_bool
  • napi_get_value_double
  • napi_get_value_bigint_int64
  • napi_get_value_bigint_uint64
  • napi_get_value_bigint_words
  • napi_get_value_external
  • napi_get_value_int32
  • napi_get_value_int64
  • napi_get_value_string_utf8
  • napi_get_value_uint32
  • napi_get_null
  • napi_coerce_to_bool
  • napi_coerce_to_number
  • napi_coerce_to_string
  • napi_instanceof
  • napi_is_dataview
  • napi_strict_equals
  • napi_detach_arraybuffer
  • napi_is_detached_arraybuffer
  • napi_get_property_names
  • napi_get_all_property_names
  • napi_delete_property
  • napi_set_named_property
  • napi_get_named_property
  • napi_has_named_property
  • napi_has_element
  • napi_delete_element
  • napi_create_function
  • napi_get_version
  • napi_get_uv_event_loop

return value is integer other than bool

use node_bindgen::derive::node_bindgen;

#[node_bindgen]
pub fn foo() -> bool {
    true
}
const addon = require('./dist')
console.log(addon.foo()) // will log 1 other than true

malloc error on shutdown

When running the class-simple example from the current repo all the tests pass but then the script crashes at the end (presumably when the bound object is deallocated):

$ make test
nj-cli build
   Compiling nj-example-class-simple v0.1.0 (/.../node-bindgen/examples/class-simple)
    Finished dev [unoptimized + debuginfo] target(s) in 0.89s
node test.js
class simple test succeed
node(33705,0x10c5295c0) malloc: *** error for object 0x104400160: pointer being freed was not allocated
node(33705,0x10c5295c0) malloc: *** set a breakpoint in malloc_error_break to debug
make: *** [test] Abort trap: 6
version
macOS 10.14.6
node 14.5.0
rustc 1.45.0

Threadsafe_callback example

Hi, I was trying to get the threadsafe_callback N API function to work, but I can't really figure out what I'm missing.

#[node_bindgen]
fn start_pipe<F: Fn(String)>(url: String, callback: F) {
    ThreadSafeFunction::create(??)
}

I'm not sure how to pass the callback function to the threadsafe function, but this probably needs to be done on a lower level with the JsEnv.create_threadsafe_function, but also there I'm missing some insight in how to actually pass the callback around.

Thanks in advance

build::configure() should not put node-vX.Y.Z.lib in %LocalAppData%\Temp

  • First of all this has the potential to break CI builds in surprising ways (if temp dir is cleaned before each build)
  • It leads to the linker flag "/LIBPATH:C:\Users\\AppData\Local\Temp\" which has all kinds of interesting security implications
  • It might clash with other projects using the temp dir
  • Other projects (napi_rs, for instance) use OUT_DIR to store the lib

I can do a pull request if you want.

Question: JavaScript Objects

Hi thanks for this awesome project.

How are JavaScript objects handled?

I want to convert a rust type to JavaScript Object - say: $myObj = {};

Can I also convert from JavaScript an Object into a Rust Type?

add tests for modules in electron runtime

Write a test suite for running the native modules in an electron runtime.

NOTE: run the tests after whenReady is resolved, for example:

app.whenReady().then(() => {
// import native modules
// run tests

// comment out the following line to run headless
// return createWindow()
}

Add tests to CI

Return functions

Any way to do this

addon.foo((string)=>{
  string = "slkdfjsf";
  return string;
})

or this

addon.foo((func)=>{
  func("slkdfjsf")
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.