Skip to content

Commit

Permalink
Merge pull request rubyjs#1 from sqreen/isolation
Browse files Browse the repository at this point in the history
Isolation
  • Loading branch information
cataphract authored Aug 17, 2018
2 parents 04e5f81 + 82ac9a7 commit 0f249c0
Show file tree
Hide file tree
Showing 20 changed files with 386 additions and 49 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ Gemfile.lock
/pkg/
/spec/reports/
/tmp/
lib/mini_racer_extension.so
lib/*.so
/lib/sq_mini_racer/
/ext/mini_racer_extension/mini_racer.creator.*
*.bundle
15 changes: 4 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
language: ruby
rvm:
- 1.9
- 2.0
- 2.1
- 2.2
- 2.3
- 2.4
- 2.5
- ruby-head
matrix:
include:
- rvm: 2.5.1
os: osx
osx_image: xcode9.4
- rvm: 2.4.0
os: osx
osx_image: xcode8.3
- rvm: 2.4.0
os: osx
osx_image: xcode7.3
dist: trusty
sudo: true
before_install:
Expand Down
50 changes: 50 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
def test(version, env='') {
node('agent_ruby_build') {
unstash 'git'

sh "${env} ./test_me.sh ${version}"
}
}

try {

stage('Checkout scm') {
node('agent_ruby_build') {
checkout scm

sh 'git clean -ffdx'

stash includes: '**/*', name: 'git'
}
}

stage('Testing') {
parallel(failFast: false,
"1.9.3-p551" : { test("1.9.3-p551") },
"2.0.0-p647" : { test("2.0.0-p647") },
"2.2.3" : { test("2.2.3") },
"2.3.3" : { test("2.3.3") },
"2.4.3" : { test("2.4.3") },
"2.5.0" : { test("2.5.0") },
)
}

stage('Building 2.3.3') {
node('agent_ruby_build') {
sh './build_me.sh 2.3.3'

if (env.BRANCH_NAME == 'master') {
archiveArtifacts 'pkg/sq_mini_racer-*.gem'
}
}
}
} catch (e) {
currentBuild.result = "FAILED"
notifyFailed()
throw e
}


def notifyFailed() {
slackSend(color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Sqreen's fork of mini\_racer

This is a fork of [`mini_racer`](https://github.com/discourse/mini_racer), changed to allow coexistence with other versions of mainline mini\_racer and with therubyracer, and to improve compatibility with old versions of Ruby. Otherwise, it should track mainstream mini\_racer. It provides extra functionality to the [`sqreen`](https://rubygems.org/gems/sqreen/) gem.

# MiniRacer

[![Build Status](https://travis-ci.org/discourse/mini_racer.svg?branch=master)](https://travis-ci.org/discourse/mini_racer)
[![Build Status](https://travis-ci.org/sqreen/mini_racer.svg?branch=master)](https://travis-ci.org/sqreen/mini_racer)

Minimal, modern embedded V8 for Ruby.

MiniRacer provides a minimal two way bridge between the V8 JavaScript engine and Ruby.

It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exhaustive testing simpler.
It was created as an alternative to the excellent [therubyracer](https://github.com/cowboyd/therubyracer). Unlike therubyracer, mini\_racer only implements a minimal bridge. This reduces the surface area making upgrading v8 much simpler and exhaustive testing simpler.

MiniRacer has an adapter for [execjs](https://github.com/rails/execjs) so it can be used directly with Rails projects to minify assets, run babel or compile CoffeeScript.

Expand Down
7 changes: 5 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ end

task :default => [:compile, :test]

gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )
gem = Gem::Specification.load( File.dirname(__FILE__) + '/sq_mini_racer.gemspec' )
Rake::ExtensionTask.new( 'mini_racer_extension', gem ) do |ext|
ext.name = 'sq_mini_racer_extension'
end
Rake::ExtensionTask.new('prv_ext_loader', gem)


# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
Expand Down
13 changes: 13 additions & 0 deletions bench.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'mini_racer'
MiniRacer::Platform.set_flags! :perf_basic_prof
c = MiniRacer::Context.new
res = nil
script = File.read('small.json');
c.eval <<JS
var data = #{script};
function foo() { return data; }
JS
3000.times do
res = c.call('foo')
end
p res.size
46 changes: 46 additions & 0 deletions build_me.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

rm -rf Gemfile.lock pkg/

set -x

if [ $# -eq 1 ]; then
eval "$(rbenv init -)"
rbenv shell $1
fi;

set -e

ruby --version
gem --version

rbenv exec bundle install --no-deployment --path vendor/bundle

rbenv exec bundle exec rake build

git config user.email "[email protected]"
git config user.name "Jenkins"

last_gem=pkg/$(ls -t pkg | head -n 1)

version=$(echo $last_gem | sed 's,pkg/sq_mini_racer-\(.*\).gem,\1,')

DO_TAG=${SQREEN_TAG_GEM}

if [ "${DO_TAG}" == "1" ]; then
git tag -a gem-$version -m "Published $(date)"
fi;

if [ -r "`pwd`/.gem/credentials" ]; then
HOME=`pwd` gem push ${last_gem} -k sqreen_rubygems_api_key
else
echo "Not publishing to rubygems.org (no credentials is `pwd`/.gem/credentials )"
fi

if [ "${DO_TAG}" == "1" ]; then
if [ -n "${PUBLISH_VERSION}" ]; then
echo "SQREEN_VERSION=$version" > $PUBLISH_VERSION
else
git push origin gem-$version
fi;
fi;
15 changes: 15 additions & 0 deletions ext/mini_racer_extension/compat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef COMPAT_HPP
#define COMPAT_HPP

#include <ruby.h>

#ifdef PRIsVALUE
# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
# define RB_OBJ_STRING(obj) (obj)
#else
# define PRIsVALUE "s"
# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
#endif

#endif // COMPAT_HPP
38 changes: 35 additions & 3 deletions ext/mini_racer_extension/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'mkmf'
require 'libv8'
require 'fileutils'

have_library('pthread')
have_library('objc') if RUBY_PLATFORM =~ /darwin/
Expand All @@ -9,6 +9,7 @@
$CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or RUBY_PLATFORM =~ /darwin/
$CPPFLAGS += " -std=c++0x"
$CPPFLAGS += " -fpermissive"
$CPPFLAGS += " -fno-omit-frame-pointer"
$CPPFLAGS += " -Wno-reserved-user-defined-literal" if RUBY_PLATFORM =~ /darwin/

$LDFLAGS.insert 0, " -stdlib=libstdc++ " if RUBY_PLATFORM =~ /darwin/
Expand Down Expand Up @@ -50,6 +51,37 @@
CONFIG['debugflags'] << ' -ggdb3 -O0'
end

Libv8.configure_makefile
LIBV8_VERSION = '6.7.288.46.1'
libv8_rb = Dir.glob('**/libv8.rb').first
FileUtils.mkdir_p('gemdir')
unless libv8_rb
puts "Will try downloading libv8 gem, version #{LIBV8_VERSION}"
`gem install --version '= #{LIBV8_VERSION}' --install-dir gemdir libv8`
unless $?.success?
warn <<EOS
WARNING: Could not download a private copy of the libv8 gem. Please make
sure that you have internet access and that the `gem` binary is available.
EOS
end

libv8_rb = Dir.glob('**/libv8.rb').first
unless libv8_rb
warn <<EOS
WARNING: Could not find libv8 after the local copy of libv8 having supposedly
been installed.
create_makefile 'mini_racer_extension'
EOS
end
end

if libv8_rb
$:.unshift(File.dirname(libv8_rb) + '/../ext')
$:.unshift File.dirname(libv8_rb)
end

require 'libv8'
Libv8.configure_makefile
create_makefile 'sq_mini_racer_extension'
Loading

0 comments on commit 0f249c0

Please sign in to comment.