neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
8.04k stars 284 forks source link

Error building new project (neon-build) #186

Closed squiidz closed 7 years ago

squiidz commented 7 years ago

Hi, i just created a new neon project, but it doesn't seems to build ... Here's the log.

Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling nod v0.1.0 (file:///Users/jchaput/dev/rust/nod/native)
Compiling cslice v0.1.1
Compiling gcc v0.3.43
error[E0463]: can't find crate for `neon_build`
 --> build.rs:1:1
  |
1 | extern crate neon_build;
  | ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

error: Could not compile `nod`.
Build failed, waiting for other jobs to finish...
error: build failed
neon ERR! cargo build failed
error Command failed with exit code 1.

thanks

dherman commented 7 years ago

I've just published a new version of neon that fixed a lot of build issues, although I'm still working out the kinks. Would you mind trying updating to neon-cli 0.1.12 and recreating the project and try again?

squiidz commented 7 years ago

I just tried the new version with a new project and got this error:

error: failed to run custom build command for 'neon-runtime v0.1.12'
process didn't exit successfully: 
/Users/jchaput/dev/rust/nod/native/target/release/build/neon-runtime-ca6fef9d30530229/build-script-build (exit code: 101)
--- stdout
Skipping node-gyp installation as part of npm install.
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
running: "ar" "crs" "/Users/jchaput/dev/rust/nod/native/target/release/build/neon-runtime-46530539b89c1ebd/out/libneon.a" "build/Release/obj.target/neon/src/neon.o"
cargo:warning=ar: build/Release/obj.target/neon/src/neon.o: No such file or directory
ExitStatus(ExitStatus(256))

command did not execute successfully, got: exit code: 1
dherman commented 7 years ago

Argh! OK I'm getting familiar with that error (but oh my heavens do I need to improve the errors). This seems to happen when the neon-runtime build script incorrectly finds the node-gyp script.

Can you show me the output of which node and ls $(which node) on your system?

squiidz commented 7 years ago

which node: /usr/local/bin/node ls: /usr/local/bin/node

thanks for the quick response btw

dherman commented 7 years ago

Does /usr/local/lib/node_modules/npm/node_modules/node-gyp exist on your system?

squiidz commented 7 years ago

yep

dherman commented 7 years ago

OK, so I'm gonna need some more info than the error is giving you -- would you be willing to let me dictate some local hacks to get the build scripts to spew more info?

(Thank you so much for this help, btw -- you're helping me make this software actually, like, work. :P)

squiidz commented 7 years ago

yeah no problem !

dherman commented 7 years ago

OK awesome! So first, clone this repo (neon, not neon-cli) somewhere on your system, and then hack neon/crates/neon-runtime/build.rs -- inside the build_object_file function, right after where it says let output = node_gyp().args(&configure_args).output().expect(...); add another few statements:

    println!("==================");
    println!("CONFIGURE:");
    println!("{}", String::from_utf8_lossy(&output.stderr));
    println!("==================");

Then inside neon/crates/neon-runtime, run cargo build and share the output here -- we'll see if that gives us some more insight.

squiidz commented 7 years ago
error: failed to run custom build command for `neon-runtime v0.1.12 (file:///Users/jchaput/dev/rust/neon/crates/neon-runtime)`
process didn't exit successfully: `/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-bf06a6f3713ebbc7/build-script-build` (exit code: 101)
--- stdout
Skipping node-gyp installation as part of npm install.
/Users/jchaput/dev/rust/neon/crates/neon-runtime
├── bindings@1.2.1
└── nan@2.5.1

==================
CONFIGURE:

==================
==================
CONFIGURE:

==================
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
running: "ar" "crs" "/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-ed514f00c83adf93/out/libneon.a" "build/Debug/obj.target/neon/src/neon.o"
cargo:warning=ar: build/Debug/obj.target/neon/src/neon.o: No such file or directory
ExitStatus(ExitStatus(256))

command did not execute successfully, got: exit code: 1
squiidz commented 7 years ago

sorry bad output ...

process didn't exit successfully: `/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-bf06a6f3713ebbc7/build-script-build` (exit code: 101)
--- stdout
Skipping node-gyp installation as part of npm install.
==================
CONFIGURE:
module.js:472
    throw err;
    ^

Error: Cannot find module '/usr/local/Cellar/node/7.5.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3

==================
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
running: "ar" "crs" "/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-ed514f00c83adf93/out/libneon.a" "build/Debug/obj.target/neon/src/neon.o"
cargo:warning=ar: build/Debug/obj.target/neon/src/neon.o: No such file or directory
ExitStatus(ExitStatus(256))

command did not execute successfully, got: exit code: 1
dherman commented 7 years ago

OK, so that's not where it's going wrong. Let's try the next node-gyp command: at the end of build_object_file, where it says node_gyp().stderr(Stdio::null()).args(&build_args).status().ok().expect(...), change it to:

    let output = node_gyp()
        .args(&build_args)
        .output()
        .expect("Failed to run \"node-gyp build\" for neon-runtime!");
    println!("--------------------");
    println!("BUILD:");
    println!("{}", String::from_utf8_lossy(&output.stderr));
    println!("--------------------");

And then run cargo build in the neon-runtime directory again.

squiidz commented 7 years ago
error: failed to run custom build command for `neon-runtime v0.1.12 (file:///Users/jchaput/dev/rust/neon/crates/neon-runtime)`
process didn't exit successfully: `/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-bf06a6f3713ebbc7/build-script-build` (exit code: 101)
--- stdout
Skipping node-gyp installation as part of npm install.
--------------------
BUILD:
module.js:472
    throw err;
    ^

Error: Cannot find module '/usr/local/Cellar/node/7.5.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3

--------------------
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
HOST = Some("x86_64-apple-darwin")
AR_x86_64-apple-darwin = None
AR_x86_64_apple_darwin = None
HOST_AR = None
AR = None
TARGET = Some("x86_64-apple-darwin")
TARGET = Some("x86_64-apple-darwin")
running: "ar" "crs" "/Users/jchaput/dev/rust/neon/crates/neon-runtime/target/debug/build/neon-runtime-ed514f00c83adf93/out/libneon.a" "build/Debug/obj.target/neon/src/neon.o"
cargo:warning=ar: build/Debug/obj.target/neon/src/neon.o: No such file or directory
ExitStatus(ExitStatus(256))

command did not execute successfully, got: exit code: 1
dherman commented 7 years ago

We're getting warmer... What does ls /usr/local/Cellar/node/7.5.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js do?

squiidz commented 7 years ago

ls: /usr/local/Cellar/node/7.5.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js: No such file or directory

dherman commented 7 years ago

How about ls -l $(which node) ?

squiidz commented 7 years ago

lrwxr-xr-x 1 jchaput admin 29 8 Feb 08:50 /usr/local/bin/node -> ../Cellar/node/7.5.0/bin/node

dherman commented 7 years ago

A few more -- we're making progress :)

ls -l /usr/local/Cellar/node/7.5.0/lib ls -l /usr/local/lib/node_modules

(There's something about your node installation setup that is tripping the build script up. It seems like it might have to do with how some symlinks are organized.)

dherman commented 7 years ago

Actually since it looks like you have a standard homebrew installation of node, maybe I can just test that on my system. I'm using node via nvm instead of homebrew, so that's probably the root cause.

squiidz commented 7 years ago

drwxr-xr-x 3 jchaput admin 102 31 Jan 17:19 dtrace

drwxr-xr-x  19 jchaput  admin  646 11 Feb 15:12 angular-cli
drwxr-xr-x   9 jchaput  admin  306 18 Dec 14:26 express
drwxr-xr-x   3 jchaput  admin  102 18 Dec 14:25 express-cli
drwxr-xr-x  14 jchaput  admin  476 17 Feb 13:03 neon-cli
drwxr-xr-x  27 jchaput  admin  918  8 Feb 08:50 npm
drwxr-xr-x   9 jchaput  admin  306  4 Dec 16:31 oni-plugin-typescript
drwxr-xr-x  21 jchaput  admin  714  4 Dec 16:30 oni-vim
squiidz commented 7 years ago

let me know if it's work on your side with homebrew

dherman commented 7 years ago

OK I think that tells me enough -- I'll try it on my system! Thanks again…

dherman commented 7 years ago

OK it looks like homebrew installs node-gyp in yet another subdirectory. Now I know of different directory structures for Windows node, unix node, nvm node, and homebrew node. O_o

This does not seem like a sustainable approach to finding and invoking node-gyp!

In my head I keep flirting with the idea of just putting the node-gyp npm package as a local dependency. The main reason I was reluctant turns out to be wrong: I thought we'd have to install different versions of node-gyp depending on which version of node the client is using, but I see that node-gyp can be used across multiple node versions, so that's not an issue.

So the only real concern then is just that it'll add another 5 or 6 seconds of build time for neon-runtime (for npm to install the node-gyp dependency). I think that's probably preferable to constantly fighting with brittle differences in directory layout across different installation flavors of node.

dherman commented 7 years ago

@squiidz #189 should fix this -- it works in homebrew on my machine. I think it's just a more robust approach. It does bump the Rust version requirement up to 1.15, but I think that's OK.

squiidz commented 7 years ago

Great, I will try it this weekend ! To me 5s more to build is not a issue. Good job :)

squiidz commented 7 years ago

Works fine on my system ! 👍