Skip to content

Compilation

joshua edited this page Feb 18, 2018 · 1 revision

This script compiles v8 on ubuntu/cent os. I use a VM for this and I'd recommend a disk of at least 30Gb in size. If you want to compile v8 in debug mode, you'll need most of that space ! With this size, you'll barely be able to compile v8 for arm7 and arm64 in release mode.

# Install git:
apt install git

# Install depot tools
# Follow instructions here.
# Fetch v8 source code.
# Use the branch of your choice. In my case latest 5.5 stable.
fetch v8
cd v8
git pull
git checkout 5.5-lkgr

# In ubuntu, you'll really want to execute:
build/install-build-deps-android.sh

# Set android target: 
# This may take a while. It downloads android tools: sdk+ndk, etc.
echo "target_os = ['android']" >> ../.gclient && gclient sync

# Generate compilation target: 
# Change android_arm.release for your favorite folder name, in this
# case: out.gn/android_arm.release
#
# you can have a full list of options by running:
#   `tools/dev/v8gen.py list -m client.v8.ports`
tools/dev/v8gen.py gen -b android.arm.release android_arm.release

# Edit ninja configuration file: 
# I’d recommend disabling icu support, and set 
# symbol_level=0 for faster compilation and thinner
# output libs. You can get the whole list of 
# compilation options by executing: 
# `gn args out.gn/android_arm.release —-list` 
# 
# You must also disable distributed compiler goma.
#
# E.g.:
# 
# v8_enable_i18n_support= false
# is_debug = false
# symbol_level = 0
# target_cpu = "arm"
# enable_goma = false
# 
# Optionally set `target_cpu="arm64"`
#
# for a full argument list, run: 
#   `gn args --list android_arm.release`
#
vi out.gn/android_arm.release/args.gn

# Compile target: 
# This may take up to 1 hour depending on your setup.
# Use a -j value suitable for your system.
ninja -C out.gn/android_arm.release -j 4

# Create fat lib files. 
# You also could add all .* files into one single library.
# 
cd out.gn/android_arm.release/obj
mkdir libs
cd libs

# one lib to rule them all.
ar -rcsD libv8_base.a ../v8_base/*.o
ar -rcsD libv8_base.a ../v8_libbase/*.o
ar -rcsD libv8_base.a ../v8_libsampler/*.o
ar -rcsD libv8_base.a ../v8_libplatform/*.o 
ar -rcsD libv8_base.a ../src/inspector/inspector/*.o

# preferred snapshot type: linked into binary.
ar -rcsD libv8_snapshot.a ../v8_snapshot/*.o 

# depending on snapshot options, you should left out 
# v8_snapshot files and include any of these other libs.
ar -rcsD libv8_nosnapshot.a ../v8_nosnapshot/*.o
ar -rcsD libv8_external_snapshot.a ../v8_external_snapshot/*.o

# source headers, for inspector compilation.
mkdir -p src/base/platform
cp -R ../../../../src/*.h ./src
cp -R ../../../../src/base/*.h ./src/base
cp -R ../../../../src/base/platform/*.h ./src/base/platform

# copy v8 compilation header files:
cp -R ../../../../include ./

# For Android compilation, you must use the same ndk as `gclient sync` downloaded. 
Clone this wiki locally