Open jdoig opened 1 year ago
Can you provide OS, Rust, and other information to debug this?
Can you provide OS, Rust, and other information to debug this?
Sorry :facepalm: , of course @sehz : OS:
NAME="Pop!_OS"
VERSION="22.04 LTS"
Rust (I've tried with both of these:
stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
I've tried compiling with node-bindgen 4.3 and 5 but get the same errors.
@simlay Please take look at this
Hmm. This looks to be related to how the nj-core is linked to node at completive. @jdoig What's your nodejs setup like? Like, I'm using fnm
to manage which nodejs I'm using and this builds with node 14 (as that's what a project I work on sometimes uses).
Though, now that I look at the node repo, it looks like napi_module_register
is soon to be deprecated but napi_define_properties
isn't.
@simlay My node setup is very much that of someone who's a node novice/hobbyist . My current goal is to port some of our auth' code over to a rust library I can call from Python/Node/etc for our other developers. So that we have ve a single uniformed auth library with strong typing and good error handling. Node isn't my runtime of choice :smile:
Typically I've node 14/16/18 installed and controlled via nvm
. And now, to follow your setup I've also installed fnm
and tired this using: 14/18/system versions of node though fnm` ... all with the same error still :disappointed:
I've checked my gcc
, make
and python
versions against Node's toolchain requirements.
And here's some "clutching-at-straws" steps I've taken :laughing: :
node-gyp
, node-ffi
(based on some searches for node ffi tools and libraries).cmake-js install
to: Install Node.js distribution files if needed
.But still the same problem.
Though, now that I look at the node repo, it looks like
napi_module_register
is soon to be deprecated butnapi_define_properties
isn't.
Please note that while we consider simplification of Node-API module registration and stopping use of napi_module_register
, we do not remove any existing API functions. To keep the ABI compatibility this function will be there for a long time.
Ok this is utterly embarrassing :flushed: ... The function I was wanting to expose had it's
#[node_bindgen()]
commented out.
One interesting issue with this is:
Now I have un-commented that line everything works ... as long as I don't have a build.rs
as soon as I add it back into the project I get exactly the same error as before :confused:
This is still causing problems:
node_bindgen::build::configure();
in build.rs causes it not to build (though looking at the code that configure should noop on Linux right?) with the initial error.build.rs
both cargo
and nj-cli
can build my library ... BUT cargo test
fails with the initial
error.So I can now build my node binary and it all seems to be working form inside a node session ... I just cant run my unit tests.
Update: To rule out any weirdness in my local terminal session I started up a fresh Debian Docker container: apt installed nodejs and gcc, then installed rust through rustup-init.sh
... same results, I can build but cant test :confused:
Update: I also have tried compiling the node-bindgen examples with the same issues.
Update: I'm not sure if it's at all relevant but I've also tried compiling Neon examples and they compile fine and test fine with no linking issues.
Update: Just had a colleague with an M2 Mac try this with similar results. Can cargo build
cant cargo test
the /examples
folder of this repo without getting linking errors:
param git:(master) cargo test
Compiling nj-example-param v0.0.0 (/Users/xxx/node-bindgen/examples/param)
Finished test [unoptimized + debuginfo] target(s) in 0.28s
Running unittests src/lib.rs (/Users/xxx/node-bindgen/examples/target/debug/deps/nj_example_param-67c9517494263fc8)
dyld[80564]: symbol not found in flat namespace (_napi_create_int32)
error: test failed, to rerun pass '--lib'
Caused by:
process didn't exit successfully: `/Users/xxx/node-bindgen/examples/target/debug/deps/nj_example_param-67c9517494263fc8` (signal: 6, SIGABRT: process abort signal)
(he got the same error when he did pass the --lib flag too)
I can confirm as I ran into the same issue:
extra/nodejs
build.rs
:
fn main() {
node_bindgen::build::configure();
}
Cargo.toml
[package]
name = "project-name"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
node-bindgen = { version = "5.1" }
[...]
[build-dependencies]
node-bindgen = { version = "5.1", default-features = false, features = ["build"]}
Results in this error:
> ~/.cargo/bin/nj-cli build -o dist
|
= note: LC_ALL="C" PATH="~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:~/.cargo/bin:~/.local/bin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl" VSLANG="1033" "cc" "-m64" "/tmp/rustcHYSVpD/symbols.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.1u26bdjqvo8hjbno.rcgu.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.484c40cyeng6z092.rcgu.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.g1afhabpyeyft7b.rcgu.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.pzta0jecpcl93jf.rcgu.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.qt7jpx7nnsf9p38.rcgu.o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e.1xta2omldd5rwbqj.rcgu.o" "-Wl,--as-needed" "-L" "~/project-folder/target/debug/deps" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "~/project-folder/target/debug/deps/libnode_bindgen-72f039e41aead63a.rlib" "~/project-folder/target/debug/deps/libnj_build-1aaf22f736cb42df.rlib" [...] "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-35b8a4bd2de4e62e.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "~/project-folder/target/debug/build/project-name-c045ed565816713e/build_script_build-c045ed565816713e" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
= note: /usr/bin/ld: ~/project-folder/target/debug/deps/libnj_core-aaa6e789a8145b4c.rlib(nj_core-aaa6e789a8145b4c.nj_core.8b52fda313818e30-cgu.14.rcgu.o): in function `nj_core::module::init_module':
~/.cargo/git/checkouts/node-bindgen-48597ec4d5b120bf/dba17af/nj-core/src/module.rs:90: undefined reference to `napi_module_register'
/usr/bin/ld: ~/project-folder/target/debug/deps/libnj_core-aaa6e789a8145b4c.rlib(nj_core-aaa6e789a8145b4c.nj_core.8b52fda313818e30-cgu.0.rcgu.o): in function `nj_core::basic::JsExports::define_property':
~/.cargo/git/checkouts/node-bindgen-48597ec4d5b120bf/dba17af/nj-core/src/basic.rs:963: undefined reference to `napi_define_properties'
collect2: error: ld returned 1 exit status
= note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the `-l` flag to specify native libraries to link
= note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
error: could not compile `project-name` (build script) due to previous error
Removing/Uncommenting the node_bindgen::build::configure()
line in build.rs
fixes the issue and the project builds correctly.
I can also confirm as I also ran into the same issue. Simply deleting build.rs
or not having node_bindgen::build::configure()
in it fixes the problem and the bindings still work as expected.
getting the same issue on ubuntu 22.0.4 with nodejs 16.20.1 & rust 1.71.0, removing build.rs works
I'm getting an error:
Could someone please advise me on what I need to do to get my project building?