如何为Windows编译最小的V8库? [英] How to compile the smallest possible V8 library for Windows?

查看:533
本文介绍了如何为Windows编译最小的V8库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为学校制作游戏引擎,我想使用Google的V8允许在引擎中编写JavaScript脚本.该引擎是使用Visual Studio 2013编写的,由于最终游戏不得超过50MB,因此我希望将V8文件大小的影响保持尽可能小.

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.

在Internet上寻找如何使用V8的东西,我遇到了有关V8的一系列教程,它带有针对V8的预编译的.lib文件.但是,它已经四岁了.我以为自己构建一个更新的版本可以提高性能并添加功能,所以昨天我花了很多时间在V8的构建过程中苦苦挣扎,并最终弄清楚了如何为Visual Studio编译V8:

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. 安装Google的仓库工具"
  2. 运行fetch v8
  1. Install Google's "depot tools"
  2. Run fetch v8

这为我提供了生成V8 Visual Studio解决方案所需的一切,并且当我对其进行编译时,它可以工作并生成.lib和.dll文件.但是,当我尝试创建测试解决方案并将这些库链接到该解决方案时,这令人难以置信.

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.

构建过程生成以下LIB文件:

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
  • 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

以及以下DLL:

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

昨天,在某个时候,我包含了许多库(我认为它是v8,v8_base和v8_snapshot),并将所有DLL复制到我项目的输出目录中,并且最终起作用了.但是,如上所述,我需要V8的文件大小影响尽可能小.我不需要i18​​n支持,因此没有它,有没有办法进行编译?就像我上面说的,我有一个旧版本的V8 .lib,它不需要运行DLL,它可以编译并正常工作...但是我错过了新功能和改进,因为已经有四年了老的?那么,所有这些.lib是什么意思?我找不到任何文档来说明哪些文档可以做什么或类似的事情.

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.

推荐答案

有一个页面在V8 Wiki中使用GYP 构建.简而言之,您应该使用GYP生成Visual Studio解决方案,然后进行构建.

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. 安装Python,Subversion客户端;通过命令行使其可用.
  2. 打开Visual Studio命令提示符,在那里执行下一步.
  3. 将V8源代码提取到某个目录中,例如将其命名为v8-build:

  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

用于最新版本(某些标记版本,例如 http://v8. googlecode.com/svn/tags/3.28.57 )

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

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

(请参阅v8-build/DEPS文件中的实际URL)

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

  1. 获取GYP:

  1. Fetch GYP:

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

(可选)获取ICU:

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

在命令行中提供工具:

  • 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
  • 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

使用所需选项运行GYP:

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

(请参阅v8-build \ build \ features.gypi中的允许变量)

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

  1. 使用Cygwin环境用Visual Studio生成生成的项目:

  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

结果库应位于v8-build\build目录

我使用Python脚本自动执行上述步骤.

I use a Python script to automate the steps above.

更新:我使用类似的脚本为V8构建NuGet软件包,这里是:

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

这篇关于如何为Windows编译最小的V8库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆