最好使用Linux环境下载、编译V8源码。在Mac上编译v8遇到了很多坑。
如果不存在网络问题,搭建V8环境相对比较简单,参考官方文件即可 👉v8.dev/docs/build
# 同步下载工具
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# 设置环境变量
export PATH=/path/to/depot_tools:$PATH
# 切换镜像
gclient config https://gitee.com/mirrors/V8.git
# 同步代码
gclient sync
# linux下安装依赖
./build/install-build-deps.sh
# 切换源码目录
cd /path/to/v8
# 执行构建
tools/dev/gm.py x64.debug
构建
同步代码时因为网络问题, 速度可能很慢。这里提供一种做法,gclient命令在下载资源时读取了源码目录中的DEPS文件。我们可以在github找到相应的库直接下载的对应目录。
举个🌰:
'third_party/protobuf': Var('chromium_url') + '/external/github.com/google/protobuf'+ '@' + '6a59a2ad1f61d9696092f79b6d74368b4d7970a3'
我们要下载protobuf这个依赖
cd v8/third_party
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout --quiet 6a59a2ad1f61d9696092f79b6d74368b4d7970a3
对于那些找不到的库,如v8/third_party/libc++/src,我们可以断点续传,避免因网络问题导致重新下载。
在举个🌰:
'build': Var('chromium_url') + '/chromium/src/build.git' + '@' + '841e388a14ed5309213a2b6ac2b6e49c2f5aa'
cd v8/build
git init
git remote origin https://chromium.googlesource.com/chromium/src/build
git pull