Class: Libv8::Builder

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

Instance Method Summary collapse

Methods included from Arch

libv8_arch

Instance Method Details

#build_libv8!Object



38
39
40
41
42
43
44
45
46
47
48
# File 'ext/libv8/builder.rb', line 38

def build_libv8!
  setup_python!
  setup_build_deps!
  Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
    puts 'Beginning compilation. This will take some time.'
    generate_gn_args

    system 'ninja -v -C out.gn/libv8 v8_monolith'
  end
  return $?.exitstatus
end

#debug_build?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'ext/libv8/builder.rb', line 34

def debug_build?
  enable_config('debug') || Libv8::VERSION.include?('beta')
end

#generate_gn_argsObject



30
31
32
# File 'ext/libv8/builder.rb', line 30

def generate_gn_args
  system "gn gen out.gn/libv8 --args='#{gn_args}'"
end

#gn_argsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/libv8/builder.rb', line 14

def gn_args
  %W(clang_use_chrome_plugins=false
     linux_use_bundled_binutils=false
     use_custom_libcxx=false
     use_sysroot=false
     is_debug=#{debug_build? ? 'true' : 'false'}
     symbol_level=#{debug_build? ? '-1' : '0'}
     is_component_build=false
     v8_monolithic=true
     v8_use_external_startup_data=false
     target_cpu="#{libv8_arch}"
     v8_target_cpu="#{libv8_arch}"
     treat_warnings_as_errors=false
     icu_use_data_file=false).join(' ')
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



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

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') || File.exists?('.gclient')
      system "fetch v8" or fail "unable to fetch v8 source"
    end

    Dir.chdir('v8') do
      system 'git fetch origin'
      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



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

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



68
69
70
# File 'ext/libv8/builder.rb', line 68

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