|
1 | | -unless $:.include? File.expand_path("../../../lib", __FILE__) |
2 | | - $:.unshift File.expand_path("../../../lib", __FILE__) |
3 | | -end |
4 | 1 | require 'mkmf' |
5 | 2 | require 'rbconfig' |
6 | 3 | require 'shellwords' |
7 | 4 | require 'libv8/version' |
8 | | -require File.expand_path '../compiler', __FILE__ |
9 | | -require File.expand_path '../arch', __FILE__ |
10 | | -require File.expand_path '../make', __FILE__ |
11 | | -require File.expand_path '../patcher', __FILE__ |
12 | 5 |
|
13 | 6 | module Libv8 |
14 | 7 | class Builder |
15 | | - include Libv8::Arch |
16 | | - include Libv8::Make |
17 | | - include Libv8::Patcher |
| 8 | + def gn_args |
| 9 | + 'is_debug=false is_component_build=false v8_monolithic=true v8_use_external_startup_data=false target_cpu="x64" v8_target_cpu="x64" treat_warnings_as_errors=false v8_enable_i18n_support=false' |
| 10 | + end |
18 | 11 |
|
19 | | - def initialize |
20 | | - @compiler = choose_compiler |
| 12 | + def generate_gn_args |
| 13 | + system "gn gen out.gn/libv8 --args='#{gn_args}'" |
21 | 14 | end |
22 | 15 |
|
23 | 16 | def make_target |
24 | 17 | profile = enable_config('debug') ? 'debug' : 'release' |
25 | 18 | "#{libv8_arch}.#{profile}" |
26 | 19 | end |
27 | 20 |
|
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 ' '}" |
67 | | - end |
68 | | - |
69 | 21 | def build_libv8! |
70 | 22 | setup_python! |
71 | 23 | setup_build_deps! |
72 | 24 | Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do |
73 | | - fail 'No compilers available' if @compiler.nil? |
74 | | - patch! |
75 | | - print_build_info |
76 | 25 | puts 'Beginning compilation. This will take some time.' |
| 26 | + generate_gn_args |
77 | 27 |
|
78 | | - command = "env CXX=#{Shellwords.escape @compiler.to_s} #{make} #{make_flags}" |
79 | | - puts "Building v8 with #{command}" |
80 | | - system command |
| 28 | + system 'ninja -v -C out.gn/libv8 v8_monolith' |
81 | 29 | end |
82 | 30 | return $?.exitstatus |
83 | 31 | end |
@@ -112,56 +60,30 @@ def source_version |
112 | 60 | # |
113 | 61 | def setup_build_deps! |
114 | 62 | ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}" |
| 63 | + |
115 | 64 | 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" |
| 65 | + unless Dir.exists?('v8') || File.exists?('.gclient') |
| 66 | + system "fetch v8" or fail "unable to fetch v8 source" |
120 | 67 | end |
| 68 | + |
121 | 69 | Dir.chdir('v8') do |
| 70 | + system 'git fetch origin' |
122 | 71 | unless system "git checkout #{source_version}" |
123 | 72 | fail "unable to checkout source for v8 #{source_version}" |
124 | 73 | 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 |
| 74 | + system "gclient sync" or fail "could not sync v8 build dependencies" |
127 | 75 | end |
128 | 76 | end |
129 | 77 | end |
130 | 78 |
|
131 | 79 | private |
132 | 80 |
|
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 | 81 | def python_version |
148 | 82 | if system 'which python 2>&1 > /dev/null' |
149 | 83 | `python -c 'import platform; print(platform.python_version())'`.chomp |
150 | 84 | else |
151 | 85 | "not available" |
152 | 86 | end |
153 | 87 | 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 | 88 | end |
167 | 89 | end |
0 commit comments