Skip to content

Commit

Permalink
feat: add support for native windows arm64 build tools
Browse files Browse the repository at this point in the history
Visual Studio 2022 17.4 adds a native C++ compiler for Windows on ARM.
This allows arm64 devices to leverage native build tools, leading to
a 35% (or more) speed increase.
https://devblogs.microsoft.com/visualstudio/arm64-visual-studio-is-officially-here/

Signed-off-by: Dennis Ameling <dennis@dennisameling.com>
  • Loading branch information
dennisameling authored and StefanStojanovic committed May 25, 2023
1 parent 6f3c2d3 commit bb76021
Show file tree
Hide file tree
Showing 4 changed files with 646 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -56,7 +56,9 @@ Install tools and configuration manually:

If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips.

To target native ARM64 Node.js on Windows 10 on ARM, add the components "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64".
To target native ARM64 Node.js on Windows on ARM, add the components "Visual C++ compilers and libraries for ARM64" and "Visual C++ ATL for ARM64".

To use the native ARM64 C++ compiler on Windows on ARM, ensure that you have Visual Studio 2022 [17.4 or later](https://devblogs.microsoft.com/visualstudio/arm64-visual-studio-is-officially-here/) installed.

### Configuring Python Dependency

Expand Down
15 changes: 13 additions & 2 deletions lib/find-visualstudio.js
Expand Up @@ -266,10 +266,15 @@ VisualStudioFinder.prototype = {
return {}
},

msBuildPathExists: function msBuildPathExists (path) {
return fs.existsSync(path)
},

// Helper - process MSBuild information
getMSBuild: function getMSBuild (info, versionYear) {
const pkg = 'Microsoft.VisualStudio.VC.MSBuild.Base'
const msbuildPath = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'MSBuild.exe')
const msbuildPathArm64 = path.join(info.path, 'MSBuild', 'Current', 'Bin', 'arm64', 'MSBuild.exe')
if (info.packages.indexOf(pkg) !== -1) {
this.log.silly('- found VC.MSBuild.Base')
if (versionYear === 2017) {
Expand All @@ -279,8 +284,14 @@ VisualStudioFinder.prototype = {
return msbuildPath
}
}
// visual studio 2022 don't has msbuild pkg
if (fs.existsSync(msbuildPath)) {
/**
* Visual Studio 2022 doesn't have the MSBuild package.
* Support for compiling _on_ ARM64 was added in MSVC 14.32.31326,
* so let's leverage it if the user has an ARM64 device.
*/
if (process.arch === 'arm64' && this.msBuildPathExists(msbuildPathArm64)) {
return msbuildPathArm64
} else if (this.msBuildPathExists(msbuildPath)) {
return msbuildPath
}
return null
Expand Down

0 comments on commit bb76021

Please sign in to comment.