11

I'm making a game engine for school, and I want to use Google's V8 to allow for JavaScript scripting in-engine. The engine is written using Visual Studio 2013, and as the final game must not exceed 50MB, I want to keep the V8 filesize impact as small as possible.

Looking around the Internet for how to do stuff with V8, I came across a series of tutorials on V8, which comes with a precompiled .lib file for V8. However, it is four years old. I'm assuming that building a more recent version on my own would improve performance and add features, so I spent all of yesterday struggling with the V8 build process, and eventually figured out how to compile V8 for Visual Studio:

  1. Install Google's "depot tools"
  2. Run fetch v8

This gets me everything I need to generate the V8 Visual Studio solution, and when I compile it, it works, and generates .lib and .dll files. However, when I try to create a test solution and link these libraries to it, it's incredibly confusing.

The build process generates the following LIB files:

  • cctest.lib
  • gmock.lib
  • gtest.lib
  • icui18n.lib
  • icuuc.lib
  • mksnapshot.lib
  • unittest.lib
  • v8.lib
  • v8_base.lib
  • v8_libbase.lib
  • v8_libplatform.lib
  • v8_nosnapshot.lib
  • v8_snapshot.lib

And the following DLLs:

  • icudt.dll
  • icui18n.dll
  • icuuc.dll
  • v8.dll

At some point yesterday, I included many of the libs (I think it was v8, v8_base, and v8_snapshot) and copied over all of the DLLs to the output directory of my project, and it eventually worked. However, as I said above, I need the filesize impact of V8 to be as small as possible. I don't need i18n support, so is there a way to compile without it? Like I said above, I have an old version of the V8 .lib, which doesn't need a DLL to run, and it compiles and works fine... but am I missing out on newer features and improvements, as it's four years old? And what do all of these .libs mean, anyways? I can't find any documentation on which ones do what or anything like that.

So yeah, I guess if anyone could provide instructions or point me toward any documentation that would help, that would be great. I spent nearly all day yesterday trying to solve this problem.

ffrey
  • 51
  • 1
  • 8
Adam Rezich
  • 2,972
  • 5
  • 28
  • 39

2 Answers2

5

There is a page Building with GYP in the V8 wiki. In brief, you should use GYP to generate a Visual Studio solution and then build it.

  1. Install Python, Subversion client; make it available from a command line.
  2. Open Visual Studio Command Prompt, do next steps there.
  3. Fetch V8 sources into some directory, say it would be named v8-build:

    svn checkout http://v8.googlecode.com/svn/trunk v8-build

for the recent version (either some tagged version, for example http://v8.googlecode.com/svn/tags/3.28.57)

  1. On Windows you need Cygwin: svn checkout http://src.chromium.org/svn/trunk/deps/third_party/cygwin@66844 v8-build/third_party/cygwin

(see actual URL in a v8-build/DEPS file)

  1. Fetch GYP:

    svn checkout http://gyp.googlecode.com/svn/trunk@1831 v8-build/gyp

  2. Optionally fetch ICU:

    svn checkout https://src.chromium.org/svn/trunk/deps/third_party/icu46@258359 v8-build/third_party/icu

  3. Make tools available in the command line:

    • set CYGWIN_ROOT=%cd%\v8-build\third_party\cygwin
    • set PATH=%CYGWIN_ROOT%\bin;%PATH%
    • set PYTHONPATH=%cd%\v8-build\gyp\pylib
    • v8-build\third_party\cygwin\setup_mount.bat
    • v8-build\third_party\cygwin\setup_env.bat
  4. Run GYP with desired options:

    python v8-build\build\gyp_v8 -Dcomponent=static_library -Dtarget_arch=x64 -v8_enable_i18n_support=0 -Dv8_use_snapshot=0

(see allowed variables in v8-build\build\features.gypi)

  1. Build generated project with Visual Studio using the Cygwin environment:

    msbuild /m /p:UseEnv=true /p:Configuration=Release /p:Platform=x64 v8-build\tools\gyp\v8.vcxproj

  2. Result libraries should be in the v8-build\build directory

I use a Python script to automate the steps above.

Update: I use similar script to build NuGet packages for V8, and here is it: https://github.com/pmed/v8-nuget/blob/master/build.py

pmed
  • 1,456
  • 8
  • 11
  • I'm trying to compile this right now, but I'm a bit confused -- why do some gyp options have a "D" in front of them, and others don't? It seems like v8_enable_i18n_support and v8_use_snapshot should either both or neither have the "D" in front of them, as they're both variables in features.gypi, right? Other than that, and the misspelling of "component", this looks to be exactly what I needed. – Adam Rezich Oct 13 '14 at 18:12
  • Additionally, this seems to only give me v8_base.lib and v8_nosnapshot.lib. When trying to compile a test project using the provided sample code, I get this linker error: `Error 2 error LNK2001: unresolved external symbol "class v8::Platform * __cdecl v8::platform::CreateDefaultPlatform(int)" (?CreateDefaultPlatform@platform@v8@@YAPAVPlatform@2@H@Z)`, which I'm assuming means that I need the platform lib too? – Adam Rezich Oct 13 '14 at 18:40
  • 1
    To set a variable for GYP `-D name=value` command-line options are used. In the answer above V8 has been configured to build static libraries without ICU and snapshot support. You have to link v8_base.lib and v8_nosnapshot.lib against your application. for the recent V8 versions you also need the v8_libplatform.lib, see topic [PSA: New V8 API required to be implemented by embedders](https://groups.google.com/forum/#!topic/v8-users/KhniGgixxGM) in v8-users group – pmed Oct 14 '14 at 01:08
  • I've also added pre-built NuGet packages for V8: https://www.nuget.org/profiles/pmed They are built from the stable V8 version (5.4 at the moment), but can be easily re-built locally for any V8 branch with a single build.py script from https://github.com/pmed/v8-nuget – pmed Oct 09 '16 at 07:44
2

I know this post is quite old, but I'm going to improve pmed's answer. I'm assuming you have Python installed in your windows machine (just install it from the official page and add the Python root directory to your PATH variable) and also Git-Bash. I will be using "~/" to represent your user directory.

The easiest way to compile V8 is using depot tools, just create a directory, let's say ~/devtools/google, use git-bash to run

cd ~/devtools/google
git clone git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Then add ~/devtools/google/depot_tools to your PATH variable.

Use Power Shell to run

cd ~/devtools/google
fetch v8

That will clone the files of the V8 engine and all its dependencies gyp, cygwin, etc.

At this point you can follow the pmed's answer from step 7, just change the directories for the environment variables:

I'm using Path-to-your-installation\v8\ to represent ~/devtools/google/v8

CYGWIN_ROOT=Path-to-your-installation\v8\third_party\cygwin
PATH=%CYGWIN_ROOT%\bin;%PATH%
PYTHONPATH=Path-to-your-installation\v8\build\gyp\pylib

Then run (in PowerShell) Path-to-your-installation\v8\build\third_party\cygwin\setup_mount.bat Path-to-your-installation\v8\build\third_party\cygwin\setup_env.bat

The visual studio project will be located in Path-to-your-installation\v8\tools\gyp*

You can just open the v8 project with Visual Studio and compile it.

I had hard times trying to figure out why "fetch v8" fails somehow in Git-bash, appearently, you must use PowerShell (maybe the classic cmd too?)

PS: If you have problems compiling (unable to remap [...] cygncurses-8.dll) take a look at this post https://superuser.com/questions/194529/cygwin-fatal-error-unable-to-remap-what-does-it-mean

Regards.

Community
  • 1
  • 1
cnexans
  • 905
  • 1
  • 7
  • 20