Ruby 3.3.4 にて Apple Silicon の Mac で posix-spawn のインストールに失敗するときの対処法

結論

以下のように Bundler の config に設定してから $ bundle install し直す。

$ bundle config build.posix-spawn --with-cflags="-Wno-incompatible-function-pointer-types"

参考

github.com

エラーメッセージ

current directory: /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/posix-spawn-0.3.15/ext
/Users/Foobar/.rbenv/versions/3.3.4/bin/ruby extconf.rb
creating Makefile

current directory: /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/posix-spawn-0.3.15/ext
make DESTDIR\= sitearchdir\=./.gem.20240809-949-scz66m sitelibdir\=./.gem.20240809-949-scz66m clean

current directory: /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/posix-spawn-0.3.15/ext
make DESTDIR\= sitearchdir\=./.gem.20240809-949-scz66m sitelibdir\=./.gem.20240809-949-scz66m
compiling posix-spawn.c
posix-spawn.c:226:27: error: incompatible function pointer types passing 'int (VALUE, VALUE, posix_spawn_file_actions_t *)' (aka 'int (unsigned long, unsigned long, void **)') to parameter of type 'int
(*)(VALUE, VALUE, VALUE)' (aka 'int (*)(unsigned long, unsigned long, unsigned long)') [-Wincompatible-function-pointer-types]
        rb_hash_foreach(options, posixspawn_file_actions_operations_iter, (VALUE)fops);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Foobar/.rbenv/versions/3.3.4/include/ruby-3.3.0/ruby/internal/intern/hash.h:83:40: note: passing argument to parameter 'func' here
void rb_hash_foreach(VALUE hash, int (*func)(VALUE key, VALUE val, VALUE arg), VALUE arg);
                                       ^
1 error generated.
make: *** [posix-spawn.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/posix-spawn-0.3.15 for inspection.
Results logged to /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/extensions/arm64-darwin-23/3.3.0-static/posix-spawn-0.3.15/gem_make.out

  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:43:in `each'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:43:in `make'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /Users/Foobar/.rbenv/versions/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/installer.rb:853:in `build_extensions'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/rubygems_gem_installer.rb:76:in `build_extensions'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/source/rubygems.rb:205:in `install'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/installer/parallel_installer.rb:132:in `do_install'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/installer/parallel_installer.rb:123:in `block in worker_pool'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/worker.rb:62:in `apply_func'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/worker.rb:57:in `block in process_queue'
  <internal:kernel>:187:in `loop'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/worker.rb:54:in `process_queue'
  /Users/Foobar/repo/vendor/bundle/ruby/3.3.0/gems/bundler-2.5.10/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'
Powered by はてなブログ