lundi 2 mars 2015

node-gyp: Importing custom modules using process.binding

I want to write node bindings for cares library (Would like to add more functions to existing library but don't want to put as part of node project). I have created new project with below directory structure. deps contains cares and debugger-agent(dependency for cares) which is copied from node project.





.
├── build
├── deps
│ ├── cares
│ │ ├── build
│ │ ├── config
│ │ │ ├── android
│ │ │ ├── cygwin
│ │ │ ├── darwin
│ │ │ ├── freebsd
│ │ │ ├── linux
│ │ │ ├── netbsd
│ │ │ ├── openbsd
│ │ │ ├── sunos
│ │ │ └── win32
│ │ ├── include
│ │ └── src
│ └── debugger-agent
│ ├── include
│ ├── lib
│ └── src
├── lib
└── src



Below is my binding.gyp:





{
'variables': {
'node_shared_cares%': 'true',
},
'targets': [
{
'target_name': 'node_cares',
'sources': [ 'src/node_cares.cc' ],
'include_dirs': [ 'deps/cares/include', 'deps/debugger-agent/include' ],
'source_dirs': [ 'deps/cares/src', 'deps/debugger-agent/src' ],
'library_files': [
'lib/dns.js',
],
'conditions': [
[ 'node_shared_cares=="false"', {
'dependencies': [ 'deps/cares/cares.gyp:cares' ]
}]
]
}
]
}



Output of node-gyp build running under Mac creates following files under build:



  • Debug/cares.dylib

  • Debug/debugger-agent.dylib

  • Debug/node_cares.node


The problem is I don't know where to keep these files so that I can import using process.binding('node_cares'). Tried keeping under projectdir, projectdir/build and projectdir/build/Debug/ but no luck. Sorry I am new to C++ and node addons. Is there any documentation on this(like creating wraps, building and importing them). Any comments or examples are greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire