简体   繁体   中英

node-gyp platform specific addon

Is it possible to specify that a certain native addon is only meant to be build for a certain platform (eg: win32 )?

Currently I have a C++ addon that makes use of the Windows API, but node-gyp attempts to build that for UNIX based systems as well.

I've been searching in node-gyp documentation and NodeJS C/C++ addon documentation section without any luck.

Yes.

You can add an "os" section to your package.json to restrict which platforms your addon is compatible with.

Here is the OS package.json documentation.

You can define your own installation script that checks the platform and conditionally builds the binary based on platform.

For example, js-bson includes a custom script the attempt to build and fail silently. You could instead include a script in there that checks the OS, and only runs node-gyp rebuild if the system is windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM