Skip to content

Commit c06ffee

Browse files
committed
doc: document the GN build
1 parent 8a41d9b commit c06ffee

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

doc/contributing/gn-build.md

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# GN Build
2+
3+
Similar to GYP, GN is a build system designed for building Chromium. The
4+
official builds of Node.js are built with GYP, but GN build files are also
5+
provided as an unofficial alternative build system.
6+
7+
Currently the GN build is used by:
8+
9+
1. Electron for building Node.js together with Chromium.
10+
2. V8 for testing the integration of Node.js in CI.
11+
12+
## Files of GN
13+
14+
Node.js contains following GN build files:
15+
16+
* `node.gni` - Public GN arguments for configuring the build.
17+
* `*/BUILD.gn` - This is the file where GN looks for build rules, in Node.js it
18+
just includes the `unofficial.gni` file to avoid accidental modifications.
19+
* `*/unofficial.gni` - The actual build rules for each component.
20+
21+
## Build with GN
22+
23+
Unlike GYP, the GN tool does not include any built-in rules for compiling a
24+
project, which means projects building with GN must provide their own build
25+
configurations for things like how to invoke a C++ compiler. Chromium related
26+
projects like V8 and skia choose to reuse Chromium's build configurations, and
27+
we are reusing V8's Node.js integration testing repository
28+
([node-ci](https://chromium.googlesource.com/v8/node-ci/)) for building Node.js.
29+
30+
### 1. Install `depot_tools`
31+
32+
The `depot_tools` is a set of tools used by Chromium related projects for
33+
checking out code and managing dependencies, and since we are reusing the infra
34+
of V8, we have to install and add it to `PATH`:
35+
36+
```bash
37+
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
38+
export PATH=/path/to/depot_tools:$PATH
39+
```
40+
41+
You can also follow the [official tutorial of
42+
`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html).
43+
44+
### 2. Check out code
45+
46+
To check out the latest main branch of Node.js for building, use the `fetch`
47+
tool from `depot_tools`:
48+
49+
```bash
50+
mkdir node_gn
51+
cd node_gn
52+
fetch node
53+
```
54+
55+
You can choose to save some time by omitting git history:
56+
57+
```bash
58+
fetch --no-history node
59+
```
60+
61+
After syncing is done, you will get a directory structure like this:
62+
63+
```console
64+
node_gn/
65+
├── .gclient
66+
├── .gclient_entries
67+
├── ...
68+
└── node
69+
├── DEPS
70+
├── ...
71+
├── build/
72+
├── node/
73+
└── tools/
74+
```
75+
76+
The `node_gn` is a workspace directory, which only contains configurations and
77+
caches of the `gclient` tool from `depot_tools`, and the repository is checked
78+
out at `node_gn/node`.
79+
80+
The `node_gn/node` directory is not the repository of Node.js, it is actually
81+
node-ci, the repository used by V8 for testing integration with Node.js. The
82+
source code of Node.js is checked out at `node_gn/node/node`.
83+
84+
### 3. Build
85+
86+
GN only supports [`ninja`](https://ninja-build.org) for building, so to build
87+
Node.js with GN we have to generate `ninja` build files first and then call
88+
`ninja` to do the building.
89+
90+
The `node-ci` repository provides a script for calling GN:
91+
92+
```bash
93+
./tools/gn-gen.py out/Release
94+
```
95+
96+
which writes `ninja` build files into the `out/Release` directory.
97+
98+
And then you can execute `ninja`:
99+
100+
```bash
101+
ninja -C out/Release node
102+
```
103+
104+
## Status of the GN build
105+
106+
Currently the GN build of Node.js is not fully functioning. It builds for macOS
107+
and Linux, but we are still fixing a few issues to make the Windows build work.
108+
And not all tests are passing using the GN build.
109+
110+
There are also efforts on [making GN build work without using
111+
`depot_tools`](https://github.com/photoionization/node_with_gn), which uses a
112+
[forked version of GN](https://github.com/yue/build-gn).

0 commit comments

Comments
 (0)