Build V8 with GN and MinGW

365 views Asked by At

I would like to build a static, monolithic library suitable for embedding via MinGW. This is a multiplatform project and I want to avoid switching my entire toolchain over to MSVC. All answers on StackOverflow, Google Groups and the v8 wiki refer to SCons, GYP or MinGW build generation files that no longer exist. I have:

  1. Followed the instructions here to install depot_tools and fetch v8.
  2. Added [User Directory]\depot_tools to the front of my PATH variable.
  3. Set DEPOT_TOOLS_WIN_TOOLCHAIN=0 in my environment variables.

Instructions here suggest bypassing the manual workflow by outputting build files yourself. When I run gn args out/mingw I get a python stack trace ending with:

Exception: No supported Visual Studio can be found. Supported versions are: 16.0 (2019), 17.0 (2022), 15.0 (2017).
ERROR at //build/config/win/visual_studio_version.gni:27:7: Script returned non-zero exit code.
      exec_script("../../vs_toolchain.py", [ "get_toolchain_dir" ], "scope")
      ^----------
1

There are 1 answers

0
jackdbd On

I'm not sure if this answers your question, since you mentioned gn specifically. But a few months ago I managed to compile V8 using gm.py and following these instructions.

This is what I did (I keep all git repos in ~/repos):

mkdir ~/repos/v8/v8 # that's right, type v8 twice
git checkout main

# update V8
git pull

# update V8 dependencies
gclient sync

# compile source
tools/dev/gm.py x64.release
# or, compile source and immediately run the tests
tools/dev/gm.py x64.release.check

If you need to set some specific V8 compile-time flags, I think you cannot use gm.py though. You need to generate build files using either gn or v8gen.py:

After you have managed to generate the build files, you can finally compile V8 using ninja.

A completely different route could be to use zig-v8, which uses the Zig toolchain to build V8. For example, Cosmic is a JS/WASM runtime that uses zig-v8 to embed V8.