mini_racer 0.3.1 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e370d4752aeb013f408e1df0b94521d25b81ea3fc576a53e28ecbe857bec7336
4
- data.tar.gz: 5f8eae12d493d3c70ce07f32d41da6d847de31762d6d546e42d5148843112808
3
+ metadata.gz: 2d643f2cd1fb220fc7ac49d502671334d2e9390cd6eac47b62cdecfc39f2dd82
4
+ data.tar.gz: 2c1cbb7cb254dddefdeac0c7bd246d62e2f08dfb9df24c91680ef0e6016ea483
5
5
  SHA512:
6
- metadata.gz: 9a7f5d67e29902e7fec4f516ff1037bb8c62da2dbda8cfa8604c0d0c59f3a222e37776c7d42f7cfb17bead48dc201c95209c4bcdd7f5202b0ba6d98e5678a5a2
7
- data.tar.gz: 77cef34527ace5fa77c4c4ef138809cddf1238c3388db845e595f614653feac7e8c77a378162f73bac35d9d84899a1f52c2265e27264a8368771e797e6d86189
6
+ metadata.gz: be7c745abba5a2bd5caf0e30f066601a58d00f847092bde4865d3faf7b79987af5bfe0c6cd9c2783f0ab7a7edc1e39b6a53afa489ce4e5dde0713981e26dfc51
7
+ data.tar.gz: e6128f7619cdb105b04f5a7abb0ed2c0964a2b2b353c3a4eecc79dfa3d329d88695f9885c7250d2d6615ff9bc93c22cf111d24bca54d9e57fbaa02672998879c
data/.dockerignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ lib/mini_racer_extension.so
11
+ lib/mini_racer_loader.so
12
+ *.bundle
@@ -0,0 +1,124 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ test-truffleruby:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os:
15
+ - "macos-11"
16
+ - "macos-12"
17
+ - "ubuntu-20.04"
18
+ ruby:
19
+ - "truffleruby+graalvm-head"
20
+
21
+ name: ${{ matrix.os }} - ${{ matrix.ruby }}
22
+ runs-on: ${{ matrix.os }}
23
+
24
+ env:
25
+ TRUFFLERUBYOPT: "--jvm --polyglot"
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ bundler-cache: true
33
+ - name: Install GraalVM JS component
34
+ run: gu install js
35
+ - name: Compile
36
+ run: bundle exec rake compile
37
+ - name: Test
38
+ run: bundle exec rake test
39
+
40
+ test-darwin:
41
+ strategy:
42
+ fail-fast: false
43
+ matrix:
44
+ os:
45
+ - "macos-11"
46
+ - "macos-12"
47
+ ruby:
48
+ - "ruby-2.6"
49
+ - "ruby-2.7"
50
+ - "ruby-3.0"
51
+ - "ruby-3.1"
52
+
53
+ name: ${{ matrix.os }} - ${{ matrix.ruby }}
54
+ runs-on: ${{ matrix.os }}
55
+
56
+ steps:
57
+ - uses: actions/checkout@v3
58
+ - uses: ruby/setup-ruby@v1
59
+ with:
60
+ ruby-version: ${{ matrix.ruby }}
61
+ bundler-cache: true
62
+ - name: Compile
63
+ run: bundle exec rake compile
64
+ - name: Test
65
+ run: bundle exec rake test
66
+
67
+ test-linux:
68
+ strategy:
69
+ fail-fast: false
70
+ matrix:
71
+ ruby:
72
+ - "2.6"
73
+ - "2.7"
74
+ - "3.0"
75
+ - "3.1"
76
+ platform:
77
+ - "amd64"
78
+ - "arm64"
79
+ libc:
80
+ - "gnu"
81
+ - "musl"
82
+ exclude:
83
+ # there's no libv8-node (v16) for aarch64-linux-musl at the moment
84
+ - platform: "arm64"
85
+ libc: "musl"
86
+
87
+ name: linux-${{ matrix.platform }} - ruby-${{ matrix.ruby }} - ${{ matrix.libc }}
88
+ runs-on: ubuntu-20.04
89
+
90
+ steps:
91
+ - name: Enable ${{ matrix.platform }} platform
92
+ id: qemu
93
+ if: ${{ matrix.platform != 'amd64' }}
94
+ run: |
95
+ docker run --privileged --rm tonistiigi/binfmt:latest --install ${{ matrix.platform }} | tee platforms.json
96
+ echo "::set-output name=platforms::$(cat platforms.json)"
97
+ - name: Start container
98
+ id: container
99
+ run: |
100
+ case ${{ matrix.libc }} in
101
+ gnu)
102
+ echo 'ruby:${{ matrix.ruby }}'
103
+ ;;
104
+ musl)
105
+ echo 'ruby:${{ matrix.ruby }}-alpine'
106
+ ;;
107
+ esac > container_image
108
+ echo "::set-output name=image::$(cat container_image)"
109
+ docker run --rm -d -v "${PWD}":"${PWD}" -w "${PWD}" --platform linux/${{ matrix.platform }} $(cat container_image) /bin/sleep 64d | tee container_id
110
+ docker exec -w "${PWD}" $(cat container_id) uname -a
111
+ echo "::set-output name=id::$(cat container_id)"
112
+ - name: Install Alpine system dependencies
113
+ if: ${{ matrix.libc == 'musl' }}
114
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base bash git
115
+ - name: Checkout
116
+ uses: actions/checkout@v3
117
+ - name: Update Rubygems
118
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system
119
+ - name: Bundle
120
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
121
+ - name: Compile
122
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake compile
123
+ - name: Test
124
+ run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle exec rake test
data/.gitignore CHANGED
@@ -8,4 +8,6 @@ Gemfile.lock
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  lib/mini_racer_extension.so
11
+ lib/mini_racer_loader.so
11
12
  *.bundle
13
+ .vscode/
data/CHANGELOG CHANGED
@@ -1,4 +1,64 @@
1
- - 23-07-202
1
+ - 25-05-2022
2
+
3
+ - 0.6.4
4
+
5
+ - Target Node 16.19.0.0
6
+
7
+ - 16-08-2022
8
+
9
+ - 0.6.3
10
+
11
+ - Truffle ruby support! Thanks to Brandon Fish and the truffle team
12
+ - Hide libv8 symbols on ELF targets
13
+ - Slightly shrunk binary size
14
+ - Simplified timeout implementation
15
+ - Some stability fixes
16
+
17
+ - 17-01-2022
18
+
19
+ - 0.6.2
20
+
21
+ - Fix support for compilation on 2.6, llvm compiles
22
+ - Stability patches to handle rare memory leaks
23
+ - Corrected re-raising of exceptions to support strings
24
+ - During early termination of context under certain conditions MiniRacer could crash
25
+
26
+
27
+ - 31-12-2021
28
+
29
+ - 0.6.1
30
+
31
+ - Added support for single threaded platform: `MiniRacer::Platform.set_flags! :single_threaded`
32
+ must be called prior to booting ANY MiniRacer::Context
33
+
34
+ - 0.6.0
35
+
36
+ - Ruby 3.1 support
37
+ - Fixes memory leak in heap snapshotting
38
+ - Improved compilation ergonomics in clang
39
+ - Migrated internal storage in c extension to TypedData
40
+
41
+ - 11-04-2021
42
+
43
+ - 0.5.0
44
+ - Fixes issues on aarch (Apple M1)
45
+ - Update to use libv8-node 16.x (#210) [Loic Nageleisen]
46
+ - FEATURE: Configurable max marshal stack depth (#202) [seanmakesgames]
47
+ - Ruby 2.3 and 2.4 are EOL, we no longer support them
48
+
49
+ - 0.4.0
50
+
51
+ - FEATURE: upgrade to libv8 node 15.14.0 (v8 8.6.395.17)
52
+ - Promote 0.4.0.beta1 to release, using libv8-node release path
53
+
54
+ - 08-04-2021
55
+
56
+ - 0.4.0.beta1
57
+
58
+ - FIX: on downgrade mkmf was picking the wrong version of libv8, this fix will correct future issues
59
+ - FEATURE: upgraded libv8 to use node libv8 build which supports M1 and various ARM builds v8 moved to (8.6.395.17)
60
+
61
+ - 23-07-2020
2
62
 
3
63
  - 0.3.1
4
64
 
data/Dockerfile ADDED
@@ -0,0 +1,21 @@
1
+ ARG RUBY_VERSION=2.7
2
+ FROM ruby:${RUBY_VERSION}
3
+
4
+ RUN test ! -f /etc/alpine-release || apk add --no-cache build-base git
5
+
6
+ # without this `COPY .git`, we get the following error:
7
+ # fatal: not a git repository (or any of the parent directories): .git
8
+ # but with it we need the full gem just to compile the extension because
9
+ # of gemspec's `git --ls-files`
10
+ # COPY .git /code/.git
11
+ COPY Gemfile mini_racer.gemspec /code/
12
+ COPY lib/mini_racer/version.rb /code/lib/mini_racer/version.rb
13
+ WORKDIR /code
14
+ RUN bundle install
15
+
16
+ COPY Rakefile /code/
17
+ COPY ext /code/ext/
18
+ RUN bundle exec rake compile
19
+
20
+ COPY . /code/
21
+ CMD bundle exec irb -rmini_racer
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MiniRacer
2
2
 
3
- [![Build Status](https://travis-ci.org/rubyjs/mini_racer.svg?branch=master)](https://travis-ci.org/rubyjs/mini_racer)
3
+ [![Test](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyjs/mini_racer/actions/workflows/ci.yml)
4
4
 
5
5
  Minimal, modern embedded V8 for Ruby.
6
6
 
@@ -10,12 +10,14 @@ It was created as an alternative to the excellent [therubyracer](https://github.
10
10
 
11
11
  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.
12
12
 
13
- ### A note about Ruby version Support
13
+ ### Supported Ruby Versions
14
14
 
15
- 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.
15
+ 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.
16
16
 
17
17
  If you require support for older versions of Ruby install an older version of the gem.
18
18
 
19
+ 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).
20
+
19
21
  ## Features
20
22
 
21
23
  ### Simple eval for JavaScript
@@ -85,6 +87,19 @@ context.eval 'var a = new Array(10000); while(true) {a = a.concat(new Array(1000
85
87
  # => V8OutOfMemoryError is raised
86
88
  ```
87
89
 
90
+ ### Object marshal max stackdepth support
91
+
92
+ Contexts can specify a stack depth limit for object marshalling. Max depth is unbounded by default.
93
+
94
+ ```ruby
95
+ # terminates script if stack depth exceeds max during marshal
96
+ context = MiniRacer::Context.new(marshal_stack_depth: 500)
97
+ context.attach("a", proc{|a| a})
98
+
99
+ context.eval("let arr = []; arr.push(arr); a(arr)")
100
+ # => RuntimeError is raised
101
+ ```
102
+
88
103
  ### Rich debugging with "filename" support
89
104
 
90
105
  ```ruby
@@ -99,16 +114,21 @@ context.eval('bar()', filename: 'a/bar.js')
99
114
 
100
115
  ### Fork safety
101
116
 
102
- Some Ruby web servers employ forking (for example unicorn or puma in clustered mode). V8 is not fork safe.
103
- Sadly Ruby does not have support for fork notifications per [#5446](https://bugs.ruby-lang.org/issues/5446).
117
+ 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).
118
+
119
+ 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`:
120
+
121
+ ```ruby
122
+ MiniRacer::Platform.set_flags!(:single_threaded)
123
+ ```
104
124
 
105
125
  If you want to ensure your application does not leak memory after fork either:
106
126
 
107
- 1. Ensure no MiniRacer::Context objects are created in the master process
127
+ 1. Ensure no `MiniRacer::Context` objects are created in the master process
108
128
 
109
129
  Or
110
130
 
111
- 2. Dispose manually of all MiniRacer::Context objects prior to forking
131
+ 2. Dispose manually of all `MiniRacer::Context` objects prior to forking
112
132
 
113
133
  ```ruby
114
134
  # before fork
@@ -249,7 +269,7 @@ It is possible to set V8 Runtime flags:
249
269
  MiniRacer::Platform.set_flags! :noconcurrent_recompilation, max_inlining_levels: 10
250
270
  ```
251
271
 
252
- This can come in handy if you want to use MiniRacer with Unicorn, which doesn't seem to alwatys appreciate V8's liberal use of threading:
272
+ This can come in handy if you want to use MiniRacer with Unicorn, which doesn't seem to always appreciate V8's liberal use of threading:
253
273
  ```ruby
254
274
  MiniRacer::Platform.set_flags! :noconcurrent_recompilation, :noconcurrent_sweeping
255
275
  ```
@@ -403,21 +423,18 @@ Or install it yourself as:
403
423
  $ gem install mini_racer
404
424
 
405
425
 
406
- **Note** using v8.h and compiling MiniRacer requires a C++11 standard compiler, more specifically clang 3.5 (or later) or gcc 4.8 (or later).
407
-
426
+ **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).
408
427
 
409
- ## Travis-ci
410
428
 
411
- To install `mini-racer` you will need a version of gcc that supports C++11 (gcc 4.8) this is included by default in ubuntu trusty based images.
429
+ ### Troubleshooting
412
430
 
413
- 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 4.8 on precise the simpler approach is to opt for the trusty based image.
431
+ If you have a problem installing mini_racer, please consider the following steps:
414
432
 
415
- Add this to your .travis.yml file:
416
-
417
- ```
418
- - sudo: required
419
- - dist: trusty
420
- ```
433
+ * make sure you try the latest released version of mini_racer
434
+ * make sure you have Rubygems >= 3.2.13 and bundler >= 2.2.13 installed via `gem update --system`
435
+ * if you are using bundler, make sure to have `PLATFORMS` set correctly in `Gemfile.lock` via `bundle lock --add-platform`
436
+ * make sure to recompile/reinstall `mini_racer` and `libv8-node` after system upgrades (for example via `gem uninstall --all mini_racer libv8-node`)
437
+ * make sure you are on the latest patch/teeny version of a supported Ruby branch
421
438
 
422
439
  ## Similar Projects
423
440
 
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
- require "rake/extensiontask"
4
3
 
5
4
  Rake::TestTask.new(:test) do |t|
6
5
  t.libs << "test"
@@ -11,7 +10,21 @@ end
11
10
  task :default => [:compile, :test]
12
11
 
13
12
  gem = Gem::Specification.load( File.dirname(__FILE__) + '/mini_racer.gemspec' )
14
- Rake::ExtensionTask.new( 'mini_racer_extension', gem )
13
+
14
+ if RUBY_ENGINE == "truffleruby"
15
+ task :compile do
16
+ # noop
17
+ end
18
+
19
+ task :clean do
20
+ # noop
21
+ end
22
+ else
23
+ require 'rake/extensiontask'
24
+ Rake::ExtensionTask.new( 'mini_racer_loader', gem )
25
+ Rake::ExtensionTask.new( 'mini_racer_extension', gem )
26
+ end
27
+
15
28
 
16
29
 
17
30
  # via http://blog.flavorjon.es/2009/06/easily-valgrind-gdb-your-ruby-c.html
@@ -91,5 +104,5 @@ task :lint do
91
104
  portability-*
92
105
  readability-*).join(',')
93
106
 
94
- sh RbConfig::expand("clang-tidy -checks='#{checks}' ext/mini_racer_extension/mini_racer_extension.cc -- #$INCFLAGS #$CPPFLAGS", conf)
107
+ sh RbConfig::expand("clang-tidy -checks='#{checks}' ext/mini_racer_extension/mini_racer_extension.cc -- #$INCFLAGS #$CXXFLAGS", conf)
95
108
  end
@@ -1,21 +1,41 @@
1
1
  require 'mkmf'
2
- require 'libv8'
2
+
3
+ if RUBY_ENGINE == "truffleruby"
4
+ File.write("Makefile", dummy_makefile($srcdir).join(""))
5
+ return
6
+ end
7
+
8
+ require_relative '../../lib/mini_racer/version'
9
+ gem 'libv8-node', MiniRacer::LIBV8_NODE_VERSION
10
+ require 'libv8-node'
3
11
 
4
12
  IS_DARWIN = RUBY_PLATFORM =~ /darwin/
5
13
 
6
14
  have_library('pthread')
7
15
  have_library('objc') if IS_DARWIN
8
- $CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall"
9
- $CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g"
10
- $CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic"
11
- $CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or IS_DARWIN
12
- $CPPFLAGS += " -std=c++0x"
13
- $CPPFLAGS += " -fpermissive"
14
- $CPPFLAGS += " -DV8_COMPRESS_POINTERS"
15
-
16
- $CPPFLAGS += " -Wno-reserved-user-defined-literal" if IS_DARWIN
16
+ $CXXFLAGS += " -Wall" unless $CXXFLAGS.split.include? "-Wall"
17
+ $CXXFLAGS += " -g" unless $CXXFLAGS.split.include? "-g"
18
+ $CXXFLAGS += " -rdynamic" unless $CXXFLAGS.split.include? "-rdynamic"
19
+ $CXXFLAGS += " -fPIC" unless $CXXFLAGS.split.include? "-rdynamic" or IS_DARWIN
20
+ $CXXFLAGS += " -std=c++14"
21
+ $CXXFLAGS += " -fpermissive"
22
+ #$CXXFLAGS += " -DV8_COMPRESS_POINTERS"
23
+ $CXXFLAGS += " -fvisibility=hidden "
24
+
25
+ # __declspec gets used by clang via ruby 3.x headers...
26
+ $CXXFLAGS += " -fms-extensions"
27
+
28
+ $CXXFLAGS += " -Wno-reserved-user-defined-literal" if IS_DARWIN
29
+
30
+ if IS_DARWIN
31
+ $LDFLAGS.insert(0, " -stdlib=libc++ ")
32
+ else
33
+ $LDFLAGS.insert(0, " -lstdc++ ")
34
+ end
17
35
 
18
- $LDFLAGS.insert(0, " -stdlib=libc++ ") if IS_DARWIN
36
+ # check for missing symbols at link time
37
+ # $LDFLAGS += " -Wl,--no-undefined " unless IS_DARWIN
38
+ # $LDFLAGS += " -Wl,-undefined,error " if IS_DARWIN
19
39
 
20
40
  if ENV['CXX']
21
41
  puts "SETTING CXX"
@@ -54,11 +74,19 @@ if enable_config('debug') || enable_config('asan')
54
74
  CONFIG['debugflags'] << ' -ggdb3 -O0'
55
75
  end
56
76
 
57
- Libv8.configure_makefile
77
+ Libv8::Node.configure_makefile
78
+
79
+ # --exclude-libs is only for i386 PE and ELF targeted ports
80
+ append_ldflags("-Wl,--exclude-libs=ALL ")
58
81
 
59
82
  if enable_config('asan')
60
- $CPPFLAGS.insert(0, " -fsanitize=address ")
83
+ $CXXFLAGS.insert(0, " -fsanitize=address ")
61
84
  $LDFLAGS.insert(0, " -fsanitize=address ")
62
85
  end
63
86
 
87
+ # there doesn't seem to be a CPP macro for this in Ruby 2.6:
88
+ if RUBY_ENGINE == 'ruby'
89
+ $CPPFLAGS += ' -DENGINE_IS_CRUBY '
90
+ end
91
+
64
92
  create_makefile 'mini_racer_extension'