Building V8 on Linux

In this post, we give an example how v8 build is done on Linux. This uses fedora 23 (64 bit) Linux. However, the distribution does not matter.

Setting Proxy

Usually proxy settings is not required. If your network must use proxy, this is how you set up proxy settings before going to run fetch command or git clone

export HTTPS_PROXY="http://www-domain.com:8080"
export HTTP_PROXY="http://www-domain.com:8080"

v8 uses a number of components which are fetched from separate git repositories. To manually fetch them, sync them and update project files as you can realize can be tedious. To solve this problem Google uses depot tools which includes a bunch of python scripts that help us achieve those tasks comfortably.

If you haven’t fetched depot_tools yet, this is the time to get it by applying following command (first line is the command, rest of the lines are output),

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
Cloning into 'depot_tools'...
remote: Sending approximately 19.31 MiB ...
remote: Counting objects: 1105, done
remote: Finding sources: 100% (123/123)
remote: Total 14833 (delta 9182), reused 14828 (delta 9182)
Receiving objects: 100% (14833/14833), 19.31 MiB | 1.28 MiB/s, done.
Resolving deltas: 100% (9182/9182), done.
Checking connectivity... done.

We need to add depot_tools to system PATH. If we you need to use depot tools often, putting it on .bashrc is handy.

$ PATH=`pwd`/depot_tools:$PATH

Then, we create new workspace directory for our development and run fetch command,

$ mkdir jv8_ws
$ cd jv8_ws/
$ fetch v8
Running: gclient root
Running: gclient config --spec 'solutions = [
  {
    "managed": False,
    "name": "v8",
    "url": "https://chromium.googlesource.com/v8/v8.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
'
Running: gclient sync --with_branch_heads
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules all

fetch is a shell script (a cmd script in Windows) on Linux/Unix which calls fetch.py. This is how code of fetch.py looks like,

6 base_dir=$(dirname "$0")
7
8 PYTHONDONTWRITEBYTECODE=1 exec python "$base_dir/fetch.py" "$@"

fetch builds all the required component projects and tools required to build v8. It has 16 git repositories (this changes over time),

v8/.git
v8/buildtools/clang_format/script/.git
v8/buildtools/third_party/libc++/trunk/.git
v8/buildtools/third_party/libc++abi/trunk/.git
v8/buildtools/.git
v8/tools/clang/.git
v8/tools/swarming_client/.git
v8/test/mozilla/data/.git
v8/test/test262/data/.git
v8/test/benchmarks/data/.git
v8/test/simdjs/data/.git
v8/base/trace_event/common/.git
v8/build/gyp/.git
v8/testing/gmock/.git
v8/testing/gtest/.git
v8/third_party/icu/.git

The last command to keep the source files in sync with repository and update project files as required is the `gclient sync’ command,

$ gclient sync
output of the command is large and is provided in link below to save space.

Output of the command is here (link is dead, update).

Single command builds everything for the project,

$ make native

It does a release build for native platform. Here is the output for a successful build.

Information available with the default command is brief. Enabling verbosity we get more info. Here is an example that enable verbose flag and does a debug build,

$ make x64.debug V=1 -j 16 >& gmake_log.txt

The build output is huge. I put only the essence here.

Example, running of js code,

$ gdb /home/atiq/javascript_v8_ws/v8/out/x64.debug/d8
var car = function(make,model) {
    this.make = make;
    this.model = model;
}

var myCar = new car(honda,accord);

myCar.year = 2005;

Troubleshooting, Tips and Tricks

Q1. stdio header not found

If we encounter error such as stdio.h not found,

$ make native
PYTHONPATH="/home/atiq/jv8_ws/v8/tools/generate_shim_headers:/home/atiq/jv8_ws/v8/build::/home/atiq/jv8_ws/v8/build/gyp/pylib:" \
GYP_GENERATORS=make \
build/gyp/gyp --generator-output="out" build/all.gyp \
             -Ibuild/standalone.gypi --depth=. -S.native  -Dv8_enable_backtrace=1 -Darm_fpu=default -Darm_float_abi=default
make[1]: Entering directory '/home/atiq/jv8_ws/v8/out'
 CXX(target) /home/atiq/jv8_ws/v8/out/native/obj.target/v8_base/src/accessors.o
In file included from ../src/accessors.cc:5:
In file included from .././src/accessors.h:8:
.././include/v8.h:20:10: fatal error: 'stdio.h' file not found
#include 
        ^
1 error generated.

We install required C++ package for the build. On Fedora Linux distribution, the package is named gcc-c++,

$ sudo dnf -y install gcc-c++

Installed:
 binutils.x86_64 2.25-17.fc23    cpp.x86_64 5.3.1-2.fc23    gcc.x86_64 5.3.1-2.fc23    gcc-c++.x86_64 5.3.1-2.fc23
 glibc-devel.x86_64 2.22-3.fc23    glibc-headers.x86_64 2.22-3.fc23    isl.x86_64 0.14-4.fc23
 kernel-headers.x86_64 4.4.6-300.fc23    libmpc.x86_64 1.0.2-4.fc23    libstdc++-devel.x86_64 5.3.1-2.fc23
Upgraded:
 libgcc.x86_64 5.3.1-2.fc23    libgomp.x86_64 5.3.1-2.fc23    libstdc++.x86_64 5.3.1-2.fc23
Complete!

Afterwards, build should complete without any error.

Q2. Building with g++ instead of clang++ on Linux,

To build using g++ on Linux, we pass a flag to gyp. Here is an example command that passes required flag to disable use of clang,

$ make x64.debug GYPFLAGS="-Dclang=0" V=1 -j 32 >& gmake_log.txt

Q3. I am getting libtinfo.so.5 error on fedora 24.

I believe this library requirement started with fedora 24. Please look at this fftsys tech article to resolve this.