How to compile the smallest V8 library for Windows?

I am creating a game engine for school, and I want to use Google V8 to enable JavaScript scripts to work. The engine was written using Visual Studio 2013, and since the final game should not exceed 50 MB, I want to reduce the size of the V8 file as little as possible.

Looking around the Internet on how to do things with V8, I came across a series of tutorials on V8 that comes with a precompiled one. lib for V8. However, he is four years old. I assume that building a newer version as I see fit will improve performance and add features, so I spent everything yesterday struggling with the V8 build process and eventually figured out how to compile V8 for Visual Studio:

This gives me everything I need to create a 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, this is 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 turned on many of the libs (I think these are v8, v8_base and v8_snapshot) and copied all the DLLs into the output directory of my project, and it worked as a result. However, as I said above, I need the V8 with file sizes to be as small as possible. I don't need i18n support, is there any way to compile it without it? As I said above, I have an old version of V8.lib that does not need a DLL to run, and it compiles and works fine ... but am I missing new features and improvements since it's four years old? And what do all these .libs mean, anyway? I can’t find the documentation on which they do something like that.

So, I think if anyone can give instructions or point me to any documentation that helps, that would be great. Yesterday I spent almost the whole day trying to solve this problem.

+5
source share
2 answers

The V8 wiki has a Building with GYP page . In short, you should use GYP to create a Visual Studio solution, and then create it.

  • Install the Python client, Subversion; make it available from the command line.
  • Open a Visual Studio command prompt, follow these steps.
  • Extract the sources of V8 to some directory, let's say it will be called v8-build:

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

for the latest version (or 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 v8-build / DEPS file)

  1. Get GYP:

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

  2. Optional to get ICU:

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

  3. Make tools available on 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 the necessary parameters:

    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. Generate the generated project using 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 am using a Python script to automate the steps above.

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

+4
source

I know this post is pretty old, but I'm going to improve the answer. I assume that Python is installed on your Windows computer (just install it from the official page and add the Python root directory to the PATH variable), as well as Git - Bash. I will use "~ /" to represent your user directory.

The easiest way to compile V8 is to use the depot tools, just create a directory, 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 Launch

 cd ~/devtools/google fetch v8 

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

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

I use 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) the path to your installation \ v8 \ assembly \ THIRD_PARTY \ Cygwin \ setup_mount.bat the path to your installation \ v8 \ assembly \ THIRD_PARTY \ Cygwin \ setup_env.bat

The visual studio project will be located in the path to your installation \ v8 \ tools \ bench *

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

I had a hard time trying to understand why "fetch v8" somehow doesn’t work in Git - bash, apparently you should use PowerShell (maybe classic cmd too?)

PS: If you have compilation problems (it is impossible to redirect [...] cygncurses-8.dll), see this post https://superuser.com/questions/194529/cygwin-fatal-error-unable-to-remap- what-does-it-mean p>

Sincerely.

+2
source

Source: https://habr.com/ru/post/1204364/


All Articles