Skip to content

Commit

Permalink
Merge branch 'master' into libv8-node-18
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Jan 6, 2023
2 parents b802b2b + b05d691 commit b7fd92e
Show file tree
Hide file tree
Showing 13 changed files with 583 additions and 170 deletions.
74 changes: 58 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
name: Test
name: Tests

on:
- push
pull_request:
push:
branches:
- master

env:
LIBV8_NODE_GIT_BRANCH: 'node-18'

jobs:
test-truffleruby:
strategy:
fail-fast: false
matrix:
os:
- "macos-11"
- "macos-12"
- "ubuntu-20.04"
ruby:
- "truffleruby+graalvm-head"

name: ${{ matrix.os }} - ${{ matrix.ruby }}
runs-on: ${{ matrix.os }}

env:
TRUFFLERUBYOPT: "--jvm --polyglot"

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install GraalVM JS component
run: gu install js
- name: Compile
run: bundle exec rake compile
- name: Test
run: bundle exec rake test

test-darwin:
strategy:
fail-fast: false
Expand All @@ -18,8 +52,10 @@ jobs:
- "ruby-2.7"
- "ruby-3.0"
- "ruby-3.1"

name: ${{ matrix.os }} - ${{ matrix.ruby }}
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
Expand All @@ -30,26 +66,30 @@ jobs:
run: bundle exec rake compile
- name: Test
run: bundle exec rake test

test-linux:
strategy:
fail-fast: false
matrix:
ruby:
- '2.6'
- '2.7'
- '3.0'
- '3.1'
- "2.6"
- "2.7"
- "3.0"
- "3.1"
platform:
- amd64
- arm64
# arm
# ppc64le
# s390x
- "amd64"
- "arm64"
libc:
- gnu
- musl
name: Test (linux)
- "gnu"
- "musl"
exclude:
# there's no libv8-node (v16) for aarch64-linux-musl at the moment
- platform: "arm64"
libc: "musl"

name: linux-${{ matrix.platform }} - ruby-${{ matrix.ruby }} - ${{ matrix.libc }}
runs-on: ubuntu-20.04

steps:
- name: Enable ${{ matrix.platform }} platform
id: qemu
Expand All @@ -74,9 +114,11 @@ jobs:
echo "::set-output name=id::$(cat container_id)"
- name: Install Alpine system dependencies
if: ${{ matrix.libc == 'musl' }}
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar clang binutils-gold
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base bash git
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Update Rubygems
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system
- name: Bundle
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
- name: Compile
Expand Down
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

12 changes: 11 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
- 17-01-2021
- 16-08-2022

- 0.6.3

- Truffle ruby support! Thanks to Brandon Fish and the truffle team
- Hide libv8 symbols on ELF targets
- Slightly shrunk binary size
- Simplified timeout implementation
- Some stability fixes

- 17-01-2022

- 0.6.2

Expand Down
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MiniRacer

[![Build Status](https://travis-ci.org/rubyjs/mini_racer.svg?branch=master)](https://travis-ci.org/rubyjs/mini_racer)
[![Test](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml)

Minimal, modern embedded V8 for Ruby.

Expand All @@ -10,12 +10,14 @@ It was created as an alternative to the excellent [therubyracer](https://github.

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.

### A note about Ruby version Support
### Supported Ruby Versions

MiniRacer only supports non-EOL versions of Ruby. See [Ruby](https://www.ruby-lang.org/en/downloads) to see the list of non-EOL Rubies.
MiniRacer only supports non-EOL versions of Ruby. See [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/) for the list of non-EOL Rubies.

If you require support for older versions of Ruby install an older version of the gem.

MiniRacer **does not support** [Ruby built on MinGW](https://github.com/rubyjs/mini_racer/issues/252#issuecomment-1201172236, "pure windows" no Cygwin, no WSL2) (see https://github.com/rubyjs/libv8-node/issues/9).

## Features

### Simple eval for JavaScript
Expand Down Expand Up @@ -112,16 +114,21 @@ context.eval('bar()', filename: 'a/bar.js')

### Fork safety

Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe.
Sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).
Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe by default and sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).

Since 0.6.1 mini_racer does support V8 single threaded platform mode which should remove most forking related issues. To enable run this before using `MiniRacer::Context`:

```ruby
MiniRacer::Platform.set_flags!(:single_threaded)
```

If you want to ensure your application does not leak memory after fork either:

1. Ensure no MiniRacer::Context objects are created in the master process
1. Ensure no `MiniRacer::Context` objects are created in the master process

Or

2. Dispose manually of all MiniRacer::Context objects prior to forking
2. Dispose manually of all `MiniRacer::Context` objects prior to forking

```ruby
# before fork
Expand Down Expand Up @@ -419,18 +426,15 @@ Or install it yourself as:
**Note** using v8.h and compiling MiniRacer requires a C++11 standard compiler, more specifically clang 3.5 (or later) or GCC 6.3 (or later).


## Travis-ci
### Troubleshooting

To install `mini-racer` you will need a version of GCC that supports C++11 (GCC 6.3) this is included by default in ubuntu trusty based images.
If you have a problem installing mini_racer, please consider the following steps:

Travis today ships by default with a precise based image. Precise Pangolin (12.04 LTS) was first released in August 2012. Even though you can install GCC 6.3 on precise the simpler approach is to opt for the trusty based image.

Add this to your .travis.yml file:

```
- sudo: required
- dist: trusty
```
* make sure you try the latest released version of mini_racer
* make sure you have Rubygems >= 3.2.13 and bundler >= 2.2.13 installed via `gem update --system`
* if you are using bundler, make sure to have `PLATFORMS` set correctly in `Gemfile.lock` via `bundle lock --add-platform`
* make sure to recompile/reinstall `mini_racer` and `libv8-node` after system upgrades (for example via `gem uninstall --all mini_racer libv8-node`)
* make sure you are on the latest patch/teeny version of a supported Ruby branch

## Similar Projects

Expand Down
18 changes: 15 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "bundler/gem_tasks"
require "rake/testtask"
require "rake/extensiontask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
Expand All @@ -11,8 +10,21 @@ end
task :default => [:compile, :test]

gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
Rake::ExtensionTask.new( 'mini_racer_loader', gem )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )

if RUBY_ENGINE == "truffleruby"
task :compile do
# noop
end

task :clean do
# noop
end
else
require 'rake/extensiontask'
Rake::ExtensionTask.new( 'mini_racer_loader', gem )
Rake::ExtensionTask.new( 'mini_racer_extension', gem )
end



# via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
Expand Down
9 changes: 9 additions & 0 deletions ext/mini_racer_extension/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
require 'mkmf'

if RUBY_ENGINE == "truffleruby"
File.write("Makefile", dummy_makefile($srcdir).join(""))
return
end

require_relative '../../lib/mini_racer/version'
gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
require 'libv8-node'
Expand Down Expand Up @@ -70,6 +76,9 @@

Libv8::Node.configure_makefile

# --exclude-libs is only for i386 PE and ELF targeted ports
append_ldflags("-Wl,--exclude-libs=ALL ")

if enable_config('asan')
$CXXFLAGS.insert(0, " -fsanitize=address ")
$LDFLAGS.insert(0, " -fsanitize=address ")
Expand Down

0 comments on commit b7fd92e

Please sign in to comment.