rubyjs / mini_racer

Minimal embedded v8
MIT License
598 stars 93 forks source link

v0.4.0 fails to build on ruby:3.0-alpine #199

Closed bryanp closed 1 year ago

bryanp commented 3 years ago

With https://github.com/rubyjs/mini_racer/pull/186 being included in v0.4.0 I was hopeful that mini_racer would be installable in alpine containers. Unfortunately, it isn't quite working for me. Here's a minimal Dockerfile to demonstrate the issue that I hit:

FROM ruby:3.0.1-alpine

RUN apk update && apk upgrade && \
    apk add --no-cache build-base && \
    gem update --system && gem install bundler

RUN gem install mini_racer -v 0.4.0

Here's the error:

> [3/3] RUN gem install mini_racer -v 0.4.0:
#6 2.994 Successfully installed libv8-node-15.14.0.1-x86_64-linux-musl
#6 2.994 Building native extensions. This could take a while...
#6 4.642 ERROR:  Error installing mini_racer:
#6 4.642        ERROR: Failed to build gem native extension.
#6 4.642
#6 4.642     current directory: /usr/local/bundle/gems/mini_racer-0.4.0/ext/mini_racer_extension
#6 4.642 /usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/3.0.0 -r ./siteconf20210506-1-u8eo5j.rb extconf.rb
#6 4.642 checking for -lpthread... yes
#6 4.642 creating Makefile
#6 4.642
#6 4.642 current directory: /usr/local/bundle/gems/mini_racer-0.4.0/ext/mini_racer_extension
#6 4.642 make DESTDIR\= clean
#6 4.642
#6 4.642 current directory: /usr/local/bundle/gems/mini_racer-0.4.0/ext/mini_racer_extension
#6 4.642 make DESTDIR\=
#6 4.642 compiling mini_racer_extension.cc
#6 4.642 In file included from /usr/local/include/ruby-3.0.0/ruby/ruby.h:39,
#6 4.642                  from /usr/local/include/ruby-3.0.0/ruby.h:38,
#6 4.642                  from mini_racer_extension.cc:2:
#6 4.642 /usr/local/include/ruby-3.0.0/ruby/internal/memory.h:276:16: error: conflicting declaration of 'void* ruby_nonempty_memcpy(void*, const void*, size_t)' with 'C' linkage
#6 4.642   276 | #define memcpy ruby_nonempty_memcpy
#6 4.642       |                ^~~~~~~~~~~~~~~~~~~~
#6 4.642 /usr/local/include/ruby-3.0.0/ruby/internal/memory.h:266:1: note: previous declaration with 'C++' linkage
#6 4.642   266 | ruby_nonempty_memcpy(void *dest, const void *src, size_t n)
#6 4.642       | ^~~~~~~~~~~~~~~~~~~~
#6 4.642 mini_racer_extension.cc: In function 'v8::Local<v8::Value> convert_ruby_to_v8(v8::Isolate*, v8::Local<v8::Context>, VALUE)':
#6 4.642 mini_racer_extension.cc:546:96: warning: ignoring return value of 'v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, uint32_t, v8::Local<v8::Value>)', declared with attribute 'warn_unused_result' [-Wunused-result]
#6 4.642   546 |             array->Set(context, i, convert_ruby_to_v8(isolate, context, rb_ary_entry(value, i)));
#6 4.642       |                                                                                                ^
#6 4.642 In file included from mini_racer_extension.cc:5:
#6 4.642 /usr/local/bundle/gems/libv8-node-15.14.0.1-x86_64-linux-musl/vendor/v8/include/v8.h:3719:37: note: declared here
#6 4.642  3719 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
#6 4.642       |                                     ^~~
#6 4.642 mini_racer_extension.cc:556:78: warning: ignoring return value of 'v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)', declared with attribute 'warn_unused_result' [-Wunused-result]
#6 4.642   556 |                   convert_ruby_to_v8(isolate, context, rb_ary_entry(pair, 1)));
#6 4.642       |                                                                              ^
#6 4.642 In file included from mini_racer_extension.cc:5:
#6 4.642 /usr/local/bundle/gems/libv8-node-15.14.0.1-x86_64-linux-musl/vendor/v8/include/v8.h:3716:37: note: declared here
#6 4.642  3716 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
#6 4.642       |                                     ^~~
#6 4.642 mini_racer_extension.cc: In function 'VALUE rb_external_function_notify_v8(VALUE)':
#6 4.642 mini_racer_extension.cc:1165:46: warning: ignoring return value of 'v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)', declared with attribute 'warn_unused_result' [-Wunused-result]
#6 4.642  1165 |                             .ToLocalChecked());
#6 4.642       |                                              ^
#6 4.642 In file included from mini_racer_extension.cc:5:
#6 4.642 /usr/local/bundle/gems/libv8-node-15.14.0.1-x86_64-linux-musl/vendor/v8/include/v8.h:3716:37: note: declared here
#6 4.642  3716 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
#6 4.642       |                                     ^~~
#6 4.642 mini_racer_extension.cc:1190:58: warning: ignoring return value of 'v8::Maybe<bool> v8::Object::Set(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>)', declared with attribute 'warn_unused_result' [-Wunused-result]
#6 4.642  1190 |                                         .ToLocalChecked());
#6 4.642       |                                                          ^
#6 4.642 In file included from mini_racer_extension.cc:5:
#6 4.642 /usr/local/bundle/gems/libv8-node-15.14.0.1-x86_64-linux-musl/vendor/v8/include/v8.h:3716:37: note: declared here
#6 4.642  3716 |   V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
#6 4.642       |                                     ^~~
#6 4.642 make: *** [Makefile:213: mini_racer_extension.o] Error 1
#6 4.642
#6 4.642 make failed, exit code 2
#6 4.642
#6 4.642 Gem files will remain installed in /usr/local/bundle/gems/mini_racer-0.4.0 for inspection.
#6 4.642 Results logged to /usr/local/bundle/extensions/x86_64-linux-musl/3.0.0/mini_racer-0.4.0/gem_make.out
------
executor failed running [/bin/sh -c gem install mini_racer -v 0.4.0]: exit code: 1
SamSaffron commented 3 years ago

@lloeki any ideas here?

SamSaffron commented 3 years ago

I wonder if this alpine image for ruby is missing some headers or has them messed up? does this happen in other ruby alpines?

bryanp commented 3 years ago

Hmm, it does build on ruby:2.7.3-alpine but fails on both ruby:3.0.0-alpine and ruby:3.0.1-alpine.

lloeki commented 3 years ago

Yes, something changed ever since ruby:3.0.0-preview1, I'm not sure what as I could only have a cursory look.

I'll see to dig a bit in the coming days.

lloeki commented 3 years ago

I think that might be the core of it, there's some mixup between C and C++:

/usr/local/include/ruby-3.0.0/ruby/internal/memory.h:275:16: error: conflicting declaration of 'void* ruby_nonempty_memcpy(void*, const void*, size_t)' with 'C' linkage
  275 | #define memcpy ruby_nonempty_memcpy
      |                ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/ruby-3.0.0/ruby/internal/memory.h:265:1: note: previous declaration with 'C++' linkage
  265 | ruby_nonempty_memcpy(void *dest, const void *src, size_t n)
      | ^~~~~~~~~~~~~~~~~~~~

I could swear I already handled a similar issue but have no recollection how.

lloeki commented 3 years ago

Some progress: using clang and a little bit of prodding has it building on ruby:3.0-alpine:

diff --git a/Dockerfile b/Dockerfile
index 208d733..ef86d91 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,6 +13,10 @@ COPY lib/mini_racer/version.rb /code/lib/mini_racer/version.rb
 WORKDIR /code
 RUN bundle install

+RUN apk add clang
+ENV CC=clang
+ENV CXX=clang++
+
 COPY Rakefile /code/
 COPY ext /code/ext/
 RUN bundle exec rake compile
diff --git a/ext/mini_racer_extension/extconf.rb b/ext/mini_racer_extension/extconf.rb
index 7881f20..8ae252d 100644
--- a/ext/mini_racer_extension/extconf.rb
+++ b/ext/mini_racer_extension/extconf.rb
@@ -29,6 +29,10 @@ if ENV['CXX']
   CONFIG['CXX'] = ENV['CXX']
 end

+$CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
+
 CXX11_TEST = <<EOS
 #if __cplusplus <= 199711L
 #   error A compiler that supports at least C++11 is required in order to compile this project.
docker build --build-arg RUBY_VERSION=3.0-alpine -t mini_racer:3.0-alpine .
docker run --rm -it mini_racer:3.0-alpine bundle exec rake test

But then it strangely fails on a locale test:

  1) Failure:
MiniRacerTest#test_locale [/code/test/mini_racer_test.rb:14]:
Expected: "28/4/2021"
  Actual: "7/5/2021"

84 runs, 140 assertions, 1 failures, 0 errors, 2 skips
bryanp commented 3 years ago

FWIW I have that same failing test in my local development environment (macos):

MiniRacerTest#test_locale [/Users/bryanp/Code/OSS/mini_racer/test/mini_racer_test.rb:14]:
Expected: "28/4/2021"
  Actual: "7/5/2021"

The test was introduced here with a hardcoded date string:

I opened https://github.com/rubyjs/mini_racer/pull/200 to fix it.

lloeki commented 3 years ago

Good catch, thanks @bryanp.

lloeki commented 3 years ago

OK, so a workaround would be to install and use clang:

apk add --no-cache build-base clang
export CC=clang
export CXX=clang++
gem install mini_racer

... if it were not for the required -fdeclspec or -fms-extensions flags which need some patching of extconf.rb:

diff --git a/ext/mini_racer_extension/extconf.rb b/ext/mini_racer_extension/extconf.rb
index 7881f20..8ae252d 100644
--- a/ext/mini_racer_extension/extconf.rb
+++ b/ext/mini_racer_extension/extconf.rb
@@ -29,6 +29,10 @@ if ENV['CXX']
   CONFIG['CXX'] = ENV['CXX']
 end

+puts "CXX: #{CONFIG['CXX']}"
+
+$CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
+
 CXX11_TEST = <<EOS
 #if __cplusplus <= 199711L
 #   error A compiler that supports at least C++11 is required in order to compile this project.
bryanp commented 3 years ago

Do we need platform-specific configuration in extconf.rb? Pardon my lack of knowledge here, I've not dealt with this before.

sagarjauhari commented 3 years ago

I used the suggestions here and was able to get it working with a patch. My Dockerfile:

...
RUN apk -U add --no-cache build-base clang \
    && rm -rf /var/cache/apk/*
ENV CC=clang
ENV CXX=clang++
RUN gem install 'specific_install'
RUN gem specific_install -l "https://github.com/sagarjauhari/mini_racer"
...

So confirming that the suggestions are working.

bryanp commented 3 years ago

Confirmed that @sagarjauhari works for me as well.

@lloeki @SamSaffron Can we make changes to extconf.rb to make this process easier for users, or should I just add some notes to the README about how to use mini_racer in alpine?

lloeki commented 3 years ago

It would be better to make changes so that it works out of the box. I'll see to it.

lloeki commented 3 years ago

So, I looked into an implementation, and to have the widest support possible and good feedback for the user I'm going to introduce a bit of compiler, feature, and version checking (that CXX11_TEST is a bit outdated and limited in scope). I think the README is due for some informative updates as well.

Might take a bit of time to get this right, but everyone will end up happier.

ololobus commented 3 years ago

Just got into the same problem.

I can confirm that clang + CC + CXX + extconf.rb patch solves the issue, but it breaks byebug native extensions compilation under the same circumstances, unfortunately. And byebug is a default gem for rails apps. I know that ruby 3.0 is not fully supported by byebug itself, but still.

So after experimenting a bit I figured out that clang + setting CXX=clang++ in the Dockerfile + patching extconf.rb is enough and it does not brake byebug. Maybe this will be helpful for someone :)

nogweii commented 3 years ago

FYI, it's known upstream in Ruby and a PR is open.

lloeki commented 3 years ago

Thanks @nogweii, then since it's going to be fixed upstream shortly-ish (the PR is approved) it doesn't make sense to hack anything in here.

@bryanp Would you be in to add a note to the README regarding this Ruby 3.x Alpine issue?

bryanp commented 2 years ago

I tried this again now that Ruby 3.1 is out but hit a new issue, this time in mini_racer instead of libv8-node:

$ docker build .
[+] Building 4.0s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                             0.0s
 => => transferring dockerfile: 129B                                                                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                                                                0.0s
 => => transferring context: 2B                                                                                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/ruby:3.1-alpine                                                                                                                                               0.2s
 => [1/3] FROM docker.io/library/ruby:3.1-alpine@sha256:0602d61c893480f4cd05c1941459e371e2d30ff82203fd3dabaaf2358f301894                                                                                         0.0s
 => CACHED [2/3] RUN apk update && apk upgrade &&     apk add --no-cache build-base &&     gem update --system && gem install bundler                                                                            0.0s
 => ERROR [3/3] RUN gem install mini_racer -v 0.5.0                                                                                                                                                              3.7s
------
 > [3/3] RUN gem install mini_racer -v 0.5.0:
#6 2.323 Successfully installed libv8-node-16.10.0.0-aarch64-linux
#6 2.323 Building native extensions. This could take a while...
#6 3.592 ERROR:  Error installing mini_racer:
#6 3.592        ERROR: Failed to build gem native extension.
#6 3.592
#6 3.592     current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension
#6 3.592 /usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/3.1.0 -r ./siteconf20211230-1-bfat0i.rb extconf.rb
#6 3.592 checking for -lpthread... yes
#6 3.592 creating Makefile
#6 3.592
#6 3.592 current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension
#6 3.592 make DESTDIR\= clean
#6 3.592
#6 3.592 current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension
#6 3.592 make DESTDIR\=
#6 3.592 compiling mini_racer_extension.cc
#6 3.592 mini_racer_extension.cc: In function 'void* gvl_ruby_callback(void*)':
#6 3.592 mini_racer_extension.cc:1246:42: warning: 'void rb_gc_force_recycle(VALUE)' is deprecated: this is now a no-op function [-Wdeprecated-declarations]
#6 3.592  1246 |             rb_gc_force_recycle(ruby_args);
#6 3.592       |                                          ^
#6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/intern.h:39,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby/ruby.h:192,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby.h:38,
#6 3.592                  from mini_racer_extension.cc:2:
#6 3.592 /usr/local/include/ruby-3.1.0/ruby/internal/intern/gc.h:214:6: note: declared here
#6 3.592   214 | void rb_gc_force_recycle(VALUE obj);
#6 3.592       |      ^~~~~~~~~~~~~~~~~~~
#6 3.592 mini_racer_extension.cc:1255:92: warning: 'VALUE ruby::backward::cxxanyargs::rb_rescue2(VALUE (*)(...), VALUE, VALUE (*)(...), VALUE, ...)' is deprecated: Use of ANYARGS in this function is deprecated [-Wdeprecated-declarations]
#6 3.592  1255 |             RUBY_METHOD_FUNC(rescue_callback), callback_data_value, rb_eException, (VALUE)0);
#6 3.592       |                                                                                            ^
#6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/internal/anyargs.h:83,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby/ruby.h:26,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby.h:38,
#6 3.592                  from mini_racer_extension.cc:2:
#6 3.592 /usr/local/include/ruby-3.1.0/ruby/backward/cxxanyargs.hpp:284:1: note: declared here
#6 3.592   284 | rb_rescue2(type *q, VALUE w, type *e, VALUE r, ...)
#6 3.592       | ^~~~~~~~~~
#6 3.592 mini_racer_extension.cc:1269:38: warning: 'void rb_gc_force_recycle(VALUE)' is deprecated: this is now a no-op function [-Wdeprecated-declarations]
#6 3.592  1269 |         rb_gc_force_recycle(ruby_args);
#6 3.592       |                                      ^
#6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/intern.h:39,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby/ruby.h:192,
#6 3.592                  from /usr/local/include/ruby-3.1.0/ruby.h:38,
#6 3.592                  from mini_racer_extension.cc:2:
#6 3.592 /usr/local/include/ruby-3.1.0/ruby/internal/intern/gc.h:214:6: note: declared here
#6 3.592   214 | void rb_gc_force_recycle(VALUE obj);
#6 3.592       |      ^~~~~~~~~~~~~~~~~~~
#6 3.592 linking shared-object mini_racer_extension.so
#6 3.592 g++: error: /usr/local/bundle/gems/libv8-node-16.10.0.0-aarch64-linux/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a: No such file or directory
#6 3.592 make: *** [Makefile:263: mini_racer_extension.so] Error 1
#6 3.592
#6 3.592 make failed, exit code 2
#6 3.592
#6 3.592 Gem files will remain installed in /usr/local/bundle/gems/mini_racer-0.5.0 for inspection.
#6 3.592 Results logged to /usr/local/bundle/extensions/aarch64-linux-musl/3.1.0/mini_racer-0.5.0/gem_make.out
------
executor failed running [/bin/sh -c gem install mini_racer -v 0.5.0]: exit code: 1
SamSaffron commented 2 years ago

I have fixes for this committed, will do a new release today

On Fri, 31 Dec 2021 at 3:12 am, Bryan Powell @.***> wrote:

I tried this again now that Ruby 3.1 is out but hit a new issue, this time in mini_racer instead of libv8-node:

$ docker build . [+] Building 4.0s (6/6) FINISHED => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 129B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ruby:3.1-alpine 0.2s => [1/3] FROM @.***:0602d61c893480f4cd05c1941459e371e2d30ff82203fd3dabaaf2358f301894 0.0s => CACHED [2/3] RUN apk update && apk upgrade && apk add --no-cache build-base && gem update --system && gem install bundler 0.0s => ERROR [3/3] RUN gem install mini_racer -v 0.5.0 3.7s

[3/3] RUN gem install mini_racer -v 0.5.0:

6 2.323 Successfully installed libv8-node-16.10.0.0-aarch64-linux

6 2.323 Building native extensions. This could take a while...

6 3.592 ERROR: Error installing mini_racer:

6 3.592 ERROR: Failed to build gem native extension.

6 3.592

6 3.592 current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension

6 3.592 /usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/3.1.0 -r ./siteconf20211230-1-bfat0i.rb extconf.rb

6 3.592 checking for -lpthread... yes

6 3.592 creating Makefile

6 3.592

6 3.592 current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension

6 3.592 make DESTDIR\= clean

6 3.592

6 3.592 current directory: /usr/local/bundle/gems/mini_racer-0.5.0/ext/mini_racer_extension

6 3.592 make DESTDIR\=

6 3.592 compiling mini_racer_extension.cc

6 3.592 mini_racer_extension.cc: In function 'void gvl_ruby_callback(void)':

6 3.592 mini_racer_extension.cc:1246:42: warning: 'void rb_gc_force_recycle(VALUE)' is deprecated: this is now a no-op function [-Wdeprecated-declarations]

6 3.592 1246 | rb_gc_force_recycle(ruby_args);

6 3.592 | ^

6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/intern.h:39,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby/ruby.h:192,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby.h:38,

6 3.592 from mini_racer_extension.cc:2:

6 3.592 /usr/local/include/ruby-3.1.0/ruby/internal/intern/gc.h:214:6: note: declared here

6 3.592 214 | void rb_gc_force_recycle(VALUE obj);

6 3.592 | ^~~~~~~

6 3.592 mini_racer_extension.cc:1255:92: warning: 'VALUE ruby::backward::cxxanyargs::rb_rescue2(VALUE ()(...), VALUE, VALUE ()(...), VALUE, ...)' is deprecated: Use of ANYARGS in this function is deprecated [-Wdeprecated-declarations]

6 3.592 1255 | RUBY_METHOD_FUNC(rescue_callback), callback_data_value, rb_eException, (VALUE)0);

6 3.592 | ^

6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/internal/anyargs.h:83,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby/ruby.h:26,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby.h:38,

6 3.592 from mini_racer_extension.cc:2:

6 3.592 /usr/local/include/ruby-3.1.0/ruby/backward/cxxanyargs.hpp:284:1: note: declared here

6 3.592 284 | rb_rescue2(type q, VALUE w, type e, VALUE r, ...)

6 3.592 | ^~~~~~

6 3.592 mini_racer_extension.cc:1269:38: warning: 'void rb_gc_force_recycle(VALUE)' is deprecated: this is now a no-op function [-Wdeprecated-declarations]

6 3.592 1269 | rb_gc_force_recycle(ruby_args);

6 3.592 | ^

6 3.592 In file included from /usr/local/include/ruby-3.1.0/ruby/intern.h:39,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby/ruby.h:192,

6 3.592 from /usr/local/include/ruby-3.1.0/ruby.h:38,

6 3.592 from mini_racer_extension.cc:2:

6 3.592 /usr/local/include/ruby-3.1.0/ruby/internal/intern/gc.h:214:6: note: declared here

6 3.592 214 | void rb_gc_force_recycle(VALUE obj);

6 3.592 | ^~~~~~~

6 3.592 linking shared-object mini_racer_extension.so

6 3.592 g++: error: /usr/local/bundle/gems/libv8-node-16.10.0.0-aarch64-linux/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a: No such file or directory

6 3.592 make: *** [Makefile:263: mini_racer_extension.so] Error 1

6 3.592

6 3.592 make failed, exit code 2

6 3.592

6 3.592 Gem files will remain installed in /usr/local/bundle/gems/mini_racer-0.5.0 for inspection.

6 3.592 Results logged to /usr/local/bundle/extensions/aarch64-linux-musl/3.1.0/mini_racer-0.5.0/gem_make.out


executor failed running [/bin/sh -c gem install mini_racer -v 0.5.0]: exit code: 1

— Reply to this email directly, view it on GitHub https://github.com/rubyjs/mini_racer/issues/199#issuecomment-1003092612, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAABIXPWT5BLLPJL2I6FE2LUTSAFLANCNFSM44IFIPZQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

bryanp commented 2 years ago

Thanks! Tried mini_racer v0.6.0 and it solved the above problem, but still fails:

docker build --no-cache .
[+] Building 11.4s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                             0.0s
 => => transferring dockerfile: 177B                                                                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                                                                0.0s
 => => transferring context: 2B                                                                                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/ruby:3.1-alpine                                                                                                                                               0.5s
 => CACHED [1/3] FROM docker.io/library/ruby:3.1-alpine@sha256:0602d61c893480f4cd05c1941459e371e2d30ff82203fd3dabaaf2358f301894                                                                                  0.0s
 => [2/3] RUN apk update && apk upgrade &&     apk add --no-cache build-base &&     gem update --system && gem install bundler                                                                                   7.0s
 => ERROR [3/3] RUN gem install mini_racer -v 0.6.0                                                                                                                                                              3.9s
------
 > [3/3] RUN gem install mini_racer -v 0.6.0:
#6 2.422 Successfully installed libv8-node-16.10.0.0-aarch64-linux
#6 2.422 Building native extensions. This could take a while...
#6 3.766 ERROR:  Error installing mini_racer:
#6 3.766        ERROR: Failed to build gem native extension.
#6 3.766
#6 3.766     current directory: /usr/local/bundle/gems/mini_racer-0.6.0/ext/mini_racer_extension
#6 3.766 /usr/local/bin/ruby -I /usr/local/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220103-1-4tadug.rb extconf.rb
#6 3.766 checking for -lpthread... yes
#6 3.766 creating Makefile
#6 3.766
#6 3.766 current directory: /usr/local/bundle/gems/mini_racer-0.6.0/ext/mini_racer_extension
#6 3.766 make DESTDIR\= clean
#6 3.766
#6 3.766 current directory: /usr/local/bundle/gems/mini_racer-0.6.0/ext/mini_racer_extension
#6 3.766 make DESTDIR\=
#6 3.766 compiling mini_racer_extension.cc
#6 3.766 linking shared-object mini_racer_extension.so
#6 3.766 g++: error: /usr/local/bundle/gems/libv8-node-16.10.0.0-aarch64-linux/vendor/v8/aarch64-linux-musl/libv8/obj/libv8_monolith.a: No such file or directory
#6 3.766 make: *** [Makefile:263: mini_racer_extension.so] Error 1
#6 3.766
#6 3.766 make failed, exit code 2
#6 3.766
#6 3.766 Gem files will remain installed in /usr/local/bundle/gems/mini_racer-0.6.0 for inspection.
#6 3.766 Results logged to /usr/local/bundle/extensions/aarch64-linux-musl/3.1.0/mini_racer-0.6.0/gem_make.out
------
executor failed running [/bin/sh -c gem install mini_racer -v 0.6.0]: exit code: 1

Here's my Dockerfile:

FROM ruby:3.1-alpine

RUN apk update && apk upgrade && \
    apk add --no-cache build-base && \
    gem update --system && gem install bundler

RUN gem install mini_racer -v 0.6.0
bryanp commented 2 years ago

I dug around a bit more and found that aarch64-linux exists but aarch64-linux-musl does not:

/ # ls /usr/local/bundle/gems/libv8-node-16.10.0.0-aarch64-linux/vendor/v8/
aarch64-linux  include

Thinking this might be an issue in how libv8-node is configuring the makefile (cc @lloeki).

SamSaffron commented 2 years ago

This appears to be working now @bryanp , just tried your dockerfile and it is passing.

bryanp commented 2 years ago

@SamSaffron Unfortunately I still receive the same error with the above Dockerfile, even after bumping to mini_racer 0.6.1 and specifying --no-cache. I'm using an M1 Mac—could this be explained by a difference between our platforms?

virusman commented 2 years ago

0.6.2 works fine on M1 for me.

tisba commented 2 years ago

Can confirm that 0.6.2 works fine using the above Dockerfile on x86_64-linux-musl. How did you get this running on aarch64-linux-musl I'm running into the issue @bryanp mentioned (libv8-node is not available for this Ruby platform).

Quintasan commented 2 years ago

Since https://bugs.ruby-lang.org/issues/17788 fixes the issue on Ruby 3.1 I created a backport request for Ruby 3.0 in https://bugs.ruby-lang.org/issues/18574

tisba commented 2 years ago

Just to clarify, @bryanp: Your Dockerfile works fine on x86_64-linux-musl (Intel).

You have to build libv8-node from source if you are running on M1/Apple Silicon. There is no pre-build aarch-linux build available currently for libv8-node (see https://rubygems.org/gems/libv8-node/versions).

Building libv8-node from source takes a while (~35min for me) and you'll need to adjust your Dockerfile to install needed build dependencies. Since there is still an issue (I think this one https://github.com/rubygems/rubygems/pull/4488, /cc @lloeki) which requires you to force the platform (using --platform ruby). Otherwise Rubygems gets confused and picks up aarch-linux instead.

Here is the Dockerfile I used to get mini_racer running in ruby:3.1-alpine on Apple M1:

FROM ruby:3.1-alpine

RUN apk update && apk upgrade && \
    apk add --no-cache build-base linux-headers bash python2 python3 git curl tar && \
    gem update --system && gem install bundler

RUN gem install mini_racer --platform=ruby
tisba commented 2 years ago

…oh and as @Quintasan mentioned https://bugs.ruby-lang.org/issues/17788 needs backporting to Ruby 3.0, so this will currently only work with Ruby 3.1.

tisba commented 2 years ago

FYI: The backport of bugs.ruby-lang.org/issues/17788 landed in the Ruby 3.0 branch via https://github.com/ruby/ruby/commit/2bb5fa495bf9d366d3c1fefc6b093dc4830f27bf

tisba commented 1 year ago

The backport was released in Ruby 3.0.4 (a little hard to find, but it's in https://github.com/ruby/ruby/compare/v3_0_3...v3_0_4).

Its a PITA to test though, as the Ruby alpine images on Docker Hub have been updated past Alpine 3.15 and you need specific versions of Python to build libv8-node as there is no aarch64-linux-musl for 16.10.0.0. I -think- with Ruby 3.0.4 (or the latest 3.0.x) this issue should be resolved, if you setup a proper environment to compile libv8-node.

With a hopefully soonish release of new mini_racer versions, this problem will most likely solve itself, as aarch64-linux-musl builds are available starting with libv8-node > 16.10.0.0.

tisba commented 1 year ago

With mini_racer 0.6.4 released (which uses libv8-node 16.19.0.1) we can finally close this issue 🥳 mini_racer now builds fine with Ruby 3.0, starting with Ruby 3.0.4.

FROM ruby:3.0.4-alpine

RUN apk update && apk upgrade && \
  apk add --no-cache build-base linux-headers bash git curl tar && \
  gem update --system && gem install bundler

and

# file: minimal.rb

require "bundler/inline"

gemfile do
  source "https://rubygems.org"

  gem "mini_racer"
end

require "libv8-node"

puts "RUBY_VERSION : #{RUBY_VERSION}"
puts "RUBY_PLATFORM: #{RUBY_PLATFORM}"
puts "MiniRacer::VERSION: #{MiniRacer::VERSION}"
puts "MiniRacer::LIBV8_NODE_VERSION: #{MiniRacer::LIBV8_NODE_VERSION}"
puts "Libv8::Node::VERSION: #{Libv8::Node::VERSION}"
puts "Libv8::Node::NODE_VERSION: #{Libv8::Node::NODE_VERSION}"
puts "Libv8::Node::LIBV8_VERSION: #{Libv8::Node::LIBV8_VERSION}"

ctx = MiniRacer::Context.new

puts ctx.eval("1+1")
$ docker run --rm -v "$(pwd)":/app -w /app mini_racer_debug ruby /app/minimal.rb
RUBY_VERSION : 3.0.4
RUBY_PLATFORM: aarch64-linux-musl
MiniRacer::VERSION: 0.6.4
MiniRacer::LIBV8_NODE_VERSION: ~> 16.19.0.0
Libv8::Node::VERSION: 16.19.0.1
Libv8::Node::NODE_VERSION: 16.19.0
Libv8::Node::LIBV8_VERSION: 9.4.146.26
2