Follow up Build v8 from source on Ubuntu 20.04. Today we’re gonna build v8 source on an Apple M1 chip MacOS.

Required Link to heading

  • bash shell
  • git
  • Xcode
  • python2

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

First 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.
  • Try gm.py arm64.release.d8 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 arm64.release.d8 instead.
  • After a couple minutes, check the out/arm64.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/arm64.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>