build: windows sharedlib support
Checklist
-
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
build
Description of change
Following https://github.com/nodejs/node/pull/6994 the next step is to provide support for generating a DLL on Windows for people using Node.js as a shared library. This commit makes the necessary changes, but unfortunately it requires a floating patch to V8's gyp files. I do not believe there is any way around this issue, so I am opening the PR now to get some feedback on my approach.
Overview:
- Added "dll" option to vcbuild.bat
- Insure that Unix SO name is not used on Windows (i.e. produce a .dll file)
- Insure that Node and its V8 dependency link against the Visual C++ Runtime dynamically.
The last point is very important. In Windows If different libraries you link use different versions of the C++ Runtime you will get a variety of issues that are well documented here: http://siomsystems.com/mixing-visual-studio-versions/. Note that this situation can occur in multiple ways:
- If different libraries in your program mix static and dynamic runtime libraries.
- If different libraries in your program mix versions of Visual Studio.
- If both situations above occur.
This also means that people using node.dll
must also use the exact same Visual Studio version that Node was compiled with to build the program that links against the DLL. Further information is available here: https://www.softwariness.com/articles/visual-cpp-runtime-libraries/
The basic problem with V8 is that its gyp files are setup to always link statically against the C++ runtime unless V8 itself is being compiled as a shared library. The floating patch I provided is minimal and is inspired by https://github.com/qt/qtwebengine-chromium/commit/743a6413f3cc0a621865a81f06c6d7bed7b662c5.