-
Notifications
You must be signed in to change notification settings - Fork 295
Better Support for Visual Studio 2017 and 2019 #892
Better Support for Visual Studio 2017 and 2019 #892
Conversation
These are supported in `node-gyp@5`, which we now use. We should be able to detect these versions to set the `--msvs_version` node-gyp flag correctly. The default install path structure is different starting with Visual Studio 2017. e.g. C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE
Older versions have only one path to check, whereas starting with Visual Studio/C++ Build Tools 2017, multiple distinct install directories exist (one per edition). i.e. Community, Professional, Enterprise, Build Tools, and Express. Conditioning these path checks by version can reduce the filesystem reads (in the worst-case scenario) by 22.
node-gyp v5 refuses to use any Visual Studio older than 2013. With Node >= 8, node-gyp v5 also refuses to use Visual Studio 2013. We bundle and enforce the use of Node 10 now, eventually even newer. Therefore, with versions of Visual Studio < 2015 not usable, we shouldn't detect them or have apm/node-gyp attempt to use them. (This also saves up to 3 filesystem reads.)
In modern node-gyp, this flag only serves to limit node-gyp to using a specific version of Visual Studio. It can't make node-gyp find a version it wouldn't have found. Our checks are much less sophisticated at detecting usable installations of Visual Studio. We should let node-gyp use the install of Visual Studio/Build Tools it thinks is best. It will pick any usable Visual Studio install, preferring the newest if multiple are installed and usable. It generally will not pick one mistakenly that it actually can't use. Given that the stakes are "we might prevent a valid installation of Visual Studio from being used," and there is no benefit to be had, this flag should not be set.
More research to confirm this PR is the right approach: atom/flight-manual.atom.io#630 (comment)
We bundle/use the latest npm (npm 6.14.x), which is more than new enough to pick a Visual Studio installation automatically. |
Windows-build-tools v4 (which is an old unmainteind version) installs Visual Studio 2015. But we can use the pre-installed 2017 in vs2017-win2016 Requires atom/apm#892
Windows-build-tools v4 (which is an old unmaintaind version) installs Visual Studio 2015. But we can use the pre-installed 2017 in vs2017-win2016 Requires atom/apm#892
I created a PR for atom which depends on this. |
@sadick254 @darangi Will this ever be merged? I was interested in improving superstring, but it is not worth it without using std=C++17. |
I hope this helps with reviewing this Pull Request; To summarize what this Pull Request does, here is the behavior before and after: Before:
(This behavior was helpful way back years ago, with what are now very old versions of With this PR:
|
In Azure Pipelines CI, there are copies of multiple Visual Studio installs, but not all of them are usable. Particularly, there is an unusable (for building Atom) partial install of Visual Studio 2015. This PR makes it possible to use Visual Studio 2017 instead. Otherwise, apm will see the partial VS2015 install and force Visual Studio 2015. That errors out, since the VS2015 install is missing some components. Please consider merging this PR so it is convenient to test with Visual Studio 2017 or 2019 in Atom's CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me @DeeDeeG. Thanks for all the investigation work. This really helps us do quicker reviews.
Thank you for merging! This is one of the contributions to |
Windows-build-tools v4 (which is an old unmaintaind version) installs Visual Studio 2015. But we can use the pre-installed 2017 in vs2017-win2016 Requires atom/apm#892
Mostly removing this because it has been erroring out in CI. We already get the latest version of Visual Studio from GitHub Actions' Windows base image. (We used to need to manually install an older version of Visual Studio, but we no-longer need to do that, now that Atom ships a new enough version of apm with atom/apm#892 included. That PR gives apm better support for multiple Visual Studio installs on a given system, better handling of newer versions (2017+) of VS.)
Windows-build-tools v4 (which is an old unmaintaind version) installs Visual Studio 2015. But we can use the pre-installed 2017 in vs2017-win2016 Requires atom/apm#892 (cherry picked from commit 8dd9901)
Requirements
Description of the Change
Main change:
Related changes:
--msvs_version
node-gyp flag, which sets a specific version of Visual Studio that node-gyp must find, or else it will error out.Explanation (click to expand):
Builds on
apm
's existing code to detect installs of Visual Studio, by adding the ability to detect Visual Studio 2017 and 2019.Those versions of Visual Studio are now fully supported in the version of node-gyp we use (node-gyp@5).
As of node-gyp PR nodejs/node-gyp#1762, node-gyp is much better than us at finding Visual Studio installs and identifying whether on not they can be used. This isn't a simple matter of having Visual Studio or not, but also various components must be installed.
Given that our detection is worse, I have made it so
apm
no-longer sets the--msvs_version
flag. This flag forces node-gyp to use the specified major version of Visual Studio/Build Tools. It can only restrict node-gyp within usable installs. There is no scenario where setting this causes any benefit to us. But if we get it wrong (and our detection is worse, so we very likely would), this can cause node-gyp to refuse to use a valid Visual Studio/Build Tools install and error out.Alternate Designs
This, but with some of the changes reverted/taken out.
All commits in this PR are designed to be logical choices that are well-backed-up by the explanation and reasoning given.
That said, the commits are in order of how radical the change is, or how controversial I thought the change might be. If any of the commits/changes are objectionable, please let me know, and the rest of the PR still makes sense without that change. This is a few related changes bundled together, but any of the three bullet points is a positive step in the right direction, and works independent of the other two bullet points.
Benefits
Possible Drawbacks
None that I am aware of. Before this PR, we have been artificially limiting how good a job node-gyp could do to find Visual Studio, in certain cases. Now, with this PR, we stop doing that.
Reaching for a hypothetical problem: I suppose if Visual Studio 2017 or 2019 are buggy, this exposes our users to that. (In my experience, VS 2017 and 2019 are not buggy.)
Verification Process
Lengthy "Verification Process" section contents (click to expand):
This un-blocks
apm
from using a correctly-detected, working install of Visual Studio 2019 in (forked) Atom's CI.Breakdown of the "Before" case: The issue in this case was that
apm
detected an install of 2015 that turned out to be unusable. The error is: "could not find MSBuild in registry for this version
". At the bottom of the error message, a message points out that 2019 would have been a valid version, had we allowed node-gyp to use it:Furthermore,
apm --version
can now find Visual Studio 2017 and 2019.Before and after on the same machine, with Visual Studio 2019 Community installed:
Before:
After:
Note that Visual Studio 2019 is detected:
visual studio 2019
(on the bottom line of output fromapm --version
).Here's the before and after on another machine, this time with Visual Studio 2017:
Before
After
Note that Visual Studio 2017 is detected:
visual studio 2017
(on the bottom line of output fromapm --version
).Applicable Issues
Fixes #893