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

查看:23
本文介绍了如何为 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.

在互联网上寻找如何使用 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 的"depot tools"
  2. 运行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

以及以下 DLL:

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

昨天的某个时候,我包含了许多库(我认为是 v8、v8_base 和 v8_snapshot)并将所有 DLL 复制到我的项目的输出目录中,最终它起作用了.但是,正如我上面所说,我需要 V8 对文件大小的影响尽可能小.我不需要 i18n 支持,那么有没有办法在没有它的情况下进行编译?就像我上面说的,我有一个旧版本的 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

(参见 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

使工具在命令行中可用:

Make tools available in the command line:

  • set CYGWIN_ROOT=%cd%v8-build hird_partycygwin
  • 设置PATH=%CYGWIN_ROOT%in;%PATH%
  • 设置 PYTHONPATH=%cd%v8-buildgyppylib
  • v8-build hird_partycygwinsetup_mount.bat
  • v8-build hird_partycygwinsetup_env.bat

使用所需选项运行 GYP:

Run GYP with desired options:

python v8-builduildgyp_v8 -Dcomponent=static_library -Dtarget_arch=x64 -v8_enable_i18n_support=0 -Dv8_use_snapshot=0

(参见 v8-builduildfeatures.gypi 中允许的变量)

(see allowed variables in v8-builduildfeatures.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 oolsgypv8.vcxproj

结果库应该在 v8-builduild 目录

Result libraries should be in the v8-builduild directory

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

I use a Python script to automate the steps above.

更新:我使用类似的脚本为 V8 构建 NuGet 包,这里是:https://github.com/pmed/v8-nuget/blob/master/build.py

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天全站免登陆