Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify output directory #848

Closed
gabrielschulhof opened this issue Dec 28, 2015 · 6 comments
Closed

Modify output directory #848

gabrielschulhof opened this issue Dec 28, 2015 · 6 comments

Comments

@gabrielschulhof
Copy link

Currently, I cannot find a documented way to change the output directory from "build/". I've noticed that node-gyp runs gyp_main.sh passing in --generator-output build essentially without an opportunity to modify it.

Is it nevertheless possible to modify it?

@bnoordhuis
Copy link
Member

It's hard-coded currently. Why would you want to change it? It would break most add-ons.

@gabrielschulhof
Copy link
Author

I'm adding Node.js bindings to a C library as part of the C library's repository. The C library uses Kconfig, and the node bindings depend on the whole of the C library. By default, the C library places its output into build/. So, when npm install runs as the last step of the library's build process, it removes build/ and then creates it - but the bindings depend on everything that has previously been put into build/, such as public headers etc.

This is only a problem because I'd like to

  1. Not have to document that, if you want to build Node.js bindings, you have to start with npm install and not make menuconfig && make - this would be good, because the contents of the bindings should reflect the configuration choices that you've made for the library.
  2. Support both the scenario where the user turns on node bindings from make menuconfig and then runs make as well as the scenario where she simply runs npm install.

If it were possible to build into another directory, I could still move it back to build/ after npm install was done, because npm install is getting called from a make target in the parent C library.

@gabrielschulhof
Copy link
Author

@bnoordhuis
Copy link
Member

I think what you're describing is because npm does a node-gyp rebuild (which implies node-gyp clean) if you don't have an explicit install rule in your package.json. If you add a node-gyp configure && node-gyp build, it should work (I think.)

I'm open to a PR that makes the build directory configurable but it may not be necessary is my point. :-)

@gabrielschulhof
Copy link
Author

Why is it that, when you install node, it automatically installs npm, which automatically installs node-gyp, but node and npm end up in your PATH, whereas node-gyp does not? I ask because the C library build script makes the availability of the bindings contingent upon the presence of node on the PATH. It would be nice if I didn't have to deduce the location of node-gyp from the directory in which I find node - i.e., $(dirname which node)/../lib/node_modules/npm/bin/node-gyp-bin/node-gyp. OTOH I'd really like to avoid having to tell people that, if they want the bindings, they need to first npm install -g node-gyp, especially knowing that node-gyp is already on their system whenever node is on their system. Perhaps node-gyp should also be bundled with node, like npm, since it kind of already is.

Anyhoo, my solution so far is to

node_bindings: $(SOL_LIB_OUTPUT)

    # Install dependencies
    node -e 'Object.keys(require("./package.json").dependencies).map(function(item){console.log(item);})' | xargs npm install

    # Build the package without clobbering build/
    SOLETTA_FROM_MAKE=true $(dirname `which node`)/../lib/node_modules/npm/bin/node-gyp-bin/node-gyp configure
    SOLETTA_FROM_MAKE=true $(dirname `which node`)/../lib/node_modules/npm/bin/node-gyp-bin/node-gyp build

PHONY += node_bindings

I guess if there's no cleaner solution then this issue can be closed.

@bnoordhuis
Copy link
Member

Perhaps node-gyp should also be bundled with node, like npm, since it kind of already is.

Maybe you can raise an issue over at https://github.com/nodejs/node/issues if you feel strongly about that? I personally would be okay with making the installers put node-gyp on the PATH and it's already the recommended practice to use the node-gyp that's distributed with node.

I'll go ahead and close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants