Class: Libv8::Builder

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

Constant Summary

Constants included from Patcher

Patcher::PATCH_DIRECTORY

Constants included from Checkout

Checkout::GYP_SVN, Checkout::GYP_Source, Checkout::V8_Source

Instance Method Summary collapse

Methods included from Patcher

patch!

Methods included from Checkout

check_git_svn!, checkout!, git?

Methods included from Make

make

Methods included from Arch

arm?, libv8_arch, rubinius?, x64?, x86_64_from_arch_flag, x86_64_from_build_cpu, x86_64_from_byte_length

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



15
16
17
# File 'ext/libv8/builder.rb', line 15

def initialize
  @compiler = choose_compiler
end

Instance Method Details

#build_libv8!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'ext/libv8/builder.rb', line 51

def build_libv8!
  checkout!
  setup_python!
  Dir.chdir(V8_Source) do
    setup_build_deps!
    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}"

    case RUBY_PLATFORM
    when /mingw/
      # use a script that will fix the paths in the generated Makefiles
      # don't use make_flags otherwise it will trigger a rebuild of the Makefiles
      system "env CXX=#{@compiler} LINK=#{@compiler} bash #{PATCH_DIRECTORY}/mingw-generate-makefiles.sh"
      command += " make #{make_target}"
    else
      command += "  #{make} #{make_flags}"
    end

    puts "Building v8 with #{command}"
    system command
  end
  return $?.exitstatus
end

#make_flags(*flags) ⇒ Object



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

def make_flags(*flags)
  # FreeBSD uses gcc 4.2 by default which leads to
  # compilation failures due to warnings about aliasing.
  # http://svnweb.freebsd.org/ports/head/lang/v8/Makefile?view=markup
  flags << "strictaliasing=off" if @compiler.is_a?(Compiler::GCC) and @compiler.version < '4.4'

  # Avoid compilation failures on the Raspberry Pi.
  flags << "vfp2=off vfp3=on" if @compiler.target.include? "arm"

  # FIXME: Determine when to activate this instead of leaving it on by
  # default.
  flags << "hardfp=on" if @compiler.target.include? "arm"

  # Fix Malformed archive issue caused by GYP creating thin archives by
  # default.
  flags << "ARFLAGS.target=crs"

  # 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'

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

#make_targetObject



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

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

#setup_build_deps!Object



93
94
95
96
97
98
# File 'ext/libv8/builder.rb', line 93

def setup_build_deps!
  # This uses the Git mirror of the svn repository used by
  # "make dependencies", instead of calling that make target
  `rm -rf build/gyp`
  `ln -fs #{GYP_Source} build/gyp`
end

#setup_python!Object



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

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