Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Visual Studio 2017 #1101

Closed
wants to merge 6 commits into from

Conversation

bzoz
Copy link
Contributor

@bzoz bzoz commented Jan 31, 2017

Add support for Visual Studio 2017 to node-gyp

With this version VS does not use Windows registry any more, instead it installs a COM server that one can query to obtain list of installed modules and their locations - see this blogpost: https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/.

Python does not support communicating with COM servers directly. Chromium project when updating GN did not add extra library, instead assuming default installation path with environment variable override (see https://cs.chromium.org/chromium/src/build/vs_toolchain.py?q=vs_toolchain&sq=package:chromium&l=150). I've used the same method to update GYP - default installation path and default Windows SDK version with override. PR for GYP has been also opened upstream: https://chromium-review.googlesource.com/#/c/433540/

To ease usage for node-gyp users, a Python script that can obtain VS installation path and installed SDK version is provided. It depends on comtypes Python library (https://github.com/enthought/comtypes) which adds support for COM to Python. This script is in turn used by node-gyp to set proper environment variables overrides.

For easier review this PR is split into 4 commits:

  • First commit adds comtypes Python library. It is needed to query VS COM server about installation paths.

  • Second commit adds support for VS2017 to gyp. Similar to the way it was implemented in gn, it assumes that VS2017 Professional was installed in the default location. User can use two environment variables to overwrite this: VS2017_INSTALL for installation path and VS2017_SDK for installed SDK version. This patch was also commited upstream: https://chromium-review.googlesource.com/#/c/433540/

  • Third commit moves PythonFinder to separate file. We will use Python in build stage to locate new msbuild installation location.

  • Fourth commit adds VS2017 support to node-gyp. It includes Python script that can communicate with VS2017 COM server, and necessary changes to configure and build stages.

Ref: nodejs/node#11084,
#1056

bzoz added 4 commits January 30, 2017 16:22
Add comtypes library: https://github.com/enthought/comtypes. It adds support
for using COM, which we need to find Visual Studio 2017 location.
Adds support for generating solutions and building with Visual Studio 2017
Python will be also used by build stage
Add support for building with Visual Studio 2017
@refack
Copy link
Contributor

refack commented Feb 1, 2017

@bzoz Great job tracking down the COM api 👍 but isn't comtypes overkill, you can just trigger COM objects via powershell. Or I can compile a tiny tool for that.

@refack
Copy link
Contributor

refack commented Feb 2, 2017

tiny tool 29KB made from Microsoft/vs-setup-samples.
It has easy to parse text output, e.g.

C:\temp$ Setup.Configuration.CS.exe
InstanceId: 45ec1659 (Complete)
InstallationVersion: 15.0.26020.0 (4222126355906560)
InstallationPath: D:\bin\dev\VS\2017\BuildTools
Product: Microsoft.VisualStudio.Product.BuildTools
Workloads:
    Microsoft.VisualStudio.Workload.MSBuildTools
    Microsoft.VisualStudio.Workload.VCTools

and the env manipulation bat is at ${InstallationPath}\Common7\Tools\VsMSBuildCmd.bat

@refack refack mentioned this pull request Feb 2, 2017
@refack
Copy link
Contributor

refack commented Feb 8, 2017

VS2017 build tools on Windows 7SP1:

gyp ERR! stack Error: Command failed: c:\bin\dev\python27\python.EXE \\REFAELUX\code\3party\node-gyp\find_vs2017.py
gyp ERR! stack Traceback (most recent call last):
gyp ERR! stack   File "\\REFAELUX\code\3party\node-gyp\find_vs2017.py", line 173, in <module>
gyp ERR! stack     main()
gyp ERR! stack   File "\\REFAELUX\code\3party\node-gyp\find_vs2017.py", line 158, in main
gyp ERR! stack     installs = GetVS2017CPPBasePath()
gyp ERR! stack   File "\\REFAELUX\code\3party\node-gyp\find_vs2017.py", line 106, in GetVS2017CPPBasePath
gyp ERR! stack     iface = CreateObject(GUID('{177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D}'))
gyp ERR! stack   File "\\REFAELUX\code\3party\node-gyp\comtypes\comtypes\client\__init__.py", line 238, in CreateObject
gyp ERR! stack     obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
gyp ERR! stack   File "\\REFAELUX\code\3party\node-gyp\comtypes\comtypes\__init__.py", line 1225, in CoCreateInstance
gyp ERR! stack     _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
gyp ERR! stack   File "_ctypes/callproc.c", line 945, in GetResult
gyp ERR! stack WindowsError: [Error -2147221164] Class not registered

Apparently the COM interface doesn't get registered
(I get the same with the above COM calling EXE)

@bzoz
Copy link
Contributor Author

bzoz commented Feb 9, 2017

@refack sorry, I cannot reproduce. After installing "Build Tools for Visual Studio 2017 RC" on Windows 7 python script can locate it.

However, I can get this error for clean Windows installation, when VS2017 was never installed. Fixed the script.

@refack
Copy link
Contributor

refack commented Feb 10, 2017

I trying with some minimal component set and found that the COM server wasn't registered...

P.S. funny thing, the Installer is an electron app

@heaths
Copy link

heaths commented Feb 13, 2017

I own the COM APIs. They are registered when you install VS, though in some older previews there were some circumstances in which they would get prematurely unregistered. That was fixed, IIRC, in RC2.

I recommend using the native COM APIs with IUnknown bindings, which would be easier to use in C++. Or is this about setting up a node-gyp project rather than using in a Node native add on?

@refack
Copy link
Contributor

refack commented Feb 13, 2017

@heaths thank for the reply. Since this is a nodejs / python project, we're trying not to cloud it with other languages or precompiled EXEs. I just converted my C# code to be .NET 2.0 compatible so now we have a way to call it from powershell 2.0.
As for the registration, at one instance I installed the "Build Tools for Visual Studio 2017 RC" on windows 7 pro SP1, in a very minimal way and the COM wasn't registered... I'll try to repro.

@heaths funny thing that the Installer is electron, what goes around comes around :)

@heaths
Copy link

heaths commented Feb 13, 2017

Sounds like the build tools are missing a dependency, then. I'll track this down.

@refack
Copy link
Contributor

refack commented Feb 13, 2017

@heaths moving to microsoft/vs-setup-samples#5

@bzoz
Copy link
Contributor Author

bzoz commented Mar 15, 2017

Not needed since #1130 landed.

@AndrewPardoe
Copy link

The officially supported vswhere tool is now available as part of the install starting today with Visual Studio 15.2 preview 2: https://blogs.msdn.microsoft.com/heaths/2017/04/21/vswhere-is-now-installed-with-visual-studio-2017/. This doesn't fix all the existing installs of VS 2017 but going forward you can now detect the VS install locations and whether C++ tools are available from a scripted environment. I hope this helps your scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants