Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to bundle install nio4r on a new Mac M3

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.

like image 476
aec Avatar asked Sep 04 '25 16:09

aec


1 Answers

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]

like image 95
Polak Avatar answered Sep 07 '25 07:09

Polak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!