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 bugs.chromium.org 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/v8gen.py x64.release
$ gn args out.gn/x64.release

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 out.gn/x64.release

Then finally you can compile anything in the /samples directory. Below is an example of compiling /samples/hello-world.cc:

$ g++ -I. -Iinclude samples/hello-world.cc -o hello-world -Wl,--start-group \
out.gn/x64.release/obj/{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 out.gn/x64.release/*.bin .
$ cp out.gn/x64.release/icudtl.dat .

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!

comment

Comments