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

Support Linux PowerPC64 LE platform #296

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
dist: xenial
dist: bionic
compiler: clang
language: ruby
rvm:
- 2.7
- 2.6
- 2.5
matrix:
include:
- rvm: 2.6
arch: ppc64le
- os: osx
osx_image: xcode11.6
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: 76 additions & 4 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 @@ -36,8 +37,11 @@ def debug_build?
end

def build_libv8!
setup_depot_tools!
setup_python!
setup_build_deps!
setup_ninja!
setup_gn!
Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
puts 'Beginning compilation. This will take some time.'
generate_gn_args
Expand All @@ -47,6 +51,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 @@ -59,6 +67,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 @@ -73,11 +94,7 @@ def source_version
# Checkout all of the V8 source and its dependencies using the
# chromium depot tools.
#
# 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 @@ -93,8 +110,63 @@ def setup_build_deps!
end
end

##
# Build ninja for linux 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/chromium/issues/detail?id=1076455
# 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)
Comment on lines +159 to +160
Copy link
Contributor Author

@runlevel5 runlevel5 Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundled depot_tools/gn is a binary for amd64. We replace that with our gn

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