Class: Libv8::Builder

Inherits:
Object
  • Object
show all
Includes:
Arch, Make, Patcher
Defined in:
ext/libv8/builder.rb

Constant Summary

Constants included from Patcher

Patcher::PATCH_DIRECTORY

Instance Method Summary collapse

Methods included from Patcher

patch!

Methods included from Make

make

Methods included from Arch

libv8_arch

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



17
18
19
# File 'ext/libv8/builder.rb', line 17

def initialize
  @compiler = choose_compiler
end

Instance Method Details

#build_libv8!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'ext/libv8/builder.rb', line 57

def build_libv8!
  setup_python!
  setup_build_deps!
  Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
    fail 'No compilers available' if @compiler.nil?
    patch!
    print_build_info
    puts 'Beginning compilation. This will take some time.'

    command = "env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}"
    puts "Building v8 with #{command}"
    system command
  end
  return $?.exitstatus
end

#gyp_defines(*defines) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'ext/libv8/builder.rb', line 26

def gyp_defines(*defines)
  # Do not use an external snapshot as we don't really care for binary size
  defines << 'v8_use_external_startup_data=0'

  # Pass clang flag to GYP in order to work around GCC compilation failures
  defines << "clang=#{@compiler.is_a?(Compiler::Clang) ? '1' : '0'}"

  "GYP_DEFINES=\"#{defines.join ' '}\""
end

#make_flags(*flags) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'ext/libv8/builder.rb', line 36

def make_flags(*flags)
  # Fix Malformed archive issue caused by GYP creating thin archives by
  # default.
  flags << "standalone_static_library=1"

  # Disable i18n
  flags << 'i18nsupport=off'

  # Solaris / Smart OS requires additional -G flag to use with -fPIC
  flags << "CFLAGS=-G" if @compiler.target =~ /solaris/

  # Disable werror as this version of v8 is getting difficult to maintain
  # with it on
  flags << 'werror=no'

  # Append GYP variable definitions
  flags << gyp_defines

  "#{make_target} #{flags.join ' '}"
end

#make_targetObject



21
22
23
24
# File 'ext/libv8/builder.rb', line 21

def make_target
  profile = enable_config('debug') ? 'debug' : 'release'
  "#{libv8_arch}.#{profile}"
end

#setup_build_deps!Object

Checkout all of the V8 source and its dependencies using the chromium depot tools.

chromium.googlesource.com/v8/v8.git#Getting-the-Code



101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/libv8/builder.rb', line 101

def setup_build_deps!
  ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}"
  Dir.chdir(File.expand_path('../../../vendor', __FILE__)) do
    system "fetch v8" or fail "unable to fetch v8 source"
    Dir.chdir('v8') do
      unless system "git checkout #{source_version}"
        fail "unable to checkout source for v8 #{source_version}"
      end
      system "gclient sync" or fail "could not sync v8 build dependencies"
    end
  end
end

#setup_python!Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'ext/libv8/builder.rb', line 73

def setup_python!
  # If python v2 cannot be found in PATH,
  # create a symbolic link to python2 the current directory and put it
  # at the head of PATH. That way all commands that inherit this environment
  # will use ./python -> python2
  if python_version !~ /^2/
    unless system 'which python2 2>&1 > /dev/null'
      fail "libv8 requires python 2 to be installed in order to build, but it is currently #{python_version}"
    end
    `ln -fs #{`which python2`.chomp} python`
    ENV['PATH'] = "#{File.expand_path '.'}:#{ENV['PATH']}"
  end
end

#source_versionObject

The release tag to checkout. If this is version 4.5.95.0 of the libv8 gem, then this will be 4.5.95



91
92
93
# File 'ext/libv8/builder.rb', line 91

def source_version
  Libv8::VERSION.gsub(/\.\d+$/, '')
end