💭

突然gem 'ffi'が原因でbundle installできなくなった話

2020/11/23に公開

タイトル通りです。
突然bundle installが通らなくなりました。

RailsはDocker化しておらず、macのローカル環境で開発していました。

環境

  • macOS Catalina 10.15.7
  • Rails 5.2.1
  • Ruby 2.4.2
  • bundler 1.17.1

結論

MacにインストールしていたXcodeのバージョンを下げたら通りました。

エラーメッセージ

$ bundle install
.
.
.
Fetching ffi 1.9.23
Installing ffi 1.9.23 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    current directory: /Users/shimazu/vendor/bundle/ruby/2.5.0/gems/ffi-1.9.23/ext/ffi_c
/Users/shimazu/.rbenv/versions/2.5.0/bin/ruby -I /Users/shimazu/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0 -r ./siteconf20201102-41899-zc56ao.rb extconf.rb
checking for ffi_call() in -lffi... yes
checking for ffi_closure_alloc()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
checking for ffi_prep_cif_var()... yes
creating extconf.h
creating Makefile
current directory: /Users/shimazu/vendor/bundle/ruby/2.5.0/gems/ffi-1.9.23/ext/ffi_c
make "DESTDIR=" clean
current directory: /Users/shimazu/vendor/bundle/ruby/2.5.0/gems/ffi-1.9.23/ext/ffi_c
make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:334:5: error: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
    ^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                      ^
1 error generated.
make: *** [Call.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/shimazu/vendor/bundle/ruby/2.5.0/gems/ffi-1.9.23 for inspection.
Results logged to /Users/shimazu/vendor/bundle/ruby/2.5.0/extensions/x86_64-darwin-19/2.5.0/ffi-1.9.23/gem_make.out
An error occurred while installing ffi (1.9.23), and Bundler cannot continue.
Make sure that `gem install ffi -v '1.9.23' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
  bootstrap was resolved to 4.0.0, which depends on
    sass was resolved to 3.5.5, which depends on
      sass-listen was resolved to 4.0.0, which depends on
        rb-inotify was resolved to 0.9.10, which depends on
          ffi

原因

エラーメッセージを見ると、Cのコンパイルで失敗しているような。。
色々と試しましたが、ローカルのXcodeのバージョンが原因のようでした。

before

$ xcodebuild -version
Xcode 12.1
Build version 12A7403

$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.21)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

after

$ xcodebuild -version
Xcode 11.5
Build version 11E608c

$ clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Discussion