1
1
unless $:. include? File . expand_path ( "../../../lib" , __FILE__ )
2
2
$:. unshift File . expand_path ( "../../../lib" , __FILE__ )
3
3
end
4
+ require 'fileutils'
4
5
require 'mkmf'
5
6
require 'rbconfig'
6
7
require 'shellwords'
@@ -35,7 +36,10 @@ def debug_build?
35
36
end
36
37
37
38
def build_libv8!
39
+ setup_depot_tools!
38
40
setup_python!
41
+ setup_ninja!
42
+ setup_gn!
39
43
setup_build_deps!
40
44
Dir . chdir ( File . expand_path ( '../../../vendor/v8' , __FILE__ ) ) do
41
45
puts 'Beginning compilation. This will take some time.'
@@ -46,6 +50,10 @@ def build_libv8!
46
50
return $?. exitstatus
47
51
end
48
52
53
+ def setup_depot_tools!
54
+ ENV [ 'PATH' ] = "#{ File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) } :#{ ENV [ 'PATH' ] } "
55
+ end
56
+
49
57
def setup_python!
50
58
# If python v2 cannot be found in PATH,
51
59
# create a symbolic link to python2 the current directory and put it
@@ -58,6 +66,19 @@ def setup_python!
58
66
`ln -fs #{ `which python2` . chomp } python`
59
67
ENV [ 'PATH' ] = "#{ File . expand_path '.' } :#{ ENV [ 'PATH' ] } "
60
68
end
69
+
70
+ if arch_ppc64?
71
+ unless system 'which python3 2>&1 > /dev/null'
72
+ fail "libv8 requires python 3 to be installed in order to build"
73
+ end
74
+
75
+ # Because infra/3pp/tools/cpython3/linux-ppc64le@version:3.8.0.chromium.8 CIPD is not yet available
76
+ # fallback to host's python3
77
+ ENV [ 'VPYTHON_BYPASS' ] = 'manually managed python not supported by chrome operations'
78
+
79
+ # stub the CIPD cpython3 with host's python3
80
+ FileUtils . symlink ( `which python3` . chomp , File . expand_path ( "../../../vendor/depot_tools/python3" , __FILE__ ) , force : true )
81
+ end
61
82
end
62
83
63
84
##
@@ -75,8 +96,6 @@ def source_version
75
96
# https://chromium.googlesource.com/v8/v8.git#Getting-the-Code
76
97
#
77
98
def setup_build_deps!
78
- ENV [ 'PATH' ] = "#{ File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) } :#{ ENV [ 'PATH' ] } "
79
-
80
99
Dir . chdir ( File . expand_path ( '../../../vendor' , __FILE__ ) ) do
81
100
unless Dir . exists? ( 'v8' ) || File . exists? ( '.gclient' )
82
101
system "fetch v8" or fail "unable to fetch v8 source"
@@ -92,8 +111,65 @@ def setup_build_deps!
92
111
end
93
112
end
94
113
114
+ ##
115
+ # Build ninja for linux ppc64le
116
+ # Upstream issue: https://bugs.chromium.org/p/v8/issues/detail?id=10465
117
+ # TODO: Remove once upstream has supported ppc64le
118
+ #
119
+ def setup_ninja!
120
+ return unless arch_ppc64?
121
+
122
+ ninja_filepath = File . expand_path ( "../../../vendor/depot_tools/ninja-linux-ppc64le" , __FILE__ )
123
+ return if File . exists? ( ninja_filepath )
124
+
125
+ Dir . chdir ( "/tmp" ) do
126
+ FileUtils . rm_rf ( "ninja" )
127
+ system "git clone https://github.com/ninja-build/ninja.git -b v1.8.2" or fail "unable to git clone ninja repository"
128
+ end
129
+
130
+ Dir . chdir ( "/tmp/ninja" ) do
131
+ system "python2 ./configure.py --bootstrap" or fail "unable to build ninja"
132
+ FileUtils . mv ( File . expand_path ( "#{ Dir . pwd } /ninja" ) , ninja_filepath )
133
+ end
134
+
135
+ patch_filepath = File . expand_path ( "../../../vendor/patches/0001-support-ninja-ppc64le.patch" , __FILE__ )
136
+ Dir . chdir ( File . expand_path ( '../../../vendor/depot_tools' , __FILE__ ) ) do
137
+ system "patch -p1 < #{ patch_filepath } " or fail "unable to patch depot_tools/ninja"
138
+ end
139
+ end
140
+
141
+ ##
142
+ # Build gn for linux ppc64le
143
+ # Upstream issue: https://bugs.chromium.org/p/v8/issues/detail?id=10467
144
+ # TODO: Remove once upstream has supported ppc64le
145
+ #
146
+ def setup_gn!
147
+ return unless arch_ppc64?
148
+
149
+ gn_filepath = File . expand_path ( "../../../vendor/depot_tools/gn-linux-ppc64le" , __FILE__ )
150
+ return if File . exists? ( gn_filepath )
151
+
152
+ Dir . chdir ( "/tmp" ) do
153
+ FileUtils . rm_rf ( "gn" )
154
+ system "git clone https://gn.googlesource.com/gn" or fail "unable to git clone gn repository"
155
+ end
156
+
157
+ Dir . chdir ( "/tmp/gn" ) do
158
+ system "python2 build/gen.py"
159
+ fail "unable to prepare gn for compilation" unless File . exists? ( File . expand_path ( "#{ Dir . pwd } /out/build.ninja" ) )
160
+ system "ninja -C out" or fail "unable to build gn"
161
+ FileUtils . mv ( File . expand_path ( "#{ Dir . pwd } /out/gn" ) , gn_filepath )
162
+ FileUtils . rm_f ( File . expand_path ( "../../../vendor/depot_tools/gn" , __FILE__ ) )
163
+ FileUtils . symlink ( gn_filepath , File . expand_path ( "../../../vendor/depot_tools/gn" , __FILE__ ) , force : true )
164
+ end
165
+ end
166
+
95
167
private
96
168
169
+ def arch_ppc64?
170
+ libv8_arch == "ppc64"
171
+ end
172
+
97
173
def python_version
98
174
if system 'which python 2>&1 > /dev/null'
99
175
`python -c 'import platform; print(platform.python_version())'` . chomp
0 commit comments