Windows on ARM
If your app doesn’t use any native modules, then it’s really easy to create an Arm version of your app.
- Make sure that your app’s
node_modules
directory is empty. - Using a Command Prompt, run
set npm_config_arch=arm64
before runningnpm install
/yarn install
as usual. - If you have Electron installed as a development dependency, npm will download and unpack the arm64 version. You can then package and distribute your app as normal.
General considerations
Lots of Windows-specific code contains if… else logic that selects between either the x64 or x86 architectures.
If you want to target arm64, logic like this will typically select the wrong architecture, so carefully check your application and build scripts for conditions like this. In custom build and packaging scripts, you should always check the value of npm_config_arch
in the environment, rather than relying on the current process arch.
Native modules
If you use native modules, you must make sure that they compile against v142 of the MSVC compiler (provided in Visual Studio 2017). You must also check that any pre-built .dll
or .lib
files provided or referenced by the native module are available for Windows on Arm.
Node.js/node-gyp
Node.js v12.9.0 or later is recommended. If updating to a new version of Node is undesirable, you can instead to version 5.0.2 or later, which contains the required changes to compile native modules for Arm.
Visual Studio 2017 (any edition) is required for cross-compiling native modules. You can download Visual Studio Community 2017 via Microsoft’s Visual Studio Dev Essentials program. After installation, you can add the Arm-specific components by running the following from a Command Prompt:
Creating a cross-compilation command prompt
Setting in the environment creates the correct arm64 .obj
files, but the standard Developer Command Prompt for VS 2017 will use the x64 linker. To fix this:
- Duplicate the x64_x86 Cross Tools Command Prompt for VS 2017 shortcut (e.g. by locating it in the start menu, right clicking, selecting Open File Location, copying and pasting) to somewhere convenient.
- Change the Target field to read
vcvarsamd64_arm64.bat
at the end instead ofvcvarsamd64_x86.bat
.
If done successfully, the command prompt should print something similar to this on startup:
Linking against the correct node.lib
By default, node-gyp
unpacks Electron’s node headers and downloads the x86 and x64 versions of node.lib
into , but it does not download the arm64 version (.) To fix this:
- Download the arm64
node.lib
from https://electronjs.org/headers/v6.0.9/win-arm64/node.lib - Move it to
%APPDATA%\..\Local\node-gyp\Cache\6.0.9\arm64\node.lib
Substitute 6.0.9
for the version you’re using.
Cross-compiling native modules
After completing all of the above, open your cross-compilation command prompt and run set npm_config_arch=arm64
. Then use npm install
to build your project as normal. As with cross-compiling x86 modules, you may need to remove node_modules
to force recompilation of native modules if they were previously compiled for another architecture.
Debugging native modules can be done with Visual Studio 2017 (running on your development machine) and corresponding Visual Studio Remote Debugger running on the target device. To debug:
- Launch your app
.exe
on the target device via the Command Prompt (passing to pause it before any native modules are loaded). - Launch Visual Studio 2017 on your development machine.
- Connect to the target device by selecting Debug > Attach to Process… and enter the device’s IP address and the port number displayed by the Visual Studio Remote Debugger tool.
- Click Refresh and select the .
- You may need to make sure that any symbols for native modules in your app are loaded correctly. To configure this, head to Debug > Options… in Visual Studio 2017, and add the folders containing your
.pdb
symbols under Debugging > Symbols.