gyp.js icon indicating copy to clipboard operation
gyp.js copied to clipboard

`shared_library` support

Open indutny opened this issue 9 years ago • 23 comments

gyp.js currently supports static_library, executable, and none target_type, but shared_library is very important for Node.js addons! Therefore we need to support it in ninja.

Hints:

  • New ninja rule solink needs to be added here
  • This rule should be used there

Possible problems - many.

Support:

  • [x] OS X
  • [x] Windows
  • [x] Linux
  • [x] FreeBSD (needs verification, should work)
  • [ ] Others (needs verification, should work)

indutny avatar Jun 12 '16 20:06 indutny

Could be tested on https://github.com/indutny/llnode

indutny avatar Jun 12 '16 21:06 indutny

I'm going to take OS X support for this.

indutny avatar Jun 12 '16 21:06 indutny

OS X - done.

indutny avatar Jun 12 '16 23:06 indutny

Linux - appears to be working.

indutny avatar Jun 13 '16 00:06 indutny

I'm inclined to say that FreeBSD and other Unixes should work, but this needs a verification.

indutny avatar Jun 13 '16 00:06 indutny

Anyone wants to verify this?

indutny avatar Jun 17 '16 17:06 indutny

Hey i'd like to ! Could you tell me where i should start ? llnode seems to be something different.

kapouer avatar Jun 17 '16 19:06 kapouer

@kapouer thank you!

@pmed you said that you tested windows shared_library support on node.js addons, would you care to share some info on this with us? Thanks!

indutny avatar Jun 17 '16 19:06 indutny

@kapouer llnode may be a bit too complicated. However, if you want to give it a shot, the way to do it is:

  • Install node.js on the system
  • Install ninja from https://ninja-build.org/
  • npm install -g gyp.js
  • git clone [email protected]:indutny/llnode.git && cd llnode
  • Install lldb-3.8 or any lldb, and its headers (Honestly, I don't know how to do it on FreeBSD, or anywhere else except Mac and Linux)
  • run gyp -Icommon.gypi llnode.gyp
  • run ninja -C out/Release
  • ls -la out/Release
  • should have llnode.so

indutny avatar Jun 17 '16 19:06 indutny

Alright, I have pushed gyppies to the repo. So it should be possible to test this by just running npm test. Note that tests should be run from MSVS console on Windows, and the NINJA env variable should be set to the full path to ninja.exe.

indutny avatar Jun 17 '16 21:06 indutny

@indutny, I've forked node-gyp to use gyp.js instead of gyp: https://github.com/pmed/node-gyp/tree/gyp.js

To build a native addon you just need a C++ compiler and Ninja installed. Visual C++ is used by default on Windows (my version of node-gyp tries to locate a VC++ version installed in the system).

And ninja executable should be in a PATH. Yoг can also set NINJA environment variable or set -ninja command line option for node-gyp to override the ninja location.

ps. I just saw you added platform.win.genEnvironment() that performs similar to findMSVS() function. Probably I would try to use your implementation.

pmed avatar Jun 18 '16 12:06 pmed

@pmed Fantastic!

indutny avatar Jun 18 '16 17:06 indutny

@pmed I have just pushed some fixes, and it appears that all npm tests pass on Windows, except the copy one.

indutny avatar Jun 18 '16 17:06 indutny

@pmed One more thought: what do you think about contributing your patch back to node-gyp, with gyp.js used under a command-line flag or env variable?

indutny avatar Jun 18 '16 18:06 indutny

See: https://github.com/nodejs/node-gyp/issues/960

indutny avatar Jun 18 '16 18:06 indutny

Yes, command-line flag to switch between gyp and gyp.js would be great. And I'd like to use gyp.js by default some time later :smile:

The switch should be the same for the configure and build commands, so env.variable seems preferable.

pmed avatar Jun 18 '16 19:06 pmed

@pmed I would go with both, probably? Is it too hard to do it in an existing architecture?

Thanks for looking into it.

indutny avatar Jun 18 '16 19:06 indutny

@indutny yes, both, with comman-line option and env var. It shouldn't be hard to keep branches both for gyp and gyp.js in configure and build commands.

I added the gyp.js dependency into node-gyp/package.json, and use gyp.main() on configure step. Build function spawns ninja -C build/Release (or build/Debug). On Windows build function in node-gyp invokes vcvarsall.bat $target_arch before ninja.

I can try to make a PR into node-gyp.

pmed avatar Jun 18 '16 19:06 pmed

Just run npm test on FreeBSD, everything appears to be working.

indutny avatar Jun 18 '16 21:06 indutny

@indutny what would you consider "others"? sunos and aix-ppc? I can try to compile on a raspberry-pi 2 running noobs, and on a MIPS32 OpenWRT machine

refack avatar Feb 09 '17 19:02 refack

Well llnode was a wild goose chase, it doesn't compile cleanly on VS2015 with GYP... :( But I was able to compile node.dll, anybody know who do you test it?

refack avatar Feb 10 '17 12:02 refack

@refack yeah solaris, aix, everywhere where node works.

indutny avatar Feb 12 '17 23:02 indutny

Cracking up my emulator...

refack avatar Feb 13 '17 00:02 refack