|
5 | 5 | require 'rbconfig' |
6 | 6 | require 'shellwords' |
7 | 7 | require 'libv8/version' |
8 | | -require File.expand_path '../compiler', __FILE__ |
9 | 8 | require File.expand_path '../arch', __FILE__ |
10 | | -require File.expand_path '../make', __FILE__ |
11 | | -require File.expand_path '../patcher', __FILE__ |
12 | 9 |
|
13 | 10 | module Libv8 |
14 | 11 | class Builder |
15 | 12 | include Libv8::Arch |
16 | | - include Libv8::Make |
17 | | - include Libv8::Patcher |
18 | 13 |
|
19 | | - def initialize |
20 | | - @compiler = choose_compiler |
| 14 | + def gn_args |
| 15 | + %W(is_debug=#{debug_build? ? 'true' : 'false'} |
| 16 | + symbol_level=#{debug_build? ? '-1' : '0'} |
| 17 | + is_component_build=false |
| 18 | + v8_monolithic=true |
| 19 | + v8_use_external_startup_data=false |
| 20 | + target_cpu="#{libv8_arch}" |
| 21 | + v8_target_cpu="#{libv8_arch}" |
| 22 | + treat_warnings_as_errors=false |
| 23 | + v8_enable_i18n_support=false).join(' ') |
21 | 24 | end |
22 | 25 |
|
23 | | - def make_target |
24 | | - profile = enable_config('debug') ? 'debug' : 'release' |
25 | | - "#{libv8_arch}.#{profile}" |
| 26 | + def generate_gn_args |
| 27 | + system "gn gen out.gn/libv8 --args='#{gn_args}'" |
26 | 28 | end |
27 | 29 |
|
28 | | - def gyp_defines(*defines) |
29 | | - # Do not use an external snapshot as we don't really care for binary size |
30 | | - defines << 'v8_use_external_startup_data=0' |
31 | | - |
32 | | - # Do not use the embedded toolchain |
33 | | - defines << 'use_sysroot=0' |
34 | | - defines << 'linux_use_bundled_binutils=0' |
35 | | - defines << 'linux_use_bundled_gold=0' |
36 | | - defines << 'make_clang_dir=""' |
37 | | - defines << 'clang_dir=""' |
38 | | - |
39 | | - # Pass clang flag to GYP in order to work around GCC compilation failures |
40 | | - defines << "clang=#{@compiler.is_a?(Compiler::Clang) ? '1' : '0'}" |
41 | | - |
42 | | - # Add contents of the GYP_DEFINES environment variable if present |
43 | | - defines << ENV['GYP_DEFINES'] unless ENV['GYP_DEFINES'].nil? |
44 | | - |
45 | | - "GYP_DEFINES=\"#{defines.join ' '}\"" |
46 | | - end |
47 | | - |
48 | | - def make_flags(*flags) |
49 | | - # Disable i18n |
50 | | - flags << 'i18nsupport=off' |
51 | | - |
52 | | - # Solaris / Smart OS requires additional -G flag to use with -fPIC |
53 | | - flags << "CFLAGS=-G" if @compiler.target =~ /solaris/ |
54 | | - |
55 | | - # Disable werror as this version of v8 is getting difficult to maintain |
56 | | - # with it on |
57 | | - flags << 'werror=no' |
58 | | - |
59 | | - # Append GYP variable definitions |
60 | | - flags << gyp_defines |
61 | | - |
62 | | - # Append manually specified MAKEFLAGS |
63 | | - flags << ENV['MAKEFLAGS'] if ENV['MAKEFLAGS'] |
64 | | - ENV['MAKEFLAGS'] = nil |
65 | | - |
66 | | - "#{make_target} #{flags.join ' '}" |
| 30 | + def debug_build? |
| 31 | + enable_config('debug') |
67 | 32 | end |
68 | 33 |
|
69 | 34 | def build_libv8! |
70 | 35 | setup_python! |
71 | 36 | setup_build_deps! |
72 | 37 | Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do |
73 | | - fail 'No compilers available' if @compiler.nil? |
74 | | - patch! |
75 | | - print_build_info |
76 | 38 | puts 'Beginning compilation. This will take some time.' |
| 39 | + generate_gn_args |
77 | 40 |
|
78 | | - command = "env CXX=#{Shellwords.escape @compiler.to_s} #{make} #{make_flags}" |
79 | | - puts "Building v8 with #{command}" |
80 | | - system command |
| 41 | + system 'ninja -v -C out.gn/libv8 v8_monolith' |
81 | 42 | end |
82 | 43 | return $?.exitstatus |
83 | 44 | end |
@@ -112,56 +73,30 @@ def source_version |
112 | 73 | # |
113 | 74 | def setup_build_deps! |
114 | 75 | ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}" |
| 76 | + |
115 | 77 | Dir.chdir(File.expand_path('../../../vendor', __FILE__)) do |
116 | | - unless Dir.exists? 'v8' |
117 | | - system "env #{gyp_defines} fetch v8" or fail "unable to fetch v8 source" |
118 | | - else |
119 | | - system "env #{gyp_defines} gclient fetch" or fail "could not fetch v8 build dependencies commits" |
| 78 | + unless Dir.exists?('v8') || File.exists?('.gclient') |
| 79 | + system "fetch v8" or fail "unable to fetch v8 source" |
120 | 80 | end |
| 81 | + |
121 | 82 | Dir.chdir('v8') do |
| 83 | + system 'git fetch origin' |
122 | 84 | unless system "git checkout #{source_version}" |
123 | 85 | fail "unable to checkout source for v8 #{source_version}" |
124 | 86 | end |
125 | | - system "env #{gyp_defines} gclient sync" or fail "could not sync v8 build dependencies" |
126 | | - system "git checkout Makefile" # Work around a weird bug on FreeBSD |
| 87 | + system "gclient sync" or fail "could not sync v8 build dependencies" |
127 | 88 | end |
128 | 89 | end |
129 | 90 | end |
130 | 91 |
|
131 | 92 | private |
132 | 93 |
|
133 | | - def choose_compiler |
134 | | - compiler = if with_config('cxx') || ENV['CXX'] |
135 | | - with_config('cxx') || ENV['CXX'] |
136 | | - else |
137 | | - begin |
138 | | - MakeMakefile::CONFIG['CXX'] # stdlib > 2.0.0 |
139 | | - rescue NameError |
140 | | - RbConfig::CONFIG['CXX'] # stdlib < 2.0.0 |
141 | | - end |
142 | | - end |
143 | | - |
144 | | - Libv8::Compiler.type_of(compiler).new compiler |
145 | | - end |
146 | | - |
147 | 94 | def python_version |
148 | 95 | if system 'which python 2>&1 > /dev/null' |
149 | 96 | `python -c 'import platform; print(platform.python_version())'`.chomp |
150 | 97 | else |
151 | 98 | "not available" |
152 | 99 | end |
153 | 100 | end |
154 | | - |
155 | | - def print_build_info |
156 | | - puts "Compiling v8 for #{libv8_arch}" |
157 | | - |
158 | | - puts "Using python #{python_version}" |
159 | | - |
160 | | - puts "Using compiler: #{@compiler} (#{@compiler.name} version #{@compiler.version})" |
161 | | - unless @compiler.compatible? |
162 | | - warn "Unable to find a compiler officially supported by v8." |
163 | | - warn "It is recommended to use clang v3.5 or GCC v4.8 or higher" |
164 | | - end |
165 | | - end |
166 | 101 | end |
167 | 102 | end |
0 commit comments