infinyon / node-bindgen Goto Github PK
View Code? Open in Web Editor NEWEasy way to write Node.js module using Rust
License: Apache License 2.0
Easy way to write Node.js module using Rust
License: Apache License 2.0
steps to reproduce:
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
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
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.
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
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
This should watch the src
directory for changes made to the native source files and run nj-cli build
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).
nj-cli build
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
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!
The ```init`` command will create a skeleton project to populate a cargo project with
build.rs
This should be similar to cargo init
commands.
This should make it easier to start with node-bindgen.
derive macro to generate JSON structure for try_to_js.
see examples/json
N-API
is ok for now. However, there are some limitations with N-API.
It maybe we can create new abstraction that will make easier to integrate Rust and Node.js (Deno)
First decided on GitHub Action or Travis.
Ability to build and test for following configuration:
Other considerations:
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.
electron test were disable due to Node
security issue.
Update npm
libraries and re-enable electron test
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:
minimum
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
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( );
For Option, return
I have a simple test repo: https://github.com/nickbabcock/node-bindgen-async-test
The code is a simple wrapper around sled to simulate a bit more of a real world example than the one found in this repo.
The CI is extremely flaky, but if I change everything to synchronous -- tests pass no problem. It's almost as if nodejs isn't respecting the await
nj-cli build
to be fail 100% in a link-time
error: linking with `link.exe` failed: exit code: 1120
cargo install nj-cli
cargo new --lib e1
; $ cd e1
[lib]
, crate-type = ["cdylib"]
[dependencies]
, node-bindgen = "2.1.1"
[build-dependencies]
, node-bindgen = {version = "2.1.1", features = ["build"]}
use node_bindgen::derive::node_bindgen;
/// add two integer
#[node_bindgen]
fn sum(first: i32, second: i32) -> i32 {
first + second
}
nj-cli build
( to be failed on Windows )stable-x86_64-pc-windows-msvc
, nightly-x86_64-pc-windows-msvc
1.44.1 (c7087fe00 2020-06-17)
, 1.46.0-nightly (0c03aee8b 2020-07-05)
[dependencies]
/[build-dependencies
] 2.1.1nj-cli
fluvio 0.2.0I 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.
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 😊
/// 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.
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.
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)
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.
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)
}
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]) {}
Release package on crates.io
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. 👍
Nodebindgen uses async-std/smol to execute future task. However, Nodejs has it's own execution infrastructure result in duplicate thread pool. This issue investigate possible way to integrate them efficiently.
With latest changes in smol, it is probably possible to execute Rust's future task in Nodej's thread pool.
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'
neon
Using dherman/electron-build-env
makes it easy to prepare a workspace for repro.
./native
directory, prepare a cdylib project use node-bindgen../
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
.yarn experiment0
.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.
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
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 |
Currently () is returned as null ptr which leads to crash in the Napi. Instead it should be mapped as undefined
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
I can do a pull request if you want.
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?
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
support conversion of Vec to napi Array
Any way to do this
addon.foo((string)=>{
string = "slkdfjsf";
return string;
})
or this
addon.foo((func)=>{
func("slkdfjsf")
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.