今まで Ruby のバージョン管理に rbenv を使っていました。
そんな中、RubyMine で mise がサポートされたことから、ためしに rbenv から乗り換えてみることにしました。
RubyMine 2024.1: Full Line Code Completion, New Terminal, Improved AI Assistant and VCS Support | The RubyMine Blog
mise でいくつかのRubyバージョンをインストールしたところ、Ruby 3.0 系のインストール時にmaybe_unused のBUILD FAILEDになったことから、対応したときのメモを残します。
目次
環境
miseでRubyをインストールするための準備
miseの公式ドキュメントでRubyを見たところ、
Behind the scenes, mise uses ruby-build to compile ruby from source. Ensure that you have the necessary dependencies installed.
と記載されていました。
そこで、リンク先である ruby-build のドキュメントを読むことにしました。
https://github.com/rbenv/ruby-build/wiki#suggested-build-environment
リンク先では、インストールする Ruby のバージョンごとに必要なものが記載されていたため、インストールしました。
% xcode-select --install % brew install openssl@3 readline libyaml gmp autoconf
また、古いバージョンもインストールしようと考えたので、OpenSSLの古いバージョンもインストールしました。
参考:OpenSSL and Ruby Compatibility Table | Ruby on Mac
% brew install rbenv/tap/openssl@1.1
Ruby 3.3.6 のインストールは成功
mise による Ruby 3.3.6 のインストールは問題なくできました。
# インストール可能なRubyのバージョンを確認 % mise ls-remote ruby 3.3 3.3.0-preview1 ... 3.3.6 # インストール % mise install ruby@3.3.6 ... mise ruby@3.3.6 ✓ installed
Ruby 3.0.7 のインストールは失敗
デフォルト設定でのインストール
古いバージョンはどうだろうと試していったところ、Ruby 3.0 系のインストールが失敗しました。
% mise install ruby@3.0.7 ... ruby-build: using readline from homebrew ruby-build: using libyaml from homebrew ruby-build: using gmp from homebrew -> ./configure "--prefix=$HOME/.local/share/mise/installs/ruby/3.0.7" --with-openssl-dir=/opt/homebrew/opt/openssl@1.1 --enable-shared --with-readline-dir=/opt/homebrew/opt/readline --with-libyaml-dir=/opt/homebrew/opt/libyaml --with-gmp-dir=/opt/homebrew/opt/gmp --with-ext=openssl,psych,+ -> make -j 14 BUILD FAILED (macOS 15.1 on arm64 using ruby-build 20241213) You can inspect the build directory at /var/folders/h2/056_jc8n64zc7263m05bwypr0000gn/T/ruby-build.20241220223959.49076.oU8PSn See the full build log at /var/folders/h2/056_jc8n64zc7263m05bwypr0000gn/T/ruby-build.20241220223959.49076.log mise ERROR failed to install core:ruby@3.0.7 mise ERROR ~/Library/Caches/mise/ruby/ruby-build/bin/ruby-build exited with non-zero status: exit code 1 mise ERROR Run with --verbose or MISE_VERBOSE=1 for more information
原因調査
まず、エラーメッセージにあったログファイルを見ると bigdecimal.c で maybe_unused に関するエラーが出ていました。
bigdecimal.c:249:5: error: 'maybe_unused' attribute cannot be applied to types
249 | ENTER(1);
| ^
エラーメッセージで調べたところ、RubyのRedmineにチケットがありました。
Bug #20760: Ruby 3.0.6 fails to build on macOS 15.0 24A335 arm64 - Ruby master - Ruby Issue Tracking System
そのチケットのコメントには
Ruby 3.0 is EOL now. We will not backport related changes into ruby_3_0 branch.
とあったものの、 rbenv でパッチをあてるためのコマンドが書かれていました。
他のツールでパッチをあてる方法を調べたところ、GitHubの以下のdiscussionに情報がありました。
rbenv install 3.0.4 fails on macOS 13.3.1 · rbenv/ruby-build · Discussion #2185
mise については記載がなかったものの、 asdf では
% RUBY_APPLY_PATCHES=$'path/to/the/ruby-3.0.x.patch' asdf install ruby 3.0.7
でインストールするようでした。
そういえば、 mise では asdf と似たような環境変数とかがあった気がしたので、miseの公式ドキュメントを見たところ、 MISE_RUBY_APPLY_PATCHES というパッチが適用できるような環境変数がありました。
https://mise.jdx.dev/lang/ruby.html#ruby.apply_patches
MISE_RUBY_APPLY_PATCHES を利用してインストール
ということで、 MISE_RUBY_APPLY_PATCHES を使って
% MISE_RUBY_APPLY_PATCHES=https://github.com/ruby/ruby/commit/1dfe75b0beb7171b8154ff0856d5149be0207724.patch mise install ruby@3.0.7
と実行したところ、
mise ruby@3.0.7 ✓ installed
と表示され、インストールが成功したようでした。
次に、 mise ls ruby したところ、
% mise ls ruby Tool Version Source Requested ruby 3.3.6
インストールされていました。
Ruby 2.6.6 のインストールも環境変数設定が必要
ちなみにもう少し古いものをインストールしてみたところ、
という結果でした。
Ruby 2.6 系については以下のGitHub Discussionに記載がありました。
Cannot install 2.6.6 on M1 macbook · rbenv/ruby-build · Discussion #2034
そこで、 RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC を付けて試してみたところ、インストールできました。
% RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC mise install ruby@2.6.6 ... mise ruby@2.6.6 ✓ installed