构建说明 (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 版本 ≥ 12
- Xcode。所需的确切版本取决于你正在构建的分支,但通常使用最新版本的 Xcode 构建
main是一个不错的选择。 - Python >= 3.9
- Node.js >= 22.12.0
Arm64 特定的先决条件
🌐 Arm64-specific prerequisites
- 罗塞塔 2 号
- 如果使用需要在 x64 和 arm64 机器上交叉编译的依赖,我们建议安装 Rosetta。可以使用 softwareupdate 命令行工具安装 Rosetta。
$ 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 版本。
证书验证失败
🌐 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 副本有关,而不是使用已弃用的 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.