js v8编译
参考 [Checking out the V8 source code https://v8.dev/docs/source-code] [Building V8 from source https://v8.dev/docs/build] [Building Google v8 http://blogs.stonesteps.ca/showpost.aspx?pid=65]
下载代码
代理设置
全程需要翻墙,下面的ip和端口请修改成自己的代理地址
如果有VPN翻墙就不用设置了
#设置python代理
export http_proxy=http://127.0.0.1:1080
export https_proxy=https://127.0.0.1:1080
export socks5_proxy=socks5://127.0.0.1:1080
#设置git代理
git config --global http.proxy 'http://127.0.0.1:1080'
git config --global https.proxy 'https://127.0.0.1:1080'
代理设置不一定成功,把各种方式都试一下, 在执行update_depot_tools试了很久按照下面的代理设置成功了:
export HTTPS_PROXY=socks5://127.0.0.1:1080
curl代理设置
# 编辑~/.curlrc,添加一行
-x socks5h://127.0.0.1:1080
安装depot_tools
[参考这里 https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up]
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=/path/to/depot_tools:$PATH
上面安装完成后执行gclient更新depot_tools:
gclient
下载代码
mkdir ~/v8
cd v8
fetch v8
cd v8
下载所有的依赖,在v8源码目录执行:
gclient sync
在linux下面需要安装其它的依赖,windows不用, 执行下面的命令
./build/install-build-deps.sh
编译V8
[Building V8 with GN https://v8.dev/docs/build-gn]
生成build file
有两种文法生成build file:使用gn或者tools/dev/v8gen.py, 这里只介绍了使用gn的方法。v8gen.py其实是内置了一些build file参数,本质最终还是使用gn生成。
# 执行下面这个命令后会打开一个编辑器里面是编译参数,需要手动填写
# 但是因为暂时时不知道有哪些参数所以直接保存退出
# out/fbb 是生成的build file所在的目录
gn args out/fbb
现在需要设置编译参数,首先列出所有的参数,下面这个命令会列出所有的参数,然后你就知道有什么参数 可以用了:
gn args out/fbb --list
之后执行下面的命令添加参数,生成build file:
gn gen out/fbb --args='is_component_build=true target_cpu="x64" is_debug=false use_goma=true'
--args后面的就是设置的参数,也可以直接打找out/fbb/args.gn文件编辑里面的参数
编译
ninja -C out/fbb