Skip to main content

Windows on ARM

If your app runs with Electron 6.0.8 or later, you can now build it for Windows 10 on Arm. 如果您的应用程序运行Electron 6.0.8或更高版本,您现在可以在Arm上为Windows 10构建它。This considerably improves performance, but requires recompilation of any native modules used in your app. 这大大提高了性能,但需要重新编译应用程序中使用的任何本机模块。It may also require small fixups to your build and packaging scripts.它还可能需要对构建和打包脚本进行小的修正。

Running a basic app运行基本应用程序

If your app doesn't use any native modules, then it's really easy to create an Arm version of your app.如果您的应用程序不使用任何本机模块,那么创建应用程序的Arm版本非常容易。

  1. Make sure that your app's node_modules directory is empty.确保应用程序的node_modules目录为空。
  2. Using a Command Prompt, run set npm_config_arch=arm64 before running npm install/yarn install as usual.使用命令提示符,在正常运行npm install/yarn install之前,运行set npm_config_arch=arm64
  3. If you have Electron installed as a development dependency如果作为开发依赖项安装了Electron, npm will download and unpack the arm64 version. ,npm将下载并解包arm64版本。You can then package and distribute your app as normal.然后,您可以正常打包和分发应用程序。

General considerations一般考虑

Architecture-specific code体系结构特定代码

Lots of Windows-specific code contains if... else logic that selects between either the x64 or x86 architectures.许多特定于Windows的代码包含在x64或x86架构之间进行选择的if…else逻辑。

if (process.arch === 'x64') {
// Do 64-bit thing...
} else {
// Do 32-bit thing...
}

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. 如果您想以arm64为目标,这样的逻辑通常会选择错误的体系结构,因此请仔细检查您的应用程序并构建脚本以了解类似情况。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.在自定义构建和打包脚本中,您应该始终检查环境中npm_config_arch的值,而不是依赖于当前的进程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). 如果使用本机模块,则必须确保它们是根据MSVC编译器的v142(在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.您还必须检查本机模块提供或引用的任何预构建.dll.lib文件是否适用于Arm上的Windows。

Testing your app测试您的应用程序

To test your app, use a Windows on Arm device running Windows 10 (version 1903 or later). 要测试应用程序,请使用运行Windows 10(版本1903或更高版本)的Windows on-Arm设备。Make sure that you copy your application over to the target device - Chromium's sandbox will not work correctly when loading your application assets from a network location.确保将应用程序复制到目标设备-当从网络位置加载应用程序资产时,Chromium的沙盒将无法正常工作。

Development prerequisites开发先决条件

Node.js/node-gyp

Node.js v12.9.0 or later is recommended.建议使用Node.js v12.9.0或更高版本。 If updating to a new version of Node is undesirable, you can instead update npm's copy of node-gyp manually to version 5.0.2 or later, which contains the required changes to compile native modules for Arm.如果不希望更新到节点的新版本,则可以手动将npm的节点gyp副本更新到版本5.0.2或更高版本,其中包含编译Arm本机模块所需的更改。

Visual Studio 2017

Visual Studio 2017 (any edition) is required for cross-compiling native modules. 交叉编译本机模块需要Visual Studio 2017(任何版本)。You can download Visual Studio Community 2017 via Microsoft's Visual Studio Dev Essentials program. 您可以通过Microsoft的Visual Studio Dev Essentials程序下载Visual Studio Community 2017。After installation, you can add the Arm-specific components by running the following from a Command Prompt:安装后,您可以通过从命令提示符运行以下命令来添加特定于Arm的组件:

vs_installer.exe ^
--add Microsoft.VisualStudio.Workload.NativeDesktop ^
--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^
--add Microsoft.VisualStudio.Component.VC.MFC.ARM64 ^
--includeRecommended

Creating a cross-compilation command prompt创建交叉编译命令提示符

Setting npm_config_arch=arm64 in the environment creates the correct arm64 .obj files, but the standard Developer Command Prompt for VS 2017 will use the x64 linker. 在环境中设置npm_config_arch=arm64将创建正确的arm64 .obj文件,但VS2017的标准开发人员命令提示符将使用x64链接器。To fix this:要解决此问题:

  1. 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.将VS 2017快捷方式的x64_x86交叉工具命令提示符复制到方便的位置(例如,在开始菜单中定位,右键单击,选择打开文件位置,复制和粘贴)。
  2. Right click the new shortcut and choose Properties.右键单击新快捷方式并选择“属性”。
  3. Change the Target field to read vcvarsamd64_arm64.bat at the end instead of vcvarsamd64_x86.bat.将目标字段更改为在末尾读取vcvarsamd64_arm64.bat,而不是vcvarsamd64_x86.bat

If done successfully, the command prompt should print something similar to this on startup:如果成功完成,命令提示符应在启动时打印类似的内容:

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.15
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64_arm64'

If you want to develop your application directly on a Windows on Arm device, substitute vcvarsx86_arm64.bat in Target so that cross-compilation can happen with the device's x86 emulation.如果您想直接在Windows on Arm设备上开发应用程序,请在目标中替换vcvarsx86_arm64.bat,以便可以在设备的x86仿真中进行交叉编译。

Linking against the correct node.lib链接到正确的node.lib

By default, node-gyp unpacks Electron's node headers and downloads the x86 and x64 versions of node.lib into %APPDATA%\..\Local\node-gyp\Cache, but it does not download the arm64 version (a fix for this is in development.) 默认情况下,node-gyp解包Electron的node头并将x86和x64版本的node.lib下载到%APPDATA%\..\Local\node-gyp\Cache中,但不下载arm64版本(正在开发修复程序To fix this:要解决此问题:

  1. Download the arm64 node.lib from https://electronjs.org/headers/v6.0.9/win-arm64/node.lib
  2. Move it to %APPDATA%\..\Local\node-gyp\Cache\6.0.9\arm64\node.lib

Substitute 6.0.9 for the version you're using.6.0.9替换您正在使用的版本。

Cross-compiling native modules交叉编译原生模块

After completing all of the above, open your cross-compilation command prompt and run set npm_config_arch=arm64. 完成以上所有操作后,打开交叉编译命令提示符并运行set npm_config_arch=arm64Then use npm install to build your project as normal. 然后使用npm install正常构建项目。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.与交叉编译x86模块一样,您可能需要删除node_modules,以强制重新编译本机模块(如果它们以前是为其他体系结构编译的)。

Debugging native modules调试原生模块

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. 可以使用Visual Studio 2017(在开发机器上运行)和目标设备上运行的相应Visual Studio远程调试器来调试本机模块。To debug:若要调试:

  1. Launch your app .exe on the target device via the Command Prompt (passing --inspect-brk to pause it before any native modules are loaded).通过命令提示符在目标设备上启动应用程序.exe(传递--inspect-brk以在加载任何原生模块之前暂停它)。
  2. Launch Visual Studio 2017 on your development machine.在您的开发机器上启动Visual Studio 2017。
  3. 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.通过选择调试>附加到进程…连接到目标设备,并输入设备的IP地址和Visual Studio远程调试器工具显示的端口号。
  4. Click Refresh and select the appropriate Electron process to attach.单击刷新并选择要连接的适当Electron进程
  5. 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.要对此进行配置,请转到Visual Studio 2017中的调试>选项…并在调试>符号下添加包含.pdb符号的文件夹。
  6. Once attached, set any appropriate breakpoints and resume JavaScript execution using Chrome's remote tools for Node.连接后,设置适当的断点,并使用Chrome的远程节点工具恢复JavaScript执行。

Getting additional help获得额外帮助

If you encounter a problem with this documentation, or if your app works when compiled for x86 but not for arm64, please file an issue with "Windows on Arm" in the title.如果您在本文档中遇到问题,或者如果您的应用程序在为x86而不是arm64编译时工作,请在标题中使用“Windows on Arm”提交问题