Ruby 2.1.4 libv8

MacのローカルでRuby2.1.3から2.1.4にあげてみた。

~/.rbenv/plugins/ruby-build
git pull
rbenv install 2.1.4
rbenv global 2.1.4
rbenv uninstall 2.1.4
gem install bundler

で行けるかなーと思ったら、Railsプロジェクトのbundleコマンドで死んだ。

$ bundle

...


Using kaminari 0.15.1

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

    /Users/nyangry/.rbenv/versions/2.1.4/bin/ruby extconf.rb
creating Makefile
Compiling v8 for x64
Using python 2.7.6
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Using compiler: g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
../src/cached-powers.cc:136:18: error: unused variable 'kCachedPowersLength' [-Werror,-Wunused-const-variable]
static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers);
                 ^
1 error generated.
make[1]: *** [vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o] Error 1
make: *** [x64.release] Error 2
vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:36:in `block in verify_installation!': libv8 did not install properly, expected binary v8 archive 'vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a'to exist, but it was not found (Libv8::Location::Vendor::ArchiveNotFound)
        from vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `each'
        from vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:35:in `verify_installation!'
        from vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:26:in `install!'
        from extconf.rb:7:in `<main>'
GYP_GENERATORS=make \
        build/gyp/gyp --generator-output="out" build/all.gyp \
                      -Ibuild/standalone.gypi --depth=. \
                      -Dv8_target_arch=x64 \
                      -S.x64  -Dv8_enable_backtrace=1 -Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2 -Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3
  CXX(target) vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/allocation.o
  CXX(target) vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/atomicops_internals_x86_gcc.o
  CXX(target) vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum.o
  CXX(target) vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/bignum-dtoa.o
  CXX(target) vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3/vendor/v8/out/x64.release/obj.target/preparser_lib/src/cached-powers.o

extconf failed, exit code 1

Gem files will remain installed in vendor/bundle/ruby/2.1.0/gems/libv8-3.16.14.3 for inspection.
Results logged to vendor/bundle/ruby/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/libv8-3.16.14.3/gem_make.out
An error occurred while installing libv8 (3.16.14.3), and Bundler cannot
continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

もうお前いいよ・・・libv8・・・・

で、今回割りと簡単そうで、誰でもこれでいけそうな対策見つけた。

v8 を入れる

$ brew install v8

bundle/configのグローバルオプション追加

$ bundle config --global build.libv8 --with-system-v8

$ cat ~/.bundle/config
---
BUNDLE_BUILD__NOKOGIRI: "--use-system-libraries"
BUNDLE_BUILD__LIBV8: "--with-system-v8"
BUNDLE_PATH: vendor/bundle

DONE!

$ bundle

これだけ。

なにをやっているの?

bundleのビルドオプションを指定して、インストール済みのv8を使ってねと教えてあげる。 これがないと自力で頑張ろうとするからいろいろ駄目になるっぽい。

グローバルだからどのリポジトリも同じ設定使えます。 nokogiriも同じようにオプション追加しとくといいかも。