Unable to bundle install nio4r on a new Mac M3
Asked Answered
C

4

14

I just got a new M3 running Sonoma, and I'm experiencing the following error running bundle:

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

I tried the suggestion in the error message with no luck, and have been scouring the Internet for a solution, and tried ~10 different things, but nothing allows me to get past the problem. I have XCode installed, and have tried various bundle config flags. No idea what else to try.

This native gem is required by puma (which I can replace with unicorn if need be) and actioncable (which seems to come with the rails gem, though if there's some way to install rails without it, I'm happy do that).

The full backtrace is from the relavant part onwards is:

...
Installing nio4r 2.5.8 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/nio4r-2.5.8/ext/nio4r
/Users/aaronecohen/.asdf/installs/ruby/3.0.2/bin/ruby -I /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/3.0.0 -r ./siteconf20240411-97157-bvwsjv.rb extconf.rb
--with-cflags\=-std\=c99
checking for unistd.h... yes
checking for linux/aio_abi.h... no
checking for linux/io_uring.h... no
checking for sys/select.h... yes
checking for port_event_t in poll.h... no
checking for sys/epoll.h... no
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for port_event_t in port.h... no
checking for sys/resource.h... yes
creating Makefile

current directory: /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/nio4r-2.5.8/ext/nio4r
make DESTDIR\= clean

current directory: /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/nio4r-2.5.8/ext/nio4r
make DESTDIR\=
compiling bytebuffer.c
compiling monitor.c
compiling nio4r_ext.c
In file included from nio4r_ext.c:6:
./../libev/ev.c:573:48: warning: '/*' within block comment [-Wcomment]
/*#define MIN_INTERVAL  0.00000095367431640625 /* 1/2**20, good till 2200 */
                                               ^
./../libev/ev.c:2136:31: warning: 'extern' variable has an initializer [-Wextern-initializer]
  EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */
                              ^
2 warnings generated.
compiling selector.c
selector.c:301:26: error: incompatible function pointer types passing 'VALUE (*)(VALUE *)' (aka 'unsigned long (*)(unsigned long *)') to parameter of type 'VALUE (*)(VALUE)' (aka
'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
        return rb_ensure(func, (VALUE)args, NIO_Selector_unlock, self);
                         ^~~~
/Users/aaronecohen/.asdf/installs/ruby/3.0.2/include/ruby-3.0.0/ruby/internal/iterator.h:53:24: note: passing argument to parameter here
VALUE rb_ensure(VALUE(*)(VALUE),VALUE,VALUE(*)(VALUE),VALUE);
                       ^
1 error generated.
make: *** [selector.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/nio4r-2.5.8 for inspection.
Results logged to /Users/aaronecohen/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/extensions/arm64-darwin-23/3.0.0/nio4r-2.5.8/gem_make.out

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

In Gemfile:
  rails was resolved to 7.0.4.3, which depends on
    actioncable was resolved to 7.0.4.3, which depends on
      nio4r

Suggestions very much appreciated, even if they don't ultimately solve the problem.

Coakley answered 12/4 at 0:19 Comment(1)
Hmm, another repo I have running Ruby 3.1 and nio4r 2.5.9 bundles just fine on the same machine. Time to upgrade the Ruby version of the previous repo ...Coakley
P
40

For bundle install I solved the issue by running first

bundle config build.nio4r --with-cflags="-Wno-incompatible-pointer-types"

This is necessary when your bundle configuration stores gems in a custom folder like ./vendor/bundle

For gem install

gem install nio4r -v 2.5.8 -- --with-cflags="-Wno-incompatible-pointer-types"

I have an M1 and that same flag solved issues for other gems as well (msgpack, pg, jaro_winkler). In fact, if you pay attention to the output log, it gives you a clue about the flag you need: [-Wincompatible-function-pointer-types]

Prismoid answered 15/4 at 16:1 Comment(3)
On my freshly setup MacBook M2 chip I ran bundle config build.nio4r --with-cflags="-Wno-incompatible-pointer-types" and then bundle install worked just fine.Asteria
Confirmed working in M1 as of Jun 2024 with SonomFleischman
On my mac M1 chip it worked for bundle install command. But when I try to run any rails command even rails -v I got Segmentation Fault error. And I have no idea what's happening now. :ODisjoint
C
0

The solution was to upgrade to Ruby 3.1, per the other repo where this was working.

Coakley answered 12/4 at 2:30 Comment(0)
I
0

Run brew install coreutils before trying anything.

Indictment answered 21/5 at 1:33 Comment(0)
A
0

This issue was fixed in nio4r v2.5.9 (ref).

I just faced this issue and fixed it by updating the gem version.

Ass answered 12/8 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.