title: ‘Compiling on Arm64’

description: ‘Tips and tricks to build V8 natively on Arm64’

If you’ve gone through instructions on how to check out and build V8 on a machine that is not x86, you may have ran into a bit of trouble, due to the build system downloading native binaries and then not being able to run them. However, even though using an Arm64 machine to work on V8 is not officially supported, overcoming those hurdles is pretty straightforward.

Bypassing vpython

fetch v8, gclient sync and other depot_tools commands use a wrapper for python called “vpython”. If you see errors related to it, you can define the following variable to use the system’s python installation instead:

  1. export VPYTHON_BYPASS="manually managed python not supported by chrome operations"

Building ninja and gn from source

The first thing to do is to make sure we have native binaries for ninja and gn, and that we pick those instead of the ones in depot_tools. A simple way to do this is to tweak your PATH as follows when installing depot_tools:

  1. export PATH=$PATH:/path/to/depot_tools

This way, you’ll be able to use your system’s ninja installation, given it’s likely to be available. Although if it isn’t you can build it from source.

Then you’ll need gn, which can be built with:

  1. git clone https://gn.googlesource.com/gn
  2. cd gn
  3. python build/gen.py
  4. ninja -C out

And finally tweak your PATH so that it comes before the gn from depot_tools.

  1. export PATH=/path/to/gn/out:$PATH

Compiling clang

By default, V8 will want to use its own build of clang that may not run on your machine. You could tweak GN arguments in order to use the system’s clang or GCC, however, you may want to use the same clang as upstream, as it will be the most supported version.

You can build it locally directly from the V8 checkout:

  1. ./tools/clang/scripts/build.py --without-android --without-fuchsia \
  2. --gcc-toolchain=/usr --use-system-cmake \
  3. --disable-asserts

Setting up GN arguments manually

Convenience scripts may not work by default, instead you’ll have to set GN arguments manually following the manual workflow. You can get the usual “release”, “optdebug” and “debug” configurations with the following arguments:

  • release
  1. is_debug=false
  • optdebug
  1. is_debug=true
  2. v8_enable_backtrace=true
  3. v8_enable_slow_dchecks=true
  • debug
  1. is_debug=true
  2. v8_enable_backtrace=true
  3. v8_enable_slow_dchecks=true
  4. v8_optimized_debug=false

Using the system’s clang or GCC { #system_clang_gcc }

Building with GCC is only a case of disabling compiling with clang:

  1. is_clang=false

Note that by default, V8 will link using lld, which requires a recent version of GCC. You can use use_lld=false to switch to the gold linker, or additionally use use_gold=false to use ld.

If you’d like to use the clang that’s installed with your system, say in /usr, you can use the following arguments:

  1. clang_base_path="/usr"
  2. clang_use_chrome_plugins=false

However, given the system’s clang version may not be well supported, you’re likely to deal with warnings, such as unknown compiler flags. In this case it’s useful to stop treating warnings as errors with:

  1. treat_warnings_as_errors=false