Skip to main content

构建说明 (macOS)

¥Build Instructions (macOS)

请遵循以下指南在 macOS 上构建 Electron 本身,以创建自定义 Electron 二进制文件。要使用预构建的 Electron 二进制文件打包和分发应用代码,请参阅 应用分发 指南。

¥Follow the guidelines below for building Electron itself on macOS, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the application distribution guide.

先决条件

¥Prerequisites

  • macOS >= 11.6.0

  • Xcode。所需的确切版本取决于你正在构建的分支,但最新版本的 Xcode 通常是构建 main 的不错选择。

    ¥Xcode. The exact version needed depends on what branch you are building, but the latest version of Xcode is generally a good bet for building main.

  • node.js(外部的)

    ¥node.js (external)

  • Python >= 3.7

Arm64 特定的先决条件

¥Arm64-specific prerequisites

  • 罗塞塔 2 号

    ¥Rosetta 2

    • 如果使用需要在 x64 和 arm64 机器上交叉编译的依赖,我们建议安装 Rosetta。Rosetta 可以使用 softwareupdate 命令行工具进行安装。

      ¥We recommend installing Rosetta if using dependencies that need to cross-compile on x64 and arm64 machines. Rosetta can be installed by using the softwareupdate command line tool.

    • $ softwareupdate --install-rosetta

架构 Electron

¥Building Electron

参见 构建说明:GN

¥See Build Instructions: GN.

故障排除

¥Troubleshooting

Xcode "不兼容的架构" 错误(特定于 MacOS arm64)

¥Xcode "incompatible architecture" errors (MacOS arm64-specific)

如果 Xcode 和 Xcode 命令行工具都已安装($ xcode -select --install,或直接下载正确的版本 此处),但堆栈跟踪显示不然,如下所示:

¥If both Xcode and Xcode command line tools are installed ($ xcode -select --install, or directly download the correct version here), but the stack trace says otherwise like so:

xcrun: error: unable to load libxcrun
(dlopen(/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib), 0x0005):
tried: '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode.app/Contents/Developer/usr/lib/libxcrun.dylib)'
(mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))), '/Users/<user>/.electron_build_tools/third_party/Xcode/Xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib (http://xcode-11.1.0.app/Contents/Developer/usr/lib/libxcrun.dylib)' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))).`

如果你使用的是 arm64 架构,构建脚本可能指向错误的 Xcode 版本(11.x.y 不支持 arm64)。导航到 /Users/<user>/.electron_build_tools/third_party/Xcode/ 并将 Xcode-13.3.0.app 重命名为 Xcode.app 以确保使用正确的 Xcode 版本。

¥If you are on arm64 architecture, the build script may be pointing to the wrong Xcode version (11.x.y doesn't support arm64). Navigate to /Users/<user>/.electron_build_tools/third_party/Xcode/ and rename Xcode-13.3.0.app to Xcode.app to ensure the right Xcode version is used.

证书验证失败

¥Certificates fail to verify

安装 certifi 将修复以下错误:

¥installing certifi will fix the following error:

________ running 'python3 src/tools/clang/scripts/update.py' in '/Users/<user>/electron'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 5 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 10 s ...
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Mac_arm64/clang-llvmorg-15-init-15652-g89a99ec9-1.tgz
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Retrying in 20 s ...

此问题与 Python 3.6 使用 OpenSSL 的 own 副本代替已弃用的 Apple 提供的 OpenSSL 库有关。certifi 添加了精选的默认根证书打包包。此问题记录在 Electron 存储库 此处 中。有关此问题的更多信息可以找到 此处此处

¥This issue has to do with Python 3.6 using its own copy of OpenSSL in lieu of the deprecated Apple-supplied OpenSSL libraries. certifi adds a curated bundle of default root certificates. This issue is documented in the Electron repo here. Further information about this issue can be found here and here.