Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Support linux ppc64le
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Apr 28, 2020
1 parent fcf04ce commit f9968de
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 7 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
dist: xenial
dist: bionic
compiler: clang
language: ruby
rvm:
- 2.7
- 2.6
- 2.5
matrix:
include:
- rvm: 2.6
os: osx
osx_image: xcode9.4.1
arch: ppc64le
fast_finish: true
addons:
apt:
packages:
- clang
- pkg-config
- python3.8
- python2.7
bundler_args: --jobs=4 --retry=3
before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then gem update bundler; fi
Expand Down
1 change: 1 addition & 0 deletions ext/libv8/arch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Arch

def libv8_arch
case Gem::Platform.local.cpu
when /^powerpc64/ then 'ppc64'
when /^arm(v6.*|v7.*)*$/ then 'arm'
when /^a(rm|arch)64$/ then 'arm64'
when /^x86$/ then 'ia32'
Expand Down
80 changes: 78 additions & 2 deletions ext/libv8/builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unless $:.include? File.expand_path("../../../lib", __FILE__)
$:.unshift File.expand_path("../../../lib", __FILE__)
end
require 'fileutils'
require 'mkmf'
require 'rbconfig'
require 'shellwords'
Expand Down Expand Up @@ -35,7 +36,10 @@ def debug_build?
end

def build_libv8!
setup_depot_tools!
setup_python!
setup_ninja!
setup_gn!
setup_build_deps!
Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
puts 'Beginning compilation. This will take some time.'
Expand All @@ -46,6 +50,10 @@ def build_libv8!
return $?.exitstatus
end

def setup_depot_tools!
ENV['PATH'] = "#{File.expand_path('../../../vendor/depot_tools', __FILE__)}:#{ENV['PATH']}"
end

def setup_python!
# If python v2 cannot be found in PATH,
# create a symbolic link to python2 the current directory and put it
Expand All @@ -58,6 +66,19 @@ def setup_python!
`ln -fs #{`which python2`.chomp} python`
ENV['PATH'] = "#{File.expand_path '.'}:#{ENV['PATH']}"
end

if arch_ppc64?
unless system 'which python3 2>&1 > /dev/null'
fail "libv8 requires python 3 to be installed in order to build"
end

# Because infra/3pp/tools/cpython3/linux-ppc64le@version:3.8.0.chromium.8 CIPD is not yet available
# fallback to host's python3
ENV['VPYTHON_BYPASS'] = 'manually managed python not supported by chrome operations'

# stub the CIPD cpython3 with host's python3
FileUtils.symlink(`which python3`.chomp, File.expand_path("../../../vendor/depot_tools/python3", __FILE__), force: true)
end
end

##
Expand All @@ -75,8 +96,6 @@ def source_version
# https://chromium.googlesource.com/v8/v8.git#Getting-the-Code
#
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"
Expand All @@ -92,8 +111,65 @@ def setup_build_deps!
end
end

##
# Build ninja for linux ppc64le
# Upstream issue: https://bugs.chromium.org/p/v8/issues/detail?id=10465
# TODO: Remove once upstream has supported ppc64le
#
def setup_ninja!
return unless arch_ppc64?

ninja_filepath = File.expand_path("../../../vendor/depot_tools/ninja-linux-ppc64le", __FILE__)
return if File.exists?(ninja_filepath)

Dir.chdir("/tmp") do
FileUtils.rm_rf("ninja")
system "git clone https://github.com/ninja-build/ninja.git -b v1.8.2" or fail "unable to git clone ninja repository"
end

Dir.chdir("/tmp/ninja") do
system "python2 ./configure.py --bootstrap" or fail "unable to build ninja"
FileUtils.mv(File.expand_path("#{Dir.pwd}/ninja"), ninja_filepath)
end

patch_filepath = File.expand_path("../../../vendor/patches/0001-support-ninja-ppc64le.patch", __FILE__)
Dir.chdir(File.expand_path('../../../vendor/depot_tools', __FILE__)) do
system "patch -p1 < #{patch_filepath}" or fail "unable to patch depot_tools/ninja"
end
end

##
# Build gn for linux ppc64le
# Upstream issue: https://bugs.chromium.org/p/v8/issues/detail?id=10467
# TODO: Remove once upstream has supported ppc64le
#
def setup_gn!
return unless arch_ppc64?

gn_filepath = File.expand_path("../../../vendor/depot_tools/gn-linux-ppc64le", __FILE__)
return if File.exists?(gn_filepath)

Dir.chdir("/tmp") do
FileUtils.rm_rf("gn")
system "git clone https://gn.googlesource.com/gn" or fail "unable to git clone gn repository"
end

Dir.chdir("/tmp/gn") do
system "python2 build/gen.py"
fail "unable to prepare gn for compilation" unless File.exists?(File.expand_path("#{Dir.pwd}/out/build.ninja"))
system "ninja -C out" or fail "unable to build gn"
FileUtils.mv(File.expand_path("#{Dir.pwd}/out/gn"), gn_filepath)
FileUtils.rm_f(File.expand_path("../../../vendor/depot_tools/gn", __FILE__))
FileUtils.symlink(gn_filepath, File.expand_path("../../../vendor/depot_tools/gn", __FILE__), force: true)
end
end

private

def arch_ppc64?
libv8_arch == "ppc64"
end

def python_version
if system 'which python 2>&1 > /dev/null'
`python -c 'import platform; print(platform.python_version())'`.chomp
Expand Down
24 changes: 24 additions & 0 deletions vendor/patches/0001-support-ninja-ppc64le.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 88070442df48a857460a68d065957d0f7efc5468 Mon Sep 17 00:00:00 2001
From: Trung LE <[email protected]>
Date: Sun, 8 Mar 2020 07:46:10 +0000
Subject: [PATCH] Support ninja ppc64le

---
ninja | 2 ++
1 file changed, 2 insertions(+)

diff --git a/ninja b/ninja
index 1a650b54..eb146a4b 100755
--- a/ninja
+++ b/ninja
@@ -28,6 +28,8 @@ case "$OS" in
# bittage of the userspace install (e.g. when running 32-bit userspace
# on x86_64 kernel)
exec "${THIS_DIR}/ninja-linux${LONG_BIT}" "$@";;
+ ppc64le)
+ exec "${THIS_DIR}/ninja-linux-ppc64le" "$@";;
*)
echo Unknown architecture \($MACHINE\) -- unable to run ninja.
print_help
--
2.17.1

0 comments on commit f9968de

Please sign in to comment.