有个系统将来可能会要用到Javascript支持,于是今天尝试编译了一下V8引擎,一路还是很顺利的,特将步骤记录如下:
- 首先准备*,我的*是装在路由器上的,此步骤就省了
- 安装Git,这个我已经有了
- 安装Python2.7,官网上下下来安装就好了,并把安装目录配置到Path环境变量里。
这里有个小插曲是,只要我在powershell里输入python,系统就会启动windows
store,让我下载Python3。稍微纠结了一下发现,一定要把python的安装目录放在Path环境变量的最前面。 - git clone https://chromium.googlesource.com/chromium/tools/depot_tools
- 把clone下来的depot_tools的路径也添加到Path环境变量里
- 再分别加入下面这些环境变量
DEPOT_TOOLS_WIN_TOOLCHAIN = 0
GYP_MSVS_OVERRIDE_PATH = C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
GYP_MSVS_VERSION 2017
注意:VS2017我是安装在C盘的,网上有资料说源码和VC都要装在C盘,不然会出错,但我源码并不是在C盘,编译还是很顺利的。 - 建一个目录,比如v8,开始下载源码,v8的代码更新的太快了,最好还是通过depot_tools工具来下载源码
这个过程比较长,特别是我还有*的情况下,大概都持续了10几分钟吧,完整命令行及输出如下
PS D:\projects> mkdir v8
PS D:\projects> cd v8
PS D:\projects\v8> fetch v8
Your depot_tools checkout is configured to fetch from an obsolete URL
Would you like to update it? [y/N]: Y
Running: 'C:\Users\mycti\.vpython-root\49ae94\Scripts\python.exe' 'D:\projects\depot_tools\gclient.py' root
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Running: 'C:\Users\mycti\.vpython-root\49ae94\Scripts\python.exe' 'D:\projects\depot_tools\gclient.py' config --spec 'solutions = [
{
"url": "https://chromium.googlesource.com/v8/v8.git",
"managed": False,
"name": "v8",
"deps_file": "DEPS",
"custom_deps": {},
},
]
'
Running: 'C:\Users\mycti\.vpython-root\49ae94\Scripts\python.exe' 'D:\projects\depot_tools\gclient.py' sync --with_branch_heads
1>________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://chromium.googlesource.com/v8/v8.git D:\projects\v8\_gclient_v8_edptbp' in 'D:\projects\v8'
1>Cloning into 'D:\projects\v8\_gclient_v8_edptbp'...
1>remote: Sending approximately 612.44 MiB ...
1>remote: Counting objects: 7695, done
1>remote: Finding sources: 100% (35/35)
1>remote: Total 739577 (delta 608565), reused 739565 (delta 608565)
1>Receiving objects: 100% (739577/739577), 612.23 MiB | 4.16 MiB/s, done.
1>Resolving deltas: 100% (608565/608565), done.
[0:05:50] Still working on:
[0:05:50] v8
1>Syncing projects: 0% ( 0/ 2)
[0:05:59] Still working on:
[0:05:59] v8
Syncing projects: 92% (25/27) v8/third_party/perfetto
[0:08:25] Still working on:
[0:08:25] v8/test/test262/data
[0:08:25] v8/third_party/icu
[0:08:35] Still working on:
[0:08:35] v8/test/test262/data
[0:08:35] v8/third_party/icu
[0:08:37] Still working on:
[0:08:37] v8/test/test262/data
[0:08:37] v8/third_party/icu
Syncing projects: 96% (26/27) v8/test/test262/data
[0:09:37] Still working on:
[0:09:37] v8/third_party/icu
[0:09:47] Still working on:
[0:09:47] v8/third_party/icu
[0:09:57] Still working on:
[0:09:57] v8/third_party/icu
[0:10:07] Still working on:
[0:10:07] v8/third_party/icu
[0:10:17] Still working on:
[0:10:17] v8/third_party/icu
[0:10:21] Still working on:
[0:10:21] v8/third_party/icu
Syncing projects: 100% (27/27), done.
Hook 'vpython.bat v8/build/landmines.py --landmine-scripts v8/tools/get_landmines.py' took 54.55 secs
Running hooks: 12% ( 3/25) clang_format_win
________ running 'download_from_google_storage --no_resume --platform=win32 --no_auth --bucket chromium-clang-format -s v8/buildtools/win/clang-format.exe.sha1' in 'D:\projects\v8'
0> Downloading v8/buildtools/win/clang-format.exe...
Downloading 1 files took 75.528000 second(s)
Hook 'download_from_google_storage --no_resume --platform=win32 --no_auth --bucket chromium-clang-format -s v8/buildtools/win/clang-format.exe.sha1' took 75.80 secs
Running hooks: 32% ( 8/25) wasm_spec_tests
________ running 'download_from_google_storage --no_resume --no_auth -u --bucket v8-wasm-spec-tests -s v8/test/wasm-spec-tests/tests.tar.gz.sha1' in 'D:\projects\v8'
0> Downloading v8/test/wasm-spec-tests/tests.tar.gz...
0> Extracting 421 entries from v8/test/wasm-spec-tests/tests.tar.gz to v8/test/wasm-spec-tests/tests
Downloading 1 files took 17.232000 second(s)
Hook 'download_from_google_storage --no_resume --no_auth -u --bucket v8-wasm-spec-tests -s v8/test/wasm-spec-tests/tests.tar.gz.sha1' took 17.49 secs
Running hooks: 36% ( 9/25) wasm_js
________ running 'download_from_google_storage --no_resume --no_auth -u --bucket v8-wasm-spec-tests -s v8/test/wasm-js/tests.tar.gz.sha1' in 'D:\projects\v8'
0> Downloading v8/test/wasm-js/tests.tar.gz...
0> Extracting 112 entries from v8/test/wasm-js/tests.tar.gz to v8/test/wasm-js/tests
Downloading 1 files took 14.481000 second(s)
Hook 'download_from_google_storage --no_resume --no_auth -u --bucket v8-wasm-spec-tests -s v8/test/wasm-js/tests.tar.gz.sha1' took 14.76 secs
Running hooks: 76% (19/25) clang
________ running 'vpython.bat v8/tools/clang/scripts/update.py' in 'D:\projects\v8'
Downloading https://commondatastorage.googleapis.com/chromium-browser-clang/Win/clang-n343707-61f538d3-1.tgz .......... Done.
Copying C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA SDK\bin\amd64\msdia140.dll to D:\projects\v8\v8\third_party\llvm-build\Release+Asserts\bin
Hook 'vpython.bat v8/tools/clang/scripts/update.py' took 17.34 secs
Running hooks: 100% (25/25), done.
Running: git submodule foreach 'git config -f $toplevel/.git/config submodule.$name.ignore all'
Running: git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
Running: git config diff.ignoreSubmodules all
PS D:\projects\v8>
- 刚才fetch成功,在当前目录下又生成了一个v8目录,进入后开始编译,powershell CPU 100%,又是半个小时的等待
PS D:\projects\v8> cd v8
PS D:\projects\v8\v8> python .\tools\dev\gm.py x64.debug
# mkdir -p out\x64.debug
# echo > out\x64.debug\args.gn << EOF
is_component_build = true
is_debug = true
symbol_level = 2
target_cpu = "x64"
use_goma = false
goma_dir = "None"
v8_enable_backtrace = true
v8_enable_fast_mksnapshot = true
v8_enable_slow_dchecks = true
v8_optimized_debug = false
EOF
# gn gen out\x64.debug
Done. Made 148 targets from 84 files in 10639ms
# autoninja -C out\x64.debug d8
"D:\projects\depot_tools\ninja.exe" -C out\x64.debug d8 -j 10
ninja: Entering directory `out\x64.debug'
[1516/1516] LINK d8.exe d8.exe.pdb
Done! - V8 compilation finished successfully.
PS D:\projects\v8\v8>
-
去out目录检查一下,应该是没有问题了
-
再尝试编译Release版本
PS D:\projects\v8\v8> python .\tools\dev\gm.py x64.release
# mkdir -p out\x64.release
# echo > out\x64.release\args.gn << EOF
is_component_build = false
is_debug = false
target_cpu = "x64"
use_goma = false
goma_dir = "None"
v8_enable_backtrace = true
v8_enable_disassembler = true
v8_enable_object_print = true
v8_enable_verify_heap = true
EOF
# gn gen out\x64.release
Done. Made 148 targets from 84 files in 10355ms
# autoninja -C out\x64.release d8
"D:\projects\depot_tools\ninja.exe" -C out\x64.release d8 -j 10
ninja: Entering directory `out\x64.release'
[1402/1402] LINK d8.exe d8.exe.pdb
Done! - V8 compilation finished successfully.
PS D:\projects\v8\v8>
咦?out目录下怎么会没有我们想要的v8.lib和v8.dll,d8.exe到是正确生成了,且obj文件一个也没少,估计Release模式采用的是静态编译吧。
我们打开out\x64.release\args.gn这个文件,把里面的
is_component_build = false
改成
is_component_build = true
再次尝试编译,检查编译结果,终于见到了我们想要的v8.dll
- 最后清理一下系统环境变量,结束!