Compile v8 arm, arm64, ia32

It’s been a long time since I last compiled v8 for arm 7 Android, and honestly, lots of things have changed. No more scons, etc… This is going to be a quick guide on how to compile v8 5.5 for Android on CentOS or Ubuntu. The list of steps is not big, but hold tight.

I use this script regularly, and is updated over the versions. I have recently used it to successfully compile and upgrade my projects to v8 v8.

# Install git:
sudo yum install git
# Install 32 bit library support (multiarch):
sudo yum install glibc-devel.i686
# 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
# If in ubuntu, you'll really want to execute:
#    build/
# 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:
# you can have a full list of options by running:
#   `tools/dev/ list -m client.v8.ports`
tools/dev/ gen -m client.v8.ports -b "V8 Android Arm - builder" 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 —-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
# v8_use_external_startup_data = false
# Optionally set `target_cpu="arm64"`
# for a full argument list, run: 
#   `gn args --list android_arm.release`
# Compile target: 
# This may take up to 1 hour depending on your setup.
# Use a -j value suitable for your system.
ninja -C -j 4
# Create fat lib files. 
# You also could add all .* files into one single library.
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 compilation on Android, always use the same ndk as 
# `gclient sync` downloaded. 
# As of the time of this writing it was `ndk r12b`
# Enjoy v8 embedded in an Android app

Compile for Android emulator

tools/dev/ gen ia32.release
# edit, to contain the following:
is_debug = false
target_cpu = "x86"
target_os = "android"
v8_enable_i18n_support = false

Published by ibon

Chocolate engineer, software eater. Data visualisation at Workday. Past: Platochat, SdkBox, Chukong, Ludei.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: