Building V8 on Arch

I've been trying to figure out things internal to V8 for another article and came across a few massive hiccups while building V8 on Arch. The current V8 build instructions are incomplete and among many things assume a python environment below version 3, so I was getting errors on literally every step of the process. After I got around the python issue I still had some hurdles to overcome. Here's my solution which allowed me to freely compile and play around with V8. Before you move forward be sure to install depot_tools as noted in the Getting the Code section of the V8 repository.

WARNING: Hacks ahead!

Arch ships with python3 by default so you have to be sure to install python2 from the AUR:

$ yaourt -S python2

Once you do the above you'll need to be sure to get the python2 binary as your system default. The "quick way" that you can do this (there's probably a better way) is to:

$ cd $(dirname $(which python)) && rm python && ln -s python2 python

and then when you're done building V8:

$ cd $(dirname $(which python)) && rm python && ln -s python3 python

Strangely enough, I found this solution on a message chain. Above you're simply removing the system's symlink to python then re-symlinking the binding to a specific version (2) and flipping it back to the default (3) when you're done. Nothing nefarious.

Unfortunately this isn't everything. I couldn't get the instructions on the V8 GitHub page to work as-is. I ended up getting V8 built by first fetching chromium. You basically need to run these steps:

$ fetch chromium #This will take a _long_ time
$ gclient sync

This will create a .gclient_entries file, which I don't think V8 does on its own, though it seems to need. I'm not sure what the file does or what the entries are (I only skimmed it), but I do know that once I had that in my directory I could successfully complete the below steps. Note: you'll have to remove the .gclient file first (not .gclient_entries), or fetch will fail.

$ fetch v8
$ gclient sync
# `cd` into the new v8 directory now
$ tools/dev/ x64.release
$ gn args

That last command will open your editor. Add these -below- lines and save the file. I noticed error output on save, but it didn't seem to affect the overall outcome.

is_debug = true
target_cpu = "x64"
v8_enable_backtrace = true
v8_enable_slow_dchecks = true
v8_optimized_debug = false

Then build with ninja (which was installed with depot_tools)

$ ninja -C

Then finally you can compile anything in the /samples directory. Below is an example of compiling /samples/

$ g++ -I. -Iinclude samples/ -o hello-world -Wl,--start-group \{libv8_{base,libbase,external_snapshot,libplatform,libsampler},\
third_party/icu/libicu{uc,i18n},src/inspector/libinspector}.a \
-Wl,--end-group -lrt -ldl -pthread -std=c++0x

In order to run the binary you'll need to create a startup snapshot and an ICU data file. Copy them to wherever your binary was compiled to.

$ cp*.bin .
$ cp .

And that should allow you to run ./hello-world. If you got this far, congratulations! You can now mess around with V8 on Arch Linux.

Happy Hacking!