2018-09-09 01:15:32 +00:00
|
|
|
# Build Instructions
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-09-09 01:15:32 +00:00
|
|
|
Follow the guidelines below for building Electron.
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
## Platform prerequisites
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-07-25 14:45:52 +00:00
|
|
|
Check the build prerequisites for your platform before proceeding
|
|
|
|
|
|
|
|
* [macOS](build-instructions-osx.md#prerequisites)
|
|
|
|
* [Linux](build-instructions-linux.md#prerequisites)
|
|
|
|
* [Windows](build-instructions-windows.md#prerequisites)
|
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
## GN prerequisites
|
2018-07-25 14:45:52 +00:00
|
|
|
|
|
|
|
You'll need to install [`depot_tools`][depot-tools], the toolset
|
|
|
|
used for fetching Chromium and its dependencies.
|
|
|
|
|
2018-08-11 17:20:19 +00:00
|
|
|
Also, on Windows, you'll need to set the environment variable
|
|
|
|
`DEPOT_TOOLS_WIN_TOOLCHAIN=0`. To do so, open `Control Panel` → `System and
|
|
|
|
Security` → `System` → `Advanced system settings` and add a system variable
|
|
|
|
`DEPOT_TOOLS_WIN_TOOLCHAIN` with value `0`. This tells `depot_tools` to use
|
|
|
|
your locally installed version of Visual Studio (by default, `depot_tools` will
|
|
|
|
try to download a Google-internal version that only Googlers have access to).
|
2018-05-18 20:04:46 +00:00
|
|
|
|
|
|
|
[depot-tools]: http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
|
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
## Cached builds (optional step)
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-09-10 19:31:41 +00:00
|
|
|
### GIT\_CACHE\_PATH
|
2018-08-17 16:20:20 +00:00
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
If you plan on building Electron more than once, adding a git cache will
|
|
|
|
speed up subsequent calls to `gclient`. To do this, set a `GIT_CACHE_PATH`
|
|
|
|
environment variable:
|
2018-08-17 16:20:20 +00:00
|
|
|
|
|
|
|
```sh
|
2018-08-21 19:40:06 +00:00
|
|
|
$ export GIT_CACHE_PATH="${HOME}/.git_cache"
|
|
|
|
$ mkdir -p "${GIT_CACHE_PATH}"
|
|
|
|
# This will use about 16G.
|
2018-08-17 16:20:20 +00:00
|
|
|
```
|
2018-09-10 19:31:41 +00:00
|
|
|
|
|
|
|
> **NOTE**: the git cache will set the `origin` of the `src/electron`
|
|
|
|
> repository to point to the local cache, instead of the upstream git
|
|
|
|
> repository. This is undesirable when running `git push`—you probably want to
|
|
|
|
> push to github, not your local cache. To fix this, from the `src/electron`
|
|
|
|
> directory, run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ git remote set-url origin https://github.com/electron/electron
|
|
|
|
```
|
2018-08-17 16:20:20 +00:00
|
|
|
|
2018-08-21 19:40:06 +00:00
|
|
|
### sccache
|
|
|
|
|
|
|
|
Thousands of files must be compiled to build Chromium and Electron.
|
|
|
|
You can avoid much of the wait by reusing Electron CI's build output via
|
|
|
|
[sccache](https://github.com/mozilla/sccache). This requires some
|
|
|
|
optional steps (listed below) and these two environment variables:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
export SCCACHE_BUCKET="electronjs-sccache"
|
|
|
|
export SCCACHE_TWO_TIER=true
|
|
|
|
```
|
|
|
|
|
|
|
|
## Getting the code
|
2018-08-17 16:20:20 +00:00
|
|
|
|
2018-05-18 20:04:46 +00:00
|
|
|
```sh
|
|
|
|
$ mkdir electron-gn && cd electron-gn
|
2018-08-11 17:20:19 +00:00
|
|
|
$ gclient config \
|
|
|
|
--name "src/electron" \
|
|
|
|
--unmanaged \
|
|
|
|
https://github.com/electron/electron
|
2018-05-18 20:04:46 +00:00
|
|
|
$ gclient sync --with_branch_heads --with_tags
|
|
|
|
# This will take a while, go get a coffee.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Building
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ cd src
|
|
|
|
$ export CHROMIUM_BUILDTOOLS_PATH=`pwd`/buildtools
|
2018-08-21 19:40:06 +00:00
|
|
|
# this next line is needed only if building with sccache
|
|
|
|
$ export GN_EXTRA_ARGS="${GN_EXTRA_ARGS} cc_wrapper=\"${PWD}/electron/external_binaries/sccache\""
|
2018-09-13 20:46:49 +00:00
|
|
|
$ gn gen out/Debug --args="import(\"//electron/build/args/debug.gn\") $GN_EXTRA_ARGS"
|
2018-05-18 20:04:46 +00:00
|
|
|
```
|
|
|
|
|
2018-09-13 20:46:49 +00:00
|
|
|
This will generate a build directory `out/Debug` under `src/` with
|
|
|
|
debug build configuration. You can replace `Debug` with another name,
|
2018-08-11 17:20:19 +00:00
|
|
|
but it should be a subdirectory of `out`.
|
2018-07-25 14:45:52 +00:00
|
|
|
Also you shouldn't have to run `gn gen` again—if you want to change the
|
2018-09-13 20:46:49 +00:00
|
|
|
build arguments, you can run `gn args out/Debug` to bring up an editor.
|
2018-07-25 14:45:52 +00:00
|
|
|
|
2018-08-11 17:20:19 +00:00
|
|
|
To see the list of available build configuration options, run `gn args
|
2018-09-13 20:46:49 +00:00
|
|
|
out/Debug --list`.
|
2018-08-11 17:20:19 +00:00
|
|
|
|
|
|
|
**For generating Debug (aka "component" or "shared") build config of
|
|
|
|
Electron:**
|
2018-07-25 14:45:52 +00:00
|
|
|
|
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ gn gen out/Debug --args="import(\"//electron/build/args/debug.gn\") $GN_EXTRA_ARGS"
|
2018-07-25 14:45:52 +00:00
|
|
|
```
|
|
|
|
|
2018-08-11 17:20:19 +00:00
|
|
|
**For generating Release (aka "non-component" or "static") build config of
|
|
|
|
Electron:**
|
2018-07-25 14:45:52 +00:00
|
|
|
|
|
|
|
```sh
|
2018-09-24 16:12:16 +00:00
|
|
|
$ gn gen out/Release --args="import(\"//electron/build/args/release.gn\") $GN_EXTRA_ARGS"
|
2018-07-25 14:45:52 +00:00
|
|
|
```
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-09-13 20:46:49 +00:00
|
|
|
**To build, run `ninja` with the `electron` target:**
|
2018-09-24 16:12:16 +00:00
|
|
|
Nota Bene: This will also take a while and probably heat up your lap.
|
2018-05-18 20:04:46 +00:00
|
|
|
|
2018-09-24 16:12:16 +00:00
|
|
|
For the debug configuration:
|
2018-05-18 20:04:46 +00:00
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ninja -C out/Debug electron
|
2018-09-24 16:12:16 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For the release configuration:
|
|
|
|
```sh
|
|
|
|
$ ninja -C out/Release electron
|
2018-05-18 20:04:46 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
This will build all of what was previously 'libchromiumcontent' (i.e. the
|
|
|
|
`content/` directory of `chromium` and its dependencies, incl. WebKit and V8),
|
|
|
|
so it will take a while.
|
|
|
|
|
|
|
|
To speed up subsequent builds, you can use [sccache][sccache]. Add the GN arg
|
2018-09-13 20:46:49 +00:00
|
|
|
`cc_wrapper = "sccache"` by running `gn args out/Debug` to bring up an
|
2018-08-11 17:20:19 +00:00
|
|
|
editor and adding a line to the end of the file.
|
2018-05-18 20:04:46 +00:00
|
|
|
|
|
|
|
[sccache]: https://github.com/mozilla/sccache
|
|
|
|
|
2018-09-13 20:46:49 +00:00
|
|
|
The built executable will be under `./out/Debug`:
|
2018-05-18 20:04:46 +00:00
|
|
|
|
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/Electron.app/Contents/MacOS/Electron
|
2018-08-11 17:20:19 +00:00
|
|
|
# or, on Windows
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/electron.exe
|
2018-05-18 20:04:46 +00:00
|
|
|
# or, on Linux
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/electron
|
2018-05-18 20:04:46 +00:00
|
|
|
```
|
|
|
|
|
2018-07-19 23:57:54 +00:00
|
|
|
### Cross-compiling
|
|
|
|
|
|
|
|
To compile for a platform that isn't the same as the one you're building on,
|
2018-08-11 17:20:19 +00:00
|
|
|
set the `target_cpu` and `target_os` GN arguments. For example, to compile an
|
|
|
|
x86 target from an x64 host, specify `target_cpu = "x86"` in `gn args`.
|
2018-07-19 23:57:54 +00:00
|
|
|
|
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ gn gen out/Debug-x86 --args='... target_cpu = "x86"'
|
2018-07-19 23:57:54 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Not all combinations of source and target CPU/OS are supported by Chromium.
|
2018-08-11 17:20:19 +00:00
|
|
|
Only cross-compiling Windows 32-bit from Windows 64-bit and Linux 32-bit from
|
|
|
|
Linux 64-bit have been tested in Electron. If you test other combinations and
|
|
|
|
find them to work, please update this document :)
|
|
|
|
|
|
|
|
See the GN reference for allowable values of [`target_os`][target_os values]
|
|
|
|
and [`target_cpu`][target_cpu values]
|
|
|
|
|
|
|
|
[target_os values]: https://gn.googlesource.com/gn/+/master/docs/reference.md#built_in-predefined-variables-target_os_the-desired-operating-system-for-the-build-possible-values
|
|
|
|
[target_cpu values]: https://gn.googlesource.com/gn/+/master/docs/reference.md#built_in-predefined-variables-target_cpu_the-desired-cpu-architecture-for-the-build-possible-values
|
2018-07-19 23:57:54 +00:00
|
|
|
|
2018-05-18 20:04:46 +00:00
|
|
|
## Tests
|
|
|
|
|
|
|
|
To run the tests, you'll first need to build the test modules against the
|
2018-07-25 14:45:52 +00:00
|
|
|
same version of Node.js that was built as part of the build process. To
|
|
|
|
generate build headers for the modules to compile against, run the following
|
|
|
|
under `src/` directory.
|
2018-05-18 20:04:46 +00:00
|
|
|
|
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ninja -C out/Debug third_party/electron_node:headers
|
2018-07-25 14:45:52 +00:00
|
|
|
# Install the test modules with the generated headers
|
2018-09-13 20:46:49 +00:00
|
|
|
$ (cd electron/spec && npm i --nodedir=../../out/Debug/gen/node_headers)
|
2018-05-18 20:04:46 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Then, run Electron with `electron/spec` as the argument:
|
|
|
|
|
|
|
|
```sh
|
2018-08-11 17:20:19 +00:00
|
|
|
# on Mac:
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/Electron.app/Contents/MacOS/Electron electron/spec
|
2018-08-11 17:20:19 +00:00
|
|
|
# on Windows:
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/electron.exe electron/spec
|
2018-08-11 17:20:19 +00:00
|
|
|
# on Linux:
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/electron electron/spec
|
2018-05-18 20:04:46 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
If you're debugging something, it can be helpful to pass some extra flags to
|
|
|
|
the Electron binary:
|
|
|
|
|
|
|
|
```sh
|
2018-09-13 20:46:49 +00:00
|
|
|
$ ./out/Debug/Electron.app/Contents/MacOS/Electron electron/spec \
|
2018-05-18 20:04:46 +00:00
|
|
|
--ci --enable-logging -g 'BrowserWindow module'
|
|
|
|
```
|
2018-09-12 02:06:55 +00:00
|
|
|
|
|
|
|
## Sharing the git cache between multiple machines
|
|
|
|
|
|
|
|
It is possible to share the gclient git cache with other machines by exporting it as
|
|
|
|
SMB share on linux, but only one process/machine can be using the cache at a
|
|
|
|
time. The locks created by git-cache script will try to prevent this, but it may
|
|
|
|
not work perfectly in a network.
|
|
|
|
|
|
|
|
On Windows, SMBv2 has a directory cache that will cause problems with the git
|
|
|
|
cache script, so it is necessary to disable it by setting the registry key
|
|
|
|
|
|
|
|
```sh
|
|
|
|
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Lanmanworkstation\Parameters\DirectoryCacheLifetime
|
|
|
|
```
|
|
|
|
|
|
|
|
to 0. More information: https://stackoverflow.com/a/9935126
|
|
|
|
|
|
|
|
## Troubleshooting
|
|
|
|
|
|
|
|
### Stale locks in the git cache
|
|
|
|
If `gclient sync` is interrupted while using the git cache, it will leave
|
|
|
|
the cache locked. To remove the lock, pass the `--break_repo_locks` argument to
|
|
|
|
`gclient sync`.
|