On Mon, Oct 29, 2012 at 4:30 AM, NodeNinja <aeon6f...@gmail.com> wrote:
> On Sunday, October 28, 2012 11:07:48 PM UTC+5:30, mscdex wrote:
>> On Oct 28, 1:15 pm, NodeNinja <aeon6f...@gmail.com> wrote:
>> > and was wondering if there was anyway to target multiple platforms?
>> Sure, you can target multiple platforms in your binding.gyp easily
>> using conditionals like that. However I thought you were originally
>> asking how to compile a Linux executable on Windows.
> My intention in to build the addon on one system preferably having Windows
> OS and then use that addon on Windows and Linux.
> If I do something like this in binding.gyp
> 'conditions': [
> and then building the addon on windows?
> 1. Will three versions of the addon be generated?
No. You need to run the node-gyp configure/build cycle once for each
platform that you target. Here is how you approximately would script
that on a UNIX system:
for OS in linux mac win; do
GYP_DEFINES="-DOS=$OS" CC=gcc-$OS CXX=g++-$OS node-gyp rebuild --arch=ia32
cp build/Release/module.node build/Release/module-$OS.node
CC and CXX need to point to the cross-compilers for the platform that
you're compiling for. If your module is C++ only, you can skip the CC
> 2. Can I then run the addon on Windows and Linux?
> You might be able to get away with using a cross-compiler under >> cygwin, but just mentioning that makes me cringe.
> Your advice is sound mscdex... > I couldn't find much info on the net for cross compiling on windows > possibly install linux on a vm is a good way to start!
Yeah...that is theoretically possible, but good luck getting libc to match, let alone your other bindings, architectures, etc.
Note that having a module that will hapilly 'npm install' on all three OSes does NOT require pre-building them. The Gyp scripting you saw does exactly that: it detects which OS it's building on and follows different instructions for each. Testing all three, on the other hand...I second mscdex' vote for using a virtual machine to test in a native environment. :)
If you're looking at an embedded system, you *might* want to cross-compile the module down to a binary on a different machine, at which point you have stepped into a different arena from simply building something that will compile and run successfully across platforms. (I'd stick it out for native compilation; YMMV.)
> Note that having a module that will hapilly 'npm install' on all three > OSes does NOT require pre-building them. The Gyp scripting you saw does > exactly that: it detects which OS it's building on and follows different > instructions for each. Testing all three, on the other hand...I second > mscdex' vote for using a virtual machine to test in a native environment. :)
> Good luck! > --Jon
Excellent Info Jonathan, the part that modules don't necessarily need to be pre built with the node-gyp system almost skipped me.