Repository navigation
Use Clang on Windows #2295
Description
Activity
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?
For now, it's kind of buggy, not production ready. Maybe after when we resolve nodejs/node#35433.
@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
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!Reacted by Trevor Baron and Anoop M DWoot 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@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).Reacted by Trevor Baron
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.
This might be related to: