使用 GN 构建 Electron
Electron 现在使用 GN 来构建自身。以下是关于原因的讨论。
🌐 Electron now uses GN to build itself. Here's a discussion of why.
GYP 和 GN
🌐 GYP and GN
当 Electron 于 2013 年首次发布时,Chromium 的构建配置是用 GYP 编写的,GYP 是“生成你的项目”的缩写。
🌐 When Electron was first released in 2013, Chromium's build configuration was written with GYP, short for "Generate Your Projects".
2014年,Chromium 项目引入了一种新的构建配置工具,名为 GN(“Generate Ninja” 的缩写)。Chromium 的构建文件被迁移到 GN,GYP 从源代码中被移除。
🌐 In 2014, the Chromium project introduced a new build configuration tool called GN (short for "Generate Ninja") Chromium's build files were migrated to GN and GYP was removed from the source code.
Electron 历来将主 [Electron 代码] 与 libchromiumcontent 分开,后者是 Electron 中封装 Chromium 'content' 子模块的部分。Electron 一直使用 GYP,而 libchromiumcontent 作为 Chromium 的一个子集,则在 Chromium 切换到 GN 时也进行了切换。
🌐 Electron has historically kept a separation between the main Electron code and libchromiumcontent, the part of Electron that wraps Chromium's 'content' submodule. Electron has carried on using GYP, while libchromiumcontent -- as a subset of Chromium -- switched to GN when Chromium did.
就像啮合不完全的齿轮一样,使用这两种构建系统之间存在摩擦。保持兼容性容易出错,从编译器标志到 #defines,都需要在 Chromium、Node、V8 和 Electron 之间仔细同步。
🌐 Like gears that don't quite mesh, there was friction between using the two build systems. Maintaining compatibility was error-prone, from compiler flags and #defines that needed to be meticulously kept in sync between Chromium, Node, V8, and Electron.
为了解决这个问题,Electron 团队一直在努力将所有内容迁移到 GN。今天,删除 Electron 中最后一部分 GYP 代码的提交 已经合并到主分支。
🌐 To address this, the Electron team has been working on moving everything to GN. Today, the commit to remove the last of the GYP code from Electron was landed in master.
这对你意味着什么
🌐 What this means for you
如果你正在为 Electron 本身做贡献,从 master 或 4.0.0 检出并构建 Electron 的进程与 3.0.0 及更早版本有很大不同。详情请参阅GN 构建说明。
🌐 If you're contributing to Electron itself, the process of checking out and building Electron from master or 4.0.0 is very different than it was in 3.0.0 and earlier. See the GN build instructions for details.
如果你正在使用 Electron 开发应用,你可能会注意到在新的 Electron 4.0.0-nightly 版本中有一些小的变化;但更有可能的是,Electron 在构建系统上的变化对你来说是完全透明的。
🌐 If you're developing an app with Electron, there are a few minor changes you might notice in the new Electron 4.0.0-nightly; but more than likely, Electron's change in build system will be totally transparent to you.
这对 Electron 意味着什么
🌐 What this means for Electron
GN 比 GYP 更快,其生成的文件也更易读且更易维护。此外,我们希望使用单一的构建配置系统能够减少将 Electron 升级到新版本 Chromium 所需的工作量。
🌐 GN is faster than GYP and its files are more readable and maintainable. Moreover, we hope that using a single build configuration system will reduce the work required to upgrade Electron to new versions of Chromium.