Welcome to the chapters of Let’s Understand Chrome V8.
Note: Install SDK separately, do not use VS installer, because the SDK installed with VS installer is incomplete.
Download the depot_tools bundle and extract it somewhere.
Warning: DO NOT use drag-n-drop or copy-n-paste extract from Explorer, this will not extract the hidden “.git” folder which is necessary for depot_tools to auto-update itself. You can use “Extract all…” from the context menu though.
Add depot_tools
to the start of your PATH (must be ahead of any installs of Python. Note that environment variable names are case insensitive).
Assuming you unzipped the bundle to C:\src\depot_tools
, open: Control Panel → System and Security → System → Advanced system settings.
If you have Administrator access, Modify the PATH system variable and put C:\src\depot_tools
at the front (or at least in front of any directory that might already have a copy of Python or Git).
If you don’t have Administrator access, you can add a user-level PATH environment variable by opening: Control Panel → System and Security → System → Search for “Edit environment variables for your account”.
Add C:\src\depot_tools
at the front. Note: If your system PATH has a Python in it, you will be out of luck.
Also, add a DEPOT_TOOLS_WIN_TOOLCHAIN
environment variable in the same way, and set it to 0. This tells depot_tools
to use your locally installed version of Visual Studio (by default, depot_tools
will try to use a google-internal version).
From a cmd.exe
shell, run.
Note: No Powershell!
On the first run, gclient
will install all the Windows-specific bits needed to work with the code, including msysgit
and python.
If you run gclient
from a non-cmd shell (e.g., cygwin
, PowerShell), it may appear to run properly, but msysgit
, python and other tools may not get installed correctly.
If you see strange errors with the file system on the first run of gclient
, you may want to disable Windows Indexing.
cd ~\v8\src> gn gen --ide=vs out\default --args="is_component_build = true is_debug = true v8_optimized_debug = false"
is_debug = true
enable V8 debug,v8_optimized_debug = false
disenable the optimization that interferes with debug. My args.gn
is below:
is_component_build = trueis_debug = truev8_optimized_debug = falsev8_use_snapshot = false
Compile V8 with VS2019
src\out\default — ->all.sln
Open it,as shown in Figure 1.
In the Solution Explorer, there is the v8_hello_world
, right-click it to “Set as Startup Project”, and then build. You can see the compilation process in the output window, as shown in Figure 1.
Figure 2 is the call stack of hello-world.cc
.
In summary, if you see strange errors, maybe related to the SDK version or environment path.
The V8 has huge code, so we need to find an easy way.
The source code of V8 is in src, as shown in Figure 3.
We start to learn from hello-world.cc
(it is in the samples directory) as shown in Figure 1.
V8 is the JavaScript engine, the hello-world.cc
includes initialization, isolate creation, handle creation, JavaScript compilation, and execution.
Again, the easy way is to debug hello-world.cc
one step by one step.
Okay, my blog is cncyclops.com. Please reach out to me if you have any issues.
WeChat: qq9123013 Email: [email protected]
Also published here.