Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem::Ext::BuildError: ERROR: Failed to build gem native extension #250

Closed
hananamar opened this issue May 3, 2022 · 15 comments
Closed

Gem::Ext::BuildError: ERROR: Failed to build gem native extension #250

hananamar opened this issue May 3, 2022 · 15 comments

Comments

@hananamar
Copy link

I have a rails app with gem "mini_racer", '0.6.2', platforms: :ruby in my Gemfile.
When running bundle install I get the following error message:

Installing mini_racer 0.6.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
/home/hanan/.rbenv/versions/2.7.5/bin/ruby -I /home/hanan/.rbenv/versions/2.7.5/lib/ruby/site_ruby/2.7.0 -r
./siteconf20220503-3610945-1245bxh.rb extconf.rb
checking for -lpthread... yes
creating Makefile

current directory: /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
make DESTDIR\= clean

current directory: /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
make DESTDIR\=
compiling mini_racer_extension.cc
mini_racer_extension.cc: In function ‘VALUE convert_v8_to_ruby(v8::Isolate*, v8::Local<v8::Context>, v8::Local<v8::Value>)’:
mini_racer_extension.cc:573:18: warning: ‘stackCounter.StackCounter::isolate’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
  573 |     StackCounter stackCounter(isolate);
      |                  ^~~~~~~~~~~~
linking shared-object mini_racer_extension.so
g++: error:
/home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a:
No such file or directory
make: *** [Makefile:262: mini_racer_extension.so] Error 1

make failed, exit code 2

Gem files will remain installed in /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2 for inspection.
Results logged to
/home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/x86_64-linux/2.7.0/mini_racer-0.6.2/gem_make.out

An error occurred while installing mini_racer (0.6.2), and Bundler cannot continue.
Make sure that `gem install mini_racer -v '0.6.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  mini_racer

I checked the missing folder and indeed I found that the missing file form the libv8 gem was actually present in
/home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux-musl/libv8/obj/libv8_monolith.a,
as opposed to
/home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a which is where mini_racer is looking for it.

I tried to add a symbolic link to point the missing directory to the existing one... and it worked.1

But this solution is not sustainable.

Footnotes

  1. The command I used to add the symlink: ln -s /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux-musl /home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux

@schneimo
Copy link

schneimo commented May 14, 2022

Get a very similar error on MacOS using gem.

mini_racer searches for libv8 in /Users/moritz/.gem/gems/libv8-node-16.10.0.0-x86_64-darwin/vendor/v8/universal-darwin/libv8/obj/libv8_monolith.a as opposed to its real destination /Users/moritz/.gem/gems/libv8-node-16.10.0.0-x86_64-darwin/vendor/v8/x86_64-darwin/libv8/obj/libv8_monolith.a.

@dmix
Copy link

dmix commented May 18, 2022

I'm having the same problem, the problem is that it's trying to download the musl version instead of the standard x86_64 version

/home/hanan/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/

The README mentions adding the appropriate PLATFORM to Gemfile.lock https://github.com/rubyjs/mini_racer/pull/240/files

But I've also added this:

PLATFORMS
  ruby
  x86_64-linux

This was discussed in this issue #218 but it's clearly causing issues for people.

So I'm not sure how to fix this personally.

@weedySeaDragon
Copy link

Thanks a million @hananamar ! Ran into this tonight while deploying (to a staging server thankfully). I created the symlink for the dir as you did and it worked perfectly. You saved me hours!
@tisba Just wanted to ping you to let you know that the symlink also worked for me.

@Insood
Copy link

Insood commented Jul 14, 2022

+1 here, also have issues installing.

0.4.0 installs just fine, but 0.6.2 wants to grab the musl version for some reason.

Doing the symlink also works, but feels dirty (also not sustainable).

I've also changed to

PLATFORMS
x86_64-linux

and I get the same issue:

+ bundle install
Fetching gem metadata from https://rubygems.org/.......
Fetching gem metadata from https://enterprise.contribsys.com/..
...
Using libv8-node 16.10.0.0 (x86_64-linux)
...
Installing mini_racer 0.6.2 with native extensions
...
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/home/jenkins/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
/home/jenkins/.rbenv/versions/2.7.5/bin/ruby -I
/home/jenkins/.rbenv/versions/2.7.5/lib/ruby/2.7.0 -r
./siteconf20220715-18367-1cxvv05.rb extconf.rb
checking for -lpthread... yes
creating Makefile

current directory:
/home/jenkins/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
make "DESTDIR=" clean

current directory:
/home/jenkins/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/mini_racer-0.6.2/ext/mini_racer_extension
make "DESTDIR="
compiling mini_racer_extension.cc
linking shared-object mini_racer_extension.so
g++: error:
/home/jenkins/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/libv8-node-16.10.0.0-x86_64-linux-musl/vendor/v8/x86_64-linux/libv8/obj/libv8_monolith.a:
No such file or directory

@SamSaffron
Copy link
Collaborator

I just got hit by this on local @lloeki , the bug in rubygems / bundler is really painful ...

Our makefule looks for things in x86_64-linux but rubygems puts it in x86_64-linux-musl

I wonder if we should add some internal workaround here where we put a symlink in place or add some lines to the makefile to fix it up?

For people hitting this:

gem update --system
gem install bundler 
gem uninstall libv8-node 
gem install libv8-node 

@lloeki
Copy link
Collaborator

lloeki commented Aug 16, 2022

Yeah it's super painful when it happens.

There's been additional work on the ruby gems repo to squash remaining corner cases.

I thought about symlinks but they're problematic because when bundler fetches the incorrect one it would allow Ruby to find the libc-mismatched lib and result in very obscure errors.

I've been thinking about doing things the way we did with sq_mini_racer:

  • remove the libv8-node dependency from mini_racer's gemspec
  • have extconf properly detect the platform version, download the libv8-node gem, extract it in a temp folder, and then build against that
  • cleanup tmp, including the downloaded libv8-node gem

This has the advantage of removing libv8-node from the bundle, thus reducing the overall bundle size, which is good since libv8-node is generally dead weight once mini_racer is compiled.

The has the drawback of breaking the "fetching..." vs "installing..." expectation: the first one is downloading but executing no external code, the second one should build (and thus executes) but maybe never hit the network, which security wise means each step could theoretically be sandboxed with different capabilities. Maybe some do bundle cache --all --all platforms + bundle install --local but even so I don't think anyone is as rigorous as previously mentioned.

@SamSaffron
Copy link
Collaborator

I am quite positive on just having the dependency removed in this way. I know it is not ideal cause we are stuck implementing bits of rubygems, but we would get far better control here which is nice.

@lloeki
Copy link
Collaborator

lloeki commented Aug 17, 2022

Alright I'll go this route and open a PR.

@lloeki
Copy link
Collaborator

lloeki commented Aug 23, 2022

By the way, rubygems/rubygems#5852 has been merged, fixing rubygems/rubygems#3174 right inside Rubygems. rubygems/rubygems#4488 is now a backport inside Bundler.

@seanmakesgames
Copy link
Contributor

Currently having the same issue. Sam's instructions weren't working in my docker-compose environment.

And deployment is failing for me the same way.

@seanmakesgames
Copy link
Contributor

Updated bundler, have confirmed this issue is not happening on bundler 2.3.22. @hananamar (and any others) have you tried with newer bundler?

@tisba
Copy link
Collaborator

tisba commented Sep 29, 2022

All mentioned steps, including to update bundler, are in https://github.com/rubyjs/mini_racer/#troubleshooting. Especially with the latest round of fixes to bundler, I'm pretty confident that this will have solved a lot of the issues that were popping up over time.

@isankadn
Copy link

isankadn commented Oct 28, 2022

in my case, I had a similar issue in Centos 7.

g++ version was "4.+" something and after upgrade g++ to "7.3.1". it worked!

@tisba
Copy link
Collaborator

tisba commented Oct 28, 2022

As state by the README (just over the Troubleshooting section):

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).

I think, we're in a good spot with this one, so I'm closing this issue.

@tisba tisba closed this as completed Oct 28, 2022
@chriscz
Copy link

chriscz commented Nov 28, 2022

I also ran into this issue on Fedora 36. We were storing our gems in vendor/bundle in our development docker image. I updated my rubygems and bundler to no avail, only after I nuked the vendor directory did it actually work again. So in all the following, similar to Sam's recommentation:

gem update --system
gem update bundler 
gem uninstall libv8-node 
bundle clean # Only applicable if you set path (lcheck `bundle config get path`
bundle install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests