Building V8

https://code.google.com/p/v8/wiki/BuildingWithGYP

Building V8

V8 is built with the help of GYP. GYP is a meta build system of sorts, as it generates build files for a number of other build systems. How you build therefore depends on what "back-end" build system and compiler you're using. The instructions below assume that you already have acheckout of V8.

Prerequisite: Installing GYP

First, you need GYP itself. On systems that have make (Linux, Mac, most other Unixes), this is as easy as:

make dependencies

Otherwise (e.g. on Windows), you need to get GYP manually. From the root of your V8 checkout, run:

svn co http://gyp.googlecode.com/svn/trunk build/gyp

Building

GCC + make

Requires GNU make 3.81 or later. Should work with any GCC 4.x version.

Build instructions

The top-level Makefile defines a number of targets for each target architecture (ia32, x64, arm) and mode (debug or release). So your basic command for building is:

make ia32.release

or analogously for the other architectures and modes. You can build both debug and release binaries with just one command:

make ia32

To automatically build in release mode for the host architecture:

make native

You can also can build all architectures in a given mode at once:

make release

Or everything:

make

Optional parameters

  • -j specifies the number of parallel build processes. Set it (roughly) to the number of CPU cores your machine has. The GYP/make based V8 build also supports distcc, so you can compile with -j100 or so, provided you have enough machines around.
  • OUTDIR=foo specifies where the compiled binaries go. It defaults to ./out/. In this directory, a subdirectory will be created for each architecture and mode. You will find the d8 shell's binary in foo/ia32.release/d8, for example.
  • library=shared or component=shared_library (the two are completely equivalent) builds V8 as a shared library (libv8.so).
  • soname_version=1.2.3 is only relevant for shared library builds and configures the SONAME of the library. Both the SONAME and the filename of the library will be libv8.so.1.2.3 if you specify this. Due to a peculiarity in GYP, if you specify a custom SONAME, the library's path will no longer be encoded in the binaries, so you'll have to run d8 as follows:
    LD_LIBRARY_PATH=out/ia32.release/lib.target out/ia32.release/d8
  • console=readline enables readline support for the d8 shell. You need readline development headers for this (libreadline-dev on Ubuntu).
  • disassembler=on enables the disassembler for release mode binaries (it's always enabled for debug binaries). This is useful if you want to inspect generated machine code.
  • snapshot=off disables building with a heap snapshot. Compiling will be a little faster, but V8’s start up will be slightly slower.
  • gdbjit=on enables GDB JIT support.
  • liveobjectlist=on enables the Live Object List feature.
  • vfp3=off is only relevant for ARM builds with snapshot and disables the use of VFP3 instructions in the snapshot.
  • debuggersupport=off disables the javascript debugger.
  • werror=no omits the -Werror flag. This is especially useful for not officially supported C++ compilers (e.g. newer versions of the GCC) so that compile warnings are ignored.
  • strictaliasing=off passes the -fno-strict-aliasing flag to GCC. This may help to work around build failures on officially unsupported platforms and/or GCC versions.
  • regexp=interpreted chooses the interpreted mode of the irregexp regular expression engine instead of the native code mode.
  • hardfp=on creates "hardfp" binaries on ARM.

Clang + make

Building with clang works on both Mac and Linux. You can use the same Makefile and instructions as when building with GCC, just a few extra steps are required first:

export CC=/path/to/clang
export CXX=/path/to/clang++
export GYP_DEFINES="clang=1"

After that, you can simply call make with any target as discussed in the GCC + make section.

Cross-compiling

Similar to building with Clang, you can also use a cross-compiler. Just export your toolchain (CXX/LINK environment variables should be enough) and compile. For example:

export CXX=/path/to/cross-compile-g++
export LINK=/path/to/cross-compile-g++
make arm.release

Xcode

From the root of your V8 checkout, run either of:

build/gyp_v8 -Dtarget_arch=ia32
build/gyp_v8 -Dtarget_arch=x64

This will generate Xcode project files in build/ that you can then either open with Xcode or compile directly from the command line:

xcodebuild -project build/all.xcodeproj -configuration Release
xcodebuild -project build/all.xcodeproj

Note: If you have configured your GYP_GENERATORS environment variable, either unset it, or set it to xcode for this to work.

Custom build settings

You can export the GYP_DEFINES environment variable in your shell to configure custom build options. The syntax is GYP_DEFINES="-Dvariable1=value1 -Dvariable2=value2" and so on for as many variables as you wish. Possibly interesting options include:

  • -Dcomponent=shared_library (see library=shared in the GCC + make section above)
  • -Dconsole=readline (see console=readline)
  • -Dv8_enable_disassembler=1 (see disassembler=on)
  • -Dv8_use_snapshot='false' (see snapshot=off)
  • -Dv8_enable_gdbjit=1 (see gdbjit=on)
  • -Dv8_use_liveobjectlist=true (see liveobjectlist=on)

Visual Studio

Prerequisites

On Windows, you need to install some additional dependencies first:

  1. Python. You have several options:
    • Use the Windows installer from http://python.org/download
    • Check out the version provided by Chromium:

      svn co http://src.chromium.org/svn/trunk/tools/third_party/python_26@89111 third_party/python_26
    • Use a cygwin shell instead of the normal Windows command prompt.
    Either way, it is recommended to put python.exe into your PATH.
  2. The Chromium-provided cygwin installation. This is absolutely required, your build will fail if you don't do this:
    svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@66844 third_party/cygwin

Building

  • If you use the command prompt:
    1. Generate project files:
      python build\gyp_v8
      Specify the path to  python.exe if you don't have it in your PATH. Append  -Dtarget_arch=x64 if you want to build 64bit binaries (you will need a 64bit version of Visual Studio to do this). If you switch between ia32 and x64 targets, you may have to manually delete the generated .vcproj/.sln files before regenerating them. Example:
      third_party/python_26/python.exe build\gyp_v8 -Dtarget_arch=x64
    2. Build:
      Either open  build\All.sln in Visual Studio, or compile on the command line as follows (adapt the path as necessary, or simply put  devenv.com in your PATH):
      "c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" /build Release build\All.sln
      Replace  Release with  Debug to build in Debug mode. The built binaries will be in build\Release\ or build\Debug\.
  • If you use cygwin, the workflow is the same, but the syntax is slightly different:
    1. Generate project files:
      build/gyp_v8
      This will spit out a bunch of warnings about missing input files, but it seems to be OK to ignore them. (If you have time to figure this out, we'd happily accept a patch that makes the warnings go away!)
    2. Build:
      /cygdrive/c/Program\ Files\ (x86)/Microsoft\ Visual\ Studio\ 9.0/Common7/IDE/devenv.com /build Release build/all.sln

Custom build settings

See the "custom build settings" section for Xcode above.

Running tests

You can abuse the test driver's --buildbot flag to make it find the executables where MSVC puts them:

python tools/run-tests.py --buildbot --outdir build --arch ia32 --mode Release

MinGW

Building on MinGW is not officially supported, but it is possible. You even have two options:

Option 1: With Cygwin Installed

Requirements:

  • MinGW
  • Cygwin, including Python
  • Python from www.python.org (yes, you need two Python installations!)

Building:

  1. Open a MinGW shell
  2. export PATH=$PATH:/c/cygwin/bin (or wherever you installed Cygwin)
  3. make ia32.release -j8

Running tests:

  1. Open a MinGW shell
  2. export PATH=/c/Python27:$PATH (or wherever you installed Python)
  3. make ia32.release.check -j8

Option 2: Without Cygwin, just MinGW

Requirements:

  • MinGW
  • Python from www.python.org

Building and testing:

  1. Open a MinGW shell
  2. tools/mingw-generate-makefiles.sh (re-run this any time a *.gyp* file changed, such as after updating your checkout)
  3. make ia32.release (unfortunately -jX doesn't seem to work here)
  4. make ia32.release.check -j8

Final Note

If you have problems or questions, please file bugs at code.google.com/p/v8/issues or send mail to [email protected]. Comments on this page are likely to go unnoticed and unanswered.

你可能感兴趣的:(Building V8)