🔗 Building V8

This exercise is an opportunity for you to gain experience building standalone V8 yourself.

Noteinfo

As mentioned previously, this exercise is entirely optional. It will help to familiarize yourself with the build system, but all other exercises will use custom prebuilt V8 binaries.

Warningwarning

If you haven't already, read through the VM overview to understand the VM / exercise setup.

Use the command exercise run builds in the VM to drop into a base Ubuntu container with depot_tools pre-installed. Note that like other exercise containers, the home directory is shared with the host.

🔗 1. Get the Code

You can try your luck building the current main git branch, but it may be in a somewhat "broken" state that will end up failing to build.

To increase the likelihood the build goes smoothly, you can clone a version more likely to compile:

  • use the lkgr ("last known good revision") branch
  • pick a release from Chromium Dash and copy the V8 commit hash
Noteinfo

On the off chance there are changes in the build system etc., a commit known to have worked with these instructions is a18d302cdb248c7c5acda7cd575e2c45f7e26dc4

Once you've identified the version / commit you'd like to use, you can fetch the code:

bash
# Download code mkdir v8 && cd v8 fetch --nohooks v8 # Checkout specific version cd v8 && git checkout <branch or hash> gclient sync # Run anytime you change v8 version
Noteinfo

To save disk space and time spent downloading, you can perform a "shallow" clone without git history:

bash
mkdir v8 && cd v8 fetch --nohooks --nohistory v8 cd v8 git fetch --depth=1 origin <branch or hash> git checkout <branch or hash> gclient sync

🔗 2. Install Dependencies

Install system-wide package dependencies with:

bash
./build/install-build-deps.sh

🔗 3. Build

Noteinfo

If you want to specify additional build options, first run:

bash
gn args out/x64.release

To list all possible options: gn args --list out/x64.release (warning: lots of output) or see BUILD.gn.

Kick off a release build:

bash
# Trigger build or rebuild # (gm.py wraps gn + ninja) tools/dev/gm.py x64.release

Compilation will take a while.

Warningwarning

The VM is not specced as a build box:

  • do NOT attempt a debug build, which requires lots of RAM and will likely DOS the machine
  • similarly, do not attempt building both V8 and JSC at the same time
  • a build can take e.g. 8+ hours, throw it in a tmux/screen session so you can disconnect as needed

🔗 4. Run!

Hopefully your build completes, and you can proudly run your freshly compiled interpreter:

bash
./out/x64.release/d8