【V8.Internal】Building V8 from bootstrap

Prerequisite

  • depot_tools
    A collection of tools used to sync repository with the huge chromium project. get it here

  • gyp
    A python module used to generate building system, that is, GYP is a meta generating tool. similar to the previous SCons.
    get it here

  • git
    An excellent source code management tool, developed by Linus Torvalds, the Father of Linux.

Process

Retrieve the code

  • From my github

  • or From official repository by depot_tool

    fetch v8

NOTE: setup depot_tool to PATH environment variable.

Sync with latest dependencies

    cd v8 && gclient sync

Generate projects and Building

For windows

1) Setup visual studio version, as c++11 required, set it up to 2013, run

set GYP_MSVS_VERSION=2015

2) Setup PATH, add cygwin( to generate global_intermediate), python etc, run

third_party/cygwin/setup_env.bat

3) Generate vs projects by GYP command(if need, install gyp for python), run

third_party/python/python.exe build\gyp_v8 -Dtarget_arch=ia32 -Dlibrary=static_library [-Dv8_use_snapshot='false']

4) Done

open `build\all.sln' to build

For linux

1) Generate Makefiles for GNU make( >= GLIBC-2.14), run

python build\gyp_v8

2) Make it, run

make ia32.release

Example Test

V8_HelloWorld

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "include/libplatform/libplatform.h"
#include "include/v8.h"

using namespace v8;

class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
 public:
  virtual void* Allocate(size_t length) {
    void* data = AllocateUninitialized(length);
    return data == NULL ? data : memset(data, 0, length);
  }
  virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  virtual void Free(void* data, size_t) { free(data); }
};


int main(int argc, char* argv[]) {
  // Link with v8_nosnapshot, comment following line.
  //V8::InitializeExternalStartupData(argv[0]);

  Platform* platform = platform::CreateDefaultPlatform();
  V8::InitializePlatform(platform);

  // Initialize V8.
  V8::Initialize();

  // Create a new Isolate and make it the current one.
  ArrayBufferAllocator allocator;
  Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = &allocator;
  Isolate* isolate = Isolate::New(create_params);
  {
    Isolate::Scope isolate_scope(isolate);

    // Create a stack-allocated handle scope.
    HandleScope handle_scope(isolate);

    // Create a new context.
    Local<Context> context = Context::New(isolate);

    // Enter the context for compiling and running the hello world script.
    Context::Scope context_scope(context);

    // Create a string containing the JavaScript source code.
    Local<String> source =
        String::NewFromUtf8(isolate, "'Hello' + ', World!'",
                            NewStringType::kNormal).ToLocalChecked();

    // Compile the source code.
    Local<Script> script = Script::Compile(context, source).ToLocalChecked();

    // Run the script to get the result.
    Local<Value> result = script->Run(context).ToLocalChecked();

    // Convert the result to an UTF8 string and print it.
    String::Utf8Value utf8(result);
    printf("%s\n", *utf8);
  }

  // Dispose the isolate and tear down V8.
  isolate->Dispose();
  V8::Dispose();
  V8::ShutdownPlatform();
  delete platform;
  return 0;
}

Compile

cl /c /I.. /I..\include \     /I..\third_party\icu\source\i18n \     /I..\third_party\icu\source\common \     /I.. /I..\include \     /I..\third_party\icu\source\i18n \     /I..\third_party\icu\source\common \     /Zi /W3 /WX /Od /Oy- \     /D V8_IMMINENT_DEPRECATION_WARNINGS \     /D _CRT_SECURE_NO_DEPRECATE \     /D _CRT_NONSTDC_NO_DEPRECATE \     /D _USING_V110_SDK71_ \     /D _HAS_EXCEPTIONS=0 \     /D V8_TARGET_ARCH_IA32 \     /D WIN32 \     /D V8_DEPRECATION_WARNINGS \     /D V8_I18N_SUPPORT \     /D V8_USE_EXTERNAL_STARTUP_DATA \     /D U_USING_ICU_NAMESPACE=0 \     /D U_ENABLE_DYLOAD=0 \     /D U_STATIC_IMPLEMENTATION \     /D ENABLE_DISASSEMBLER \     /D V8_ENABLE_CHECKS \     /D OBJECT_PRINT \     /D VERIFY_HEAP \     /D DEBUG \     /D TRACE_MAPS \     /D ENABLE_HANDLE_ZAPPING \     /D ENABLE_SLOW_DCHECKS \     /D V8_IMMINENT_DEPRECATION_WARNINGS \     /D _CRT_SECURE_NO_DEPRECATE \     /D _CRT_NONSTDC_NO_DEPRECATE \     /D _USING_V110_SDK71_ \     /D _HAS_EXCEPTIONS=0 \     /D V8_TARGET_ARCH_IA32 \     /D WIN32 \     /D V8_DEPRECATION_WARNINGS \     /D V8_I18N_SUPPORT \     /D V8_USE_EXTERNAL_STARTUP_DATA \     /D U_USING_ICU_NAMESPACE=0 \     /D U_ENABLE_DYLOAD=0 \     /D U_STATIC_IMPLEMENTATION \     /D ENABLE_DISASSEMBLER \     /D V8_ENABLE_CHECKS \     /D OBJECT_PRINT \     /D VERIFY_HEAP \     /D DEBUG \     /D TRACE_MAPS \     /D ENABLE_HANDLE_ZAPPING \     /D ENABLE_SLOW_DCHECKS \     /D _UNICODE \     /D UNICODE \     /Gm- /MTd /GS /Gy /fp:precise \     /Zc:wchar_t /Zc:forScope /Zc:inline /GR- \     /Fo"..\build\Debug\obj\hello-world\\" \     /Fd"..\build\Debug\obj\hello-world\vc140.pdb" \     /Gd /TP \     /wd4091 /wd4127 /wd4351 /wd4355 /wd4503 \     /wd4589 /wd4611 /wd4100 /wd4121 \     /wd4244 /wd4302 /wd4309 /wd4311 /wd4312 \     /wd4481 /wd4505 /wd4510 /wd4512 \     /wd4610 /wd4800 /wd4838 /wd4995 /wd4996 \     /wd4456 /wd4457 /wd4458 /wd4459 \     /wd4091 /wd4127 /wd4351 /wd4355 /wd4503 \     /wd4589 /wd4611 /wd4100 /wd4121 \     /wd4244 /wd4302 /wd4309 /wd4311 /wd4312 \     /wd4481 /wd4505 /wd4510 /wd4512 \     /wd4610 /wd4800 /wd4838 /wd4995 /wd4996 \     /wd4456 /wd4457 /wd4458 /wd4459 \     /analyze- \     /errorReport:prompt \     /MP /arch:SSE2 /MP /arch:SSE2 \     "hello-world.cc"
link "/OUT:..\build\Debug\hello-world.exe" \     /VERBOSE:Lib \     /INCREMENTAL \     ws2_32.lib advapi32.lib winmm.lib ws2_32.lib \     /MANIFEST "/MANIFESTUAC:level='asInvoker' uiAccess='false'" \     /manifest:embed \     /Debug \     "/PDB:..\build\Debug\hello-world.pdb" \     "/SUBSYSTEM:CONSOLE,5.01" \     /TLBID:1 /DYNAMICBASE /FIXED:NO /NXCOMPAT \     "/IMPLIB:..\build\Debug\lib\hello-world.lib" \     /MACHINE:X86 /SAFESEH \     "..\build\Debug\obj\hello-world\hello-world.obj" \     E:\workspace\v8\build\Debug\lib\v8_libplatform.lib \     E:\workspace\v8\build\Debug\lib\icui18n.lib \     E:\workspace\v8\build\Debug\lib\icuuc.lib \     E:\workspace\v8\build\Debug\lib\v8_base.lib \     E:\workspace\v8\build\Debug\lib\v8_libbase.lib \     E:\workspace\v8\build\Debug\lib\v8_nosnapshot.lib

Run

./hello_world
Hello, World!
Press any key to continue . . .

你可能感兴趣的:(ECMAScript,javascrip,V8,building,GYP)