Search code examples
node.jsnode-webkitnode-modulesnode-gyp

Node-webkit multi platform native module with nw-gyp


I'm currently writing a node-webkit application which uses a native module (lwip). I found out that I need to compile native modules with nw-gyp. After using nw-gyp a new file lwip_image.node will be created under node_modules/lwip/build/Release.

  1. How is the native module required? Like this: var lwip_image = require('./node_modules/lwip/build/Release/lwip_image.node') ??

  2. If the native module was created on Win8 x64, will it also work on Win7 x64 or even Win8/7 x32? Same question for Mac vs Ubuntu x32 vs Ubuntu x64?

  3. To facilitate the build process I would build the native modules on the target platforms once. After that I would like to copy them all to my project dir so I can automate the build process to build it for all platforms at once. How would I go about that? Use os.platform() and require depending on platform? ...

UPDATE: Those posts were what I was looking for: https://github.com/joyent/node/issues/4398#issuecomment-11233144 https://github.com/npm/npm/issues/1891


Solution

    1. Your module's short name will be used in "require"
    2. Your 32-bit code (compiled with target=ia32) will work on 64-bit platform, but not the other way around
    3. After you have compiled your module for all platforms, it should be enough to pack different zip, .app or .exe versions for different platforms, with different respective binaries of your module.