Have you ever asked what does V8 do? Here’s how to build a V8 of your own from source code. See what it can do and even have fun with it.

Required Link to heading

  • bash shell
  • git

I set up the V8 source code inside ~/Code/ folder and use it throughout this article. You can change it to your desired folder.

Prepare the tools and source code Link to heading

We need to get the depot tools bundle from google. It’s a package of scripts, to automate tasks to manage repositories http://www.chromium.org/developers/how-tos/install-depot-tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PWD/depot_tools:$PATH
fetch v8

You should see new directories for depot_tools and v8 in current working dir.

tree -L 1 -h                                                                                     02:34:57
.
├── [7.3K]  depot_tools
└── [2.0K]  v8

2 directories, 0 files

Install dependencies Link to heading

cd v8
export PATH=$PWD/tools/dev:$PATH
  • This will help run build commands quicker.
  • Run magic script to install everything needed ./build/install-build-deps.sh (you have to provide sudo password)
  • Try gm.py x64.release to see if it start building. Note: your python must be version 2.x.x. If not, try switch python version using pyenv or any python version management tool. Otherwise you can run python2 tools/dev/gm.py x64.release instead.
  • After a couple minutes, check the out/x64.release folder to see the result.

Play with V8 Link to heading

After building the source code, you will be able to use d8. V8’s own developer shell.

$ ./out/x64.release/d8   
V8 version 9.0.0 (candidate)

Try writing some Javascripts, eg:

d8> console.log('Hello V8!')
Hello V8!
undefined
d8> for (let i = 0; i < 5; i++) console.log(i)
0
1
2
3
4
undefined
d8> 

What’s next? Link to heading

You now have all the control over the engine. You can modify the source code, build and test it using d8.

Goodluck have fun!