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

[WIP] Upgrade to upstream v8 6.7 #258

Merged
merged 15 commits into from
Jul 6, 2018
Merged
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
44 changes: 10 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
language: ruby
rvm:
- 2.4.2
- 2.3.5
- 2.2
- rbx
- 2.5
- 2.4
- rubinius-3
matrix:
include:
- rvm: 2.4.0
- rvm: 2.5.1
os: osx
osx_image: xcode8.2
- rvm: 2.4.0
osx_image: xcode9.4.1
- rvm: 2.5.1
os: osx
osx_image: xcode7.3
- os: osx
osx_image: xcode6.4
- os: osx
osx_image: xcode9.1
- rvm: system
os: osx
osx_image: xcode8.2
- rvm: system
os: osx
osx_image: xcode7.3
- rvm: system
os: osx
osx_image: xcode6.4
- rvm: system
os: osx
osx_image: xcode9.1
- rvm: ruby-2.3.1-clang
env: CXX=clang++
- rvm: 1.9.3
osx_image: xcode9.2
allow_failures:
- rvm: 1.9.3
- rvm: rbx
- os: osx
osx_image: xcode6.4
- rvm: rubinius-3
fast_finish: true
dist: trusty
addons:
apt:
packages:
Expand All @@ -51,7 +27,7 @@ before_install:
- if [ "$TRAVIS_OS_NAME" == "osx" -a "$TRAVIS_RUBY_VERSION" != "system" ]; then gem update bundler; fi
script:
- git submodule update --init
- MAKEFLAGS+=-j8 bundle exec rake spec binary --trace
- bundle exec rake spec binary --trace
deploy:
provider: releases
file: $(git ls-files -o pkg | head -1)
Expand All @@ -60,7 +36,7 @@ deploy:
skip_cleanup: true
on:
tags: true
condition: $TRAVIS_OS_NAME = osx
# condition: $TRAVIS_OS_NAME = osx
cache:
bundler: true
notifications:
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### v6.7.288.46.0, v6.7.288.46.1 - 2017-07-06

* Update upstream v8 version to 6.7.288.46 (https://github.com/cowboyd/libv8/pull/258)
Due to the change in V8's build system this causes several major changes until
we're able to find a way to reimplement the necessary functionality. The changes
are listed below.
* Remove the option to specify --with-cxx. For now V8 is built with the
toolchain provided by the build system (https://github.com/cowboyd/libv8/issues/260)
* Remove the option to specify --with-system-v8. It was making it too easy for
the user to shot themself in the foot.
* Drop ARM support. The V8 build system is not working natively on ARM and for
some reason crosscompilation produces X86 binaries
(https://github.com/cowboyd/libv8/issues/261)
* Drop FreeBSD support. Chromium's depot_tools do not support FreeBSD at this
point. (https://github.com/cowboyd/libv8/issues/253)

### v6.3.292.48.0, v6.3.292.48.1 - 2017-12-20

* Update upstream v8 version to 6.3.292.48
Expand Down
72 changes: 9 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source and binary form.
### Why?

The goal of libv8 is two fold: provide a binary gem containing the a
pre-compiled libv8.a for as many platforms as possible while at the
pre-compiled libv8_monolith.a for as many platforms as possible while at the
same time supporting for an automated compilation for all others.

Not only does this drastically reduce gem install times, but it also
Expand All @@ -23,13 +23,12 @@ opens the door for supporting Windows.
That depends on your platform. Right now, we support the following
platforms.

* x86_64-darwin-17
* x86_64-darwin-16
* x86_64-darwin-15
* x86_64-darwin-14
* x86_64-linux
* x86-linux
* x86_64-freebsd-10
* x86_64-freebsd-11

If you don't see your platform on this list, first, make sure that it
installs from source, and second talk to us about setting up a binary
Expand Down Expand Up @@ -74,28 +73,17 @@ source-based distribution

> This step release system is a workaround to carlhuda/bundler#1537

##### Use with different standard C libraries

The Linux binary versions of this gem are linked against the most used standard
library - glibc. Currently rubygems has no mechanism to differentiate
platform-specific gems by standard library so we have no way of distributing
different binaries for different standard libraries.

What this means is that if you're running a distro that does not use glibc
(like Alpine Linux), you'll have to use a source version of the gem.

Also, at the time of writing this, the Ruby version in Alpine's package
repositories has been patched to not look to download binary versions of gems at
all.

### Requirements

Building the V8 library from source imposes the following requirements:

* A compiler that supports C++11 (such as GCC 4.8 and above or clang,
preferably 3.5 and above)
* GNU Make
* Python 2
* An x86/x86_64 CPU. See [#261](https://github.com/cowboyd/libv8/issues/261) for ARM state.
* Linux with glibc or macOS. See
[#259](https://github.com/cowboyd/libv8/issues/259),
[#253](https://github.com/cowboyd/libv8/issues/253) and
[#217](https://github.com/cowboyd/libv8/issues/217) for state of other
platforms.
* Python 2

### Using a git version

Expand All @@ -122,47 +110,6 @@ To get the source, these commands will get you started:
bundle install
bundle exec rake compile

### Bring your own V8

*This is a great way to ensure that the builds of all gems that depend on libv8
fail. Please see the Gotchas section below and use the follwing instructions
only if you know what you're doing. If you're resorting to this because the
build of the gem is failing on your system or because there's no
platform-specific gem for your platform, please open up an issue.*

Because libv8 is the interface for the V8 engine used by several gems, you may
need to use libv8, even if you have V8 installed already. If you wish to use
your own V8 installation, rather than have it built for you, use the
`--with-system-v8` option.

Using RubyGems:

gem install libv8 -- --with-system-v8

Using Bundler (in your Gemfile):

bundle config build.libv8 --with-system-v8

#### Gotchas

Please note that if you intend to run your own V8, you must install
both V8 *and its headers* (found in libv8-dev for Debian-based distros).

Also, keep in mind that V8's API does not tend to be stable and in case you're
using your local version of V8 you *need* to **make sure that the the gems that
depend on libv8 are compatible with the API of the version of V8 present on your
system**. Otherwise those gems' builds *will* fail. Ideally you want the same
version of V8 as the one packaged in the installed version of the gem. See the
Versioning section for more information.

### Bring your own compiler

You can specify a compiler of your choice by either setting the `CXX`
environment variable before compilation, or by adding the
`--with-cxx=<compiler>` option to the bundle configuration:

bundle config build.libv8 --with-cxx=clang++

### About

This project spun off of
Expand All @@ -177,7 +124,6 @@ installed that gem.
### Sponsored by

<a href="http://frontside.io">![The Frontside](/thefrontside.png)</a>
<a href="https://www.scaleway.com">![Scaleway](/scaleway.png)</a>

### License

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ task :binary => :compile do
# We don't need most things for the binary
gemspec.files = []
gemspec.files += ['lib/libv8.rb', 'lib/libv8/version.rb']
gemspec.files += ['ext/libv8/arch.rb', 'ext/libv8/location.rb', 'ext/libv8/paths.rb']
gemspec.files += ['ext/libv8/location.rb', 'ext/libv8/paths.rb']
gemspec.files += ['ext/libv8/.location.yml']

# V8
gemspec.files += Dir['vendor/v8/include/**/*.h']
gemspec.files += Dir['vendor/v8/out/**/*.a']
gemspec.files += Dir['vendor/v8/out.gn/**/*.a']

FileUtils.chmod 0644, gemspec.files
FileUtils.mkdir_p 'pkg'
Expand Down
109 changes: 22 additions & 87 deletions ext/libv8/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,40 @@
require 'rbconfig'
require 'shellwords'
require 'libv8/version'
require File.expand_path '../compiler', __FILE__
require File.expand_path '../arch', __FILE__
require File.expand_path '../make', __FILE__
require File.expand_path '../patcher', __FILE__

module Libv8
class Builder
include Libv8::Arch
include Libv8::Make
include Libv8::Patcher

def initialize
@compiler = choose_compiler
def gn_args
%W(is_debug=#{debug_build? ? 'true' : 'false'}
symbol_level=#{debug_build? ? '-1' : '0'}
is_component_build=false
v8_monolithic=true
v8_use_external_startup_data=false
target_cpu="#{libv8_arch}"
v8_target_cpu="#{libv8_arch}"
treat_warnings_as_errors=false
v8_enable_i18n_support=false).join(' ')
end

def make_target
profile = enable_config('debug') ? 'debug' : 'release'
"#{libv8_arch}.#{profile}"
def generate_gn_args
system "gn gen out.gn/libv8 --args='#{gn_args}'"
end

def gyp_defines(*defines)
# Do not use an external snapshot as we don't really care for binary size
defines << 'v8_use_external_startup_data=0'

# Do not use the embedded toolchain
defines << 'use_sysroot=0'
defines << 'linux_use_bundled_binutils=0'
defines << 'linux_use_bundled_gold=0'
defines << 'make_clang_dir=""'
defines << 'clang_dir=""'

# Pass clang flag to GYP in order to work around GCC compilation failures
defines << "clang=#{@compiler.is_a?(Compiler::Clang) ? '1' : '0'}"

# Add contents of the GYP_DEFINES environment variable if present
defines << ENV['GYP_DEFINES'] unless ENV['GYP_DEFINES'].nil?

"GYP_DEFINES=\"#{defines.join ' '}\""
end

def make_flags(*flags)
# Disable i18n
flags << 'i18nsupport=off'

# Solaris / Smart OS requires additional -G flag to use with -fPIC
flags << "CFLAGS=-G" if @compiler.target =~ /solaris/

# Disable werror as this version of v8 is getting difficult to maintain
# with it on
flags << 'werror=no'

# Append GYP variable definitions
flags << gyp_defines

# Append manually specified MAKEFLAGS
flags << ENV['MAKEFLAGS'] if ENV['MAKEFLAGS']
ENV['MAKEFLAGS'] = nil

"#{make_target} #{flags.join ' '}"
def debug_build?
enable_config('debug')
end

def build_libv8!
setup_python!
setup_build_deps!
Dir.chdir(File.expand_path('../../../vendor/v8', __FILE__)) do
fail 'No compilers available' if @compiler.nil?
patch!
print_build_info
puts 'Beginning compilation. This will take some time.'
generate_gn_args

command = "env CXX=#{Shellwords.escape @compiler.to_s} #{make} #{make_flags}"
puts "Building v8 with #{command}"
system command
system 'ninja -v -C out.gn/libv8 v8_monolith'
end
return $?.exitstatus
end
Expand Down Expand Up @@ -112,56 +73,30 @@ def source_version
#
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'
system "env #{gyp_defines} fetch v8" or fail "unable to fetch v8 source"
else
system "env #{gyp_defines} gclient fetch" or fail "could not fetch v8 build dependencies commits"
unless Dir.exists?('v8') || File.exists?('.gclient')
system "fetch v8" or fail "unable to fetch v8 source"
end

Dir.chdir('v8') do
system 'git fetch origin'
unless system "git checkout #{source_version}"
fail "unable to checkout source for v8 #{source_version}"
end
system "env #{gyp_defines} gclient sync" or fail "could not sync v8 build dependencies"
system "git checkout Makefile" # Work around a weird bug on FreeBSD
system "gclient sync" or fail "could not sync v8 build dependencies"
end
end
end

private

def choose_compiler
compiler = if with_config('cxx') || ENV['CXX']
with_config('cxx') || ENV['CXX']
else
begin
MakeMakefile::CONFIG['CXX'] # stdlib > 2.0.0
rescue NameError
RbConfig::CONFIG['CXX'] # stdlib < 2.0.0
end
end

Libv8::Compiler.type_of(compiler).new compiler
end

def python_version
if system 'which python 2>&1 > /dev/null'
`python -c 'import platform; print(platform.python_version())'`.chomp
else
"not available"
end
end

def print_build_info
puts "Compiling v8 for #{libv8_arch}"

puts "Using python #{python_version}"

puts "Using compiler: #{@compiler} (#{@compiler.name} version #{@compiler.version})"
unless @compiler.compatible?
warn "Unable to find a compiler officially supported by v8."
warn "It is recommended to use clang v3.5 or GCC v4.8 or higher"
end
end
end
end
Loading