3

When I run bundle install on my rails 5 project, I am getting a number of errors on gems that appear to have native extensions. Here is the top of the output for one of those gems:

Installing nio4r 1.2.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

checking for unistd.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl()... yes
checking for sys/select.h... yes
checking for poll.h... yes
checking for sys/epoll.h... no
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for port.h... no
checking for sys/resource.h... yes
creating Makefile

current directory: /Users/<my-username>/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
make "DESTDIR=" clean

current directory: /Users/<my-username>/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
make "DESTDIR="
compiling monitor.c
monitor.c:91:24: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
if(interests_id == rb_intern("r")) {
                   ^~~~~~~~~~~~~~
/Users/<my-username>/.rvm/rubies/ruby-2.7.4/include/ruby-2.7.0/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
    __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                  ^
monitor.c:91:24: note: '{' token is here
    if(interests_id == rb_intern("r")) {
                       ^~~~~~~~~~~~~~

I have tried a number of things.

Per this post I tried the following suggestions:

# didn't fix it
bundle config build.nio4r --with-cflags="-std=c99"
bundle

# didn't fix it
xcode-select --install
sudo xcodebuild -license accept
bundle

I also referenced this Go Rails guide, specifically the "Final Steps" section that deals with gems that require C extensions, but that command seems to not apply because I didn't migrate my macOS from Mojave.

At this point I'm not sure what to try next. Ultimately: it appears the issue revolves around being unable to install gems that require C extensions.

Environment:

  • macOS Monterey version 12.2
  • Using rvm with ruby version 2.7.4
  • Project is using rails version 5.0.1
Neil
  • 4,578
  • 14
  • 70
  • 155
  • Did you try to clean your gems and install is again via `bundle clean --force`? Sometimes several gem versions cause a lot of troubles without displaying exactly why. – brcebn Mar 17 '22 at 17:45
  • Hmm, @brcebn tried that and got the error: `Could not find activesupport-5.0.1 in any of the sources` – Neil Mar 17 '22 at 19:51
  • I've had `bundle clean` fail before. I'm inclined to nuke the bundle with `rm` and build it anew: `rm -r vendor/bundle; bundle install` (assuming your bundle is located at `vendor/bundle`. That won't solve the build problem, though. – JellicleCat Mar 17 '22 at 20:34
  • @Neil I was going to tell you that if gems are not found there are 2 possibilities. Rvm Ruby version used or Bundler version. You find it out by yourself. Good job! – brcebn Mar 18 '22 at 10:16

2 Answers2

10

It turns out the problem was that in the Gemfile.lock file, it was locked to using an older version of bundler. We simply deleted the Gemfile.lock, and re-ran bundle to regenerate Gemfile.lock. That solved it. It now says this at the bottom of the Gemfile.lock file, so it liked this version of bundler:

BUNDLED WITH
   2.3.9
Neil
  • 4,578
  • 14
  • 70
  • 155
  • 2
    Oh! This means you've also updated all your gems. It might be a break-in change. I would suggest never remove the `Gemfile.lock`. But your solution works, it's a bit radical but it definitely works. – brcebn Mar 18 '22 at 10:13
  • 1
    Typically bundler will warn you if your bundle version is somehow incompatible with the bundle.lock. As brcebn says, it's likely you've upgraded a bunch of gems and the upgrade is what solved the problem, but it could have broken other things. – voxobscuro Mar 18 '22 at 20:08
  • These are certainly valid points. For us, our `Gemfile` explicitly specifies both the `major` and `minor` versions of every gem we want. For some gems we even explicitly specify the `patch` we want. For us, so far, this has worked out. – Neil Mar 25 '22 at 00:49
0

Did you try this? It worked for me

brew install openssl

gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl@1.1/include

and then run bundle install

Kiran Reddy
  • 120
  • 1
  • 6