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.



19
20
21
# File 'ext/libv8/builder.rb', line 19

def initialize
  @compiler = choose_compiler
end

Instance Method Details

#build_libv8!Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'ext/libv8/builder.rb', line 65

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=#{Shellwords.escape @compiler.to_s} #{make} #{make_flags}"
    puts "Building v8 with #{command}"
    system command
  end
  return $?.exitstatus
end

#gyp_defines(*defines) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ext/libv8/builder.rb', line 28

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'

  # Do not use the embedded toolchain
  defines << 'use_sysroot=0'
  defines << 'linux_use_bundled_binutils=0'
  defines << 'linux_use_bundled_gold=0'
  defines << 'make_clang_dir=""'
  defines << 'clang_dir=""'

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

  # Add contents of the GYP_DEFINES environment variable if present
  defines << ENV['GYP_DEFINES'] unless ENV['GYP_DEFINES'].nil?

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

#make_flags(*flags) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'ext/libv8/builder.rb', line 48

def make_flags(*flags)
  # 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



23
24
25
26
# File 'ext/libv8/builder.rb', line 23

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'ext/libv8/builder.rb', line 109

def setup_build_deps!
  ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}"
  Dir.chdir(File.expand_path('../../../vendor', __FILE__)) do
    unless Dir.exists? 'v8'
      system "env #{gyp_defines} fetch v8" or fail "unable to fetch v8 source"
    else
      system "env #{gyp_defines} gclient fetch" or fail "could not fetch v8 build dependencies commits"
    end
    Dir.chdir('v8') do
      unless system "git checkout #{source_version}"
        fail "unable to checkout source for v8 #{source_version}"
      end
      system "env #{gyp_defines} gclient sync" or fail "could not sync v8 build dependencies"
      system "git checkout Makefile" # Work around a weird bug on FreeBSD
    end
  end
end

#setup_python!Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/libv8/builder.rb', line 81

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



99
100
101
# File 'ext/libv8/builder.rb', line 99

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