构建说明 (Linux)
¥Build Instructions (Linux)
请遵循以下指南在 Linux 上构建 Electron 本身,以创建自定义 Electron 二进制文件。要使用预构建的 Electron 二进制文件打包和分发应用代码,请参阅 应用分发 指南。
¥Follow the guidelines below for building Electron itself on Linux, 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
-
至少 25GB 磁盘空间和 8GB RAM。
¥At least 25GB disk space and 8GB RAM.
-
Python >= 3.7。
-
Node.js。安装 Node.js 有多种方法。你可以从 nodejs.org 下载源代码并编译。这样做允许以标准用户身份在你自己的主目录中安装 Node。或者尝试诸如 NodeSource 之类的存储库。
¥Node.js. There are various ways to install Node. You can download source code from nodejs.org and compile it. Doing so permits installing Node on your own home directory as a standard user. Or try repositories such as NodeSource.
-
clang 3.4 或更高版本。
¥clang 3.4 or later.
-
GTK 3 和 libnotify 的开发头文件。
¥Development headers of GTK 3 and libnotify.
在 Ubuntu >= 20.04 上,安装以下库:
¥On Ubuntu >= 20.04, install the following libraries:
$ sudo apt-get install build-essential clang libdbus-1-dev libgtk-3-dev \
libnotify-dev libasound2-dev libcap-dev \
libcups2-dev libxtst-dev \
libxss1 libnss3-dev gcc-multilib g++-multilib curl \
gperf bison python3-dbusmock openjdk-8-jre
在 Ubuntu < 20.04 上,安装以下库:
¥On Ubuntu < 20.04, install the following libraries:
$ sudo apt-get install build-essential clang libdbus-1-dev libgtk-3-dev \
libnotify-dev libgnome-keyring-dev \
libasound2-dev libcap-dev libcups2-dev libxtst-dev \
libxss1 libnss3-dev gcc-multilib g++-multilib curl \
gperf bison python-dbusmock openjdk-8-jre
在 RHEL/CentOS 上,安装以下库:
¥On RHEL / CentOS, install the following libraries:
$ sudo yum install clang dbus-devel gtk3-devel libnotify-devel \
libgnome-keyring-devel xorg-x11-server-utils libcap-devel \
cups-devel libXtst-devel alsa-lib-devel libXrandr-devel \
nss-devel python-dbusmock openjdk-8-jre
在 Fedora 上,安装以下库:
¥On Fedora, install the following libraries:
$ sudo dnf install clang dbus-devel gperf gtk3-devel \
libnotify-devel libgnome-keyring-devel libcap-devel \
cups-devel libXtst-devel alsa-lib-devel libXrandr-devel \
nss-devel python-dbusmock
在 Arch Linux / Manjaro 上,安装以下库:
¥On Arch Linux / Manjaro, install the following libraries:
$ sudo pacman -Syu base-devel clang libdbus gtk2 libnotify \
libgnome-keyring alsa-lib libcap libcups libxtst \
libxss nss gcc-multilib curl gperf bison \
python2 python-dbusmock jdk8-openjdk
其他发行版可能会提供类似的软件包,以便通过软件包管理器(例如 pacman)进行安装。或者可以从源代码编译。
¥Other distributions may offer similar packages for installation via package managers such as pacman. Or one can compile from source code.
交叉编译
¥Cross compilation
如果你想构建 arm
目标,你还应该安装以下依赖:
¥If you want to build for an arm
target you should also install the following
dependencies:
$ sudo apt-get install libc6-dev-armhf-cross linux-libc-dev-armhf-cross \
g++-arm-linux-gnueabihf
同样,对于 arm64
,安装以下内容:
¥Similarly for arm64
, install the following:
$ sudo apt-get install libc6-dev-arm64-cross linux-libc-dev-arm64-cross \
g++-aarch64-linux-gnu
要对 arm
或目标进行交叉编译,你应该将 target_cpu
参数传递给 gn gen
:
¥And to cross-compile for arm
or targets, you should pass the
target_cpu
parameter to gn gen
:
$ gn gen out/Testing --args='import(...) target_cpu="arm"'
架构
¥Building
见 构建说明:GN
故障排除
¥Troubleshooting
加载共享库时出错:libtinfo.so.5
¥Error While Loading Shared Libraries: libtinfo.so.5
预建的 clang
将尝试链接到 libtinfo.so.5
。根据主机架构,符号链接到适当的 libncurses
:
¥Prebuilt clang
will try to link to libtinfo.so.5
. Depending on the host
architecture, symlink to appropriate libncurses
:
$ sudo ln -s /usr/lib/libncurses.so.5 /usr/lib/libtinfo.so.5
高级主题
¥Advanced topics
默认构建配置针对主要桌面 Linux 发行版。要针对特定发行版或设备进行构建,以下信息可能会对你有所帮助。
¥The default building configuration is targeted for major desktop Linux distributions. To build for a specific distribution or device, the following information may help you.
使用系统 clang
而不是下载的 clang
二进制文件
¥Using system clang
instead of downloaded clang
binaries
默认情况下,Electron 是使用 Chromium 项目提供的预构建 clang
二进制文件构建的。如果出于某种原因你想要使用系统中安装的 clang
进行构建,你可以在 GN args 中指定 clang_base_path
参数。
¥By default Electron is built with prebuilt
clang
binaries provided by the
Chromium project. If for some reason you want to build with the clang
installed in your system, you can specify the clang_base_path
argument in the
GN args.
例如,如果你在 /usr/local/bin/clang
下安装了 clang
:
¥For example if you installed clang
under /usr/local/bin/clang
:
$ gn gen out/Testing --args='import("//electron/build/args/testing.gn") clang_base_path = "/usr/local/bin"'
使用 clang
以外的编译器
¥Using compilers other than clang
不支持使用 clang
以外的编译器构建 Electron。
¥Building Electron with compilers other than clang
is not supported.