构建说明(macOS)¶
请按照以下指南在 macOS 上构建 Electron 本身,以创建自定义 Electron 二进制文件。有关使用预构建的 Electron 二进制文件打包和分发应用代码的信息,请参阅应用程序分发指南。
先决条件¶
- macOS >= 12
- Xcode。所需的确切版本取决于您构建的分支,但最新版本的 Xcode 通常对构建
main分支是比较稳妥的选择。 - Python >= 3.9
- Node.js >= 22.12.0
Arm64 特定先决条件¶
- Rosetta 2
- 如果使用需要在 x64 和 arm64 机器上进行交叉编译的依赖项,我们建议安装 Rosetta。可以通过 softwareupdate 命令行工具安装 Rosetta。
$ softwareupdate --install-rosetta
构建 Electron¶
参见 构建说明:GN。
故障排除¶
Xcode “incompatible architecture” 错误(MacOS arm64 特定)¶
如果同时安装了 Xcode 和 Xcode 命令行工具($ xcode -select --install,或直接在此处下载正确版本),但堆栈跟踪信息却显示类似以下内容:
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 版本。
证书验证失败¶
安装 certifi 可以修复以下错误:
________ 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 仓库中记录,见此处。有关此问题的更多信息,请参见此处和此处。
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 el/electron