You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can we use Clang on Windows to build native modules? I want to use a single open-source compiler for all the platforms. Writing compiler flags for each compiler is not efficient, and they also may have different performance.
you could just not use node-gyp and do something manual in your package.json "build". node-gyp (& gyp) is designed to make it flexible across platforms but if you just want to enforce clang on your users then make your own build script that does everything and bypass node-gyp entirely.
I'm not sure gyp has full clang for windows support, does it @nodejs/gyp? it'd just be a bunch of hacks on hacks to make that work for an addon wouldn't it?
@rvagg could you elaborate on "you could just not use node-gyp and do something manual in your package.json"
I can use napi.h in my c++ files and use clang to generate a dll file on windows but I'm confused on what a .node module file is. Is there a way I can convert a dll to one?
@TrevorDev I can't give you an example off the top of my head, but there are plenty of Node.js addons that don't use node-gyp to build. cmake.js I think is doing their own thing. I've seen plain Makefile builds. The end goal is to build a library that can be dynamically loaded by node and .node is the convention for naming that binary libary. But how you build it is up to you. It just happens that node-gyp has integration in npm, but npm will also run scripts on install so just insert your build process in there. On windows, it's really just a .dll with a different name. I don't know the specifics of the build process but I think you can set an environment variable V to 1 and build someone's addon (via npm install or node-gyp rebuild or whatever) then gyp will show you a verbose compile output and you can see what it's doing. I assume this also works on Windows. You could learn from this process to make your own build script(s) that do what you want. Experiment and you may find a pattern that others can learn from!
For anyone else, this command worked for me:
clang++ test.cpp -Inode_modules\node-addon-api\ -IC:\Users\username.cmake-js\node-x64\v10.16.3\include\node -o test.node -shared C:\Users\username.cmake-js\node-x64\v10.16.3\win-x64\node.lib
I have been working on a new project called cmake-ts. It provides a unified interface for cross-compiling prebuilds for other operating systems (including Windows). It fills in the gaps in the Node ecosystem providing an all-in-one solution for building/prebuilding native addons. So, stay tuned for that (it is still unstable).
Activity
rvagg commentedon Dec 31, 2020
you could just not use node-gyp and do something manual in your package.json
"build". node-gyp (& gyp) is designed to make it flexible across platforms but if you just want to enforce clang on your users then make your own build script that does everything and bypass node-gyp entirely.I'm not sure gyp has full clang for windows support, does it @nodejs/gyp? it'd just be a bunch of hacks on hacks to make that work for an addon wouldn't it?
gengjiawen commentedon Jan 5, 2021
For now, it's kind of buggy, not production ready. Maybe after when we resolve nodejs/node#35433.
TrevorDev commentedon May 5, 2021
@rvagg could you elaborate on "you could just not use node-gyp and do something manual in your package.json"
I can use napi.h in my c++ files and use clang to generate a dll file on windows but I'm confused on what a .node module file is. Is there a way I can convert a dll to one?
rvagg commentedon May 5, 2021
@TrevorDev I can't give you an example off the top of my head, but there are plenty of Node.js addons that don't use node-gyp to build. cmake.js I think is doing their own thing. I've seen plain
Makefilebuilds. The end goal is to build a library that can be dynamically loaded bynodeand.nodeis the convention for naming that binary libary. But how you build it is up to you. It just happens that node-gyp has integration in npm, but npm will also run scripts on install so just insert your build process in there. On windows, it's really just a .dll with a different name. I don't know the specifics of the build process but I think you can set an environment variableVto1and build someone's addon (vianpm installornode-gyp rebuildor whatever) then gyp will show you a verbose compile output and you can see what it's doing. I assume this also works on Windows. You could learn from this process to make your own build script(s) that do what you want. Experiment and you may find a pattern that others can learn from!TrevorDev commentedon May 5, 2021
Woot got it working 🚀, thanks for the info.
For anyone else, this command worked for me:
clang++ test.cpp -Inode_modules\node-addon-api\ -IC:\Users\username.cmake-js\node-x64\v10.16.3\include\node -o test.node -shared C:\Users\username.cmake-js\node-x64\v10.16.3\win-x64\node.lib
aminya commentedon May 5, 2021
@TrevorDev I'm glad that you made it work.
I have been working on a new project called
cmake-ts. It provides a unified interface for cross-compiling prebuilds for other operating systems (including Windows). It fills in the gaps in the Node ecosystem providing an all-in-one solution for building/prebuilding native addons. So, stay tuned for that (it is still unstable).https://github.com/EmbeddedEnterprises/cmake-ts/