Building V8 on an M1 MacBook
I’ve recently got an M1 MacBook and played around with it a bit. It seems many open source projects still haven’t added MacOS with ARM64 into their support matrix, requiring a few extra steps to work properly, and V8 is no exception. Here are the steps I’ve taken to get V8 building on a M1 MacBook and hopefully it could help someone else on the Internet.
Update: since some time in 2022, the workarounds for depot_tools has no longer been necessary.
First, download the depot_tools and bootstrap it as usual. Assuming you place your all projects under a
$WORKSPACE_DIR (which is what I tend to do):
Next, fetch V8:
# Create the parent folder for V8
tools/dev/v8gen.py doesn’t seem to work on MacOS ARM64 yet - it keeps putting
target_cpu = "x64" into the config which is in conflict with the
v8_target_cpu = "arm64" that it will generate when you pass arm64 as the architecture to it. So I ended up just creating the configs manually myself. For debug builds:
mkdir -p out.gn/arm64.debug/
For release builds:
mkdir -p out.gn/arm64.release/
v8_enable_trace_ignition=true (which gives you a nice trace when you pass
--trace-ignition to d8) and
cc_wrapper="ccache" (which enables ccache integration, see Chromium’s guide on how to use ccache) are what I tend to use myself, but they are not musts. For optimized debug builds you just need to turn on
v8_optimized_debug and tweak other configs as you see fit.
As explained earlier I usually use ccache when building V8, so I’d first do
And then per the instructions of the Chromium ccache guide, prefix the
$PATH variable before I run ninja to build:
PATH=`pwd`/third_party/llvm-build/Release+Asserts/bin:$PATH ninja -C out.gn/arm64.release
Just to check that it’s working:
python2 tools/run-tests.py --outdir=out.gn/arm64.release --quickcheck