Building V8 with GN
V8 is built with the help of GN. GN is a meta build system of sorts, as it generates build files for a number of other build systems. How you build therefore depends on what “back-end” build system and compiler you’re using.
The instructions below assume that you already have a checkout of V8 and that you have installed the build dependencies.
More information on GN can be found in Chromium’s documentation or GN’s own docs.
Building V8 from source involves three steps:
- generating build files
- compiling
- running tests
There are two workflows for building V8:
- the convenience workflow using a helper script called
gmthat nicely combines all three steps - the raw workflow, where you run separate commands on a lower level for each step manually
Building V8 using gm (the convenience workflow) #
gm is a convenience all-in-one script that generates build files, triggers the build and optionally also runs the tests. It can be found at tools/dev/gm.py in your V8 checkout. We recommend adding an alias to your shell configuration:
alias gm=/path/to/v8/tools/dev/gm.pyYou can then use gm to build V8 for known configurations, such as x64.release:
gm x64.releaseTo run the tests right after the build, run:
gm x64.release.checkgm outputs all the commands it’s executing, making it easy to track and re-execute them if necessary.
gm enables building the required binaries and running specific tests with a single command:
gm x64.debug mjsunit/foo cctest/test-bar/*Building V8: the raw, manual workflow #
Step 1: generate build files #
There are several ways of generating the build files:
- The raw, manual workflow involves using
gndirectly. - A helper script named
v8genstreamlines the process for common configurations.
Generating build files using gn #
Generate build files for the directory out/foo using gn:
gn args out/fooThis opens an editor window for specifying the gn arguments. Alternatively, you can pass the arguments on the command line:
gn gen out/foo --args='is_debug=false target_cpu="x64" v8_target_cpu="arm64"'This generates build files for compiling V8 with the arm64 simulator in release mode.
For an overview of all available gn arguments, run:
gn args out/foo --listGenerate build files using v8gen #
The V8 repository includes a v8gen convenience script to more easily generate build files for common configurations. We recommend adding an alias to your shell configuration:
alias v8gen=/path/to/v8/tools/dev/v8gen.pyCall v8gen --help for more information.
List available configurations (or bots from a master):
v8gen listv8gen list -m client.v8Build like a particular bot from the client.v8 waterfall in folder foo:
v8gen -b 'V8 Linux64 - debug builder' -m client.v8 fooStep 2: compile V8 #
To build all of V8 (assuming gn generated to the x64.release folder), run:
ninja -C out/x64.releaseTo build specific targets like d8, append them to the command:
ninja -C out/x64.release d8Step 3: run tests #
You can pass the output directory to the test driver. Other relevant flags are inferred from the build:
tools/run-tests.py --outdir out/fooYou can also test your most recently compiled build (in out.gn):
tools/run-tests.py --gnBuild issues? File a bug at v8.dev/bug or ask for help on v8-users@googlegroups.com.