Building Electron From Scratch

Last night I started a journey to build Electron completely from the ground up, for investigating a subtle issue in VSCode.

The journey appears as a really painful challenge for my disk storage as well as network condition. It has downloaded around 30 GiB contents from the Internet, and occupied 55 GiB of storage space on the disk after the binary file was fully compiled. I will suggest anyone to go through this journey should place his workspace on an SSD, and adopt a network proxy of good quality if in China.

Albeit it occupies a bunch of resources greedily, the Electron team provides a command line tool e (Electron build-tools) to hopefully simplify the building process. The guidance leading to this tool, however, is not obvious enough on the doc page. I’ve wasted two or three hours following the instructions in the doc that explicitly invokes gclient or gn or ninja, which yet resulted in a bunch of errors and a hell of mess. So here’s the first advice – DO NOT follow any instructions after section “GN files” in this page. Just go ahead to use Electron build-tools!

Things become easier once you’ve learned the existence of Electron build-tools. To install the tool you only have to type one command

$ npm i -g @electron/build-tools

This package manages for you all the necessary stuffs to build Electron, including Depot Tools for source code management and Rust/clang toolchains for building, which are exposed as a single command e. To fetch the source code and build Electron in one go, you need to run

$ # you'd better add this to .bashrc
$ export GIT_CACHE_PATH="/path/to/git-cache"
$ mkdir -p $GIT_CACHE_PATH
$ # tell depot_tools not to update itself
$ # setup network proxy if necessary
$ export http_proxy=... https_proxy=...
$ # go to your workspace
$ mkdir -p $WORKSPACE && cd $WORKSPACE
$ # fetch and build Electron!
$ e init --root=$PWD --bootstrap testing --fork hsfzxjy/electron --goma none

Some notes on these command:

  1. depot_tools respect the environment variable GIT_CACHE_PATH to cache up git database for all fetched dependencies. The variable is highly recommended to set as it could significantly speed up file synchronization next time.
  2. depot_tools will automatically check updates for itself and I don’t like it. Disable this behavior via DEPOT_TOOLS_UPDATE=0.
  3. depot_tools respect the http_proxy and https_proxy for network proxy, but proxychains might fail wierdly.
  4. The flag --goma none is necessary if you build Electron on your personal computer without using distributed building facility like Goma. Otherwise the building process will emit errors in the middle.

Author: hsfzxjy.
Link: .
License: CC BY-NC-ND 4.0.
All rights reserved by the author.
Commercial use of this post in any form is NOT permitted.
Non-commercial use of this post should be attributed with this block of text.



A comment box should be right here...But it was gone due to network issues :-(If you want to leave comments, make sure you have access to