今更ながら Ruby 1.9.3 インストール

Ruby 2.0 が出てる今日このごろ。ちょい前に会社で作ったアプリの動作環境を作るのに、Ruby 1.9.3 を入れることにした。rvm は既にあるから install を実行。

$ rvm install 1.9.3
Installing Ruby from source to: /Users/watanata/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)...

エラーが出たので ~/.rvm/log/ruby-1.9.3-p392/make.log を見てみると、こんな感じ。

[2013-04-02 14:05:32] make
        CC = clang
        LD = ld
        LDSHARED = clang -dynamic -bundle
        CFLAGS = -O3 -ggdb -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration  -pipe
        XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
        CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/Users/watanata/.rvm/usr/include -I. -I.ext/include/x86_64-darwin11.4.2 -I./include -I.
        DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
        SOLIBS =
...
compiling bignum.c
bignum.c:2732:26: warning: while loop has empty body [-Wempty-body]
        while (--ny && !zds[ny]); ++ny;
                                ^
bignum.c:2732:26: note: put the semicolon on a separate line to silence this warning
1 warning generated.
...
compiling st.c
st.c:520:35: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
            i = table->num_entries++;
              ~ ~~~~~~~~~~~~~~~~~~^~
1 error generated.
make: *** [st.o] Error 1


検索してみたら Ruby Forum に投稿があって、Ruby 1.9.3-p385 以降 + clang 4.2 で出るエラーだとか。clang が 4.1 だと出ないらしいけど、自分の環境は 4.2 でビンゴ。そーですか。

対処方法は?と思ってたら、トリビアル・イシューズ さんに対処方法が紹介されてた。

このエラーは -Wshorten-64-to-32 の警告と警告レベルをエラーとして扱う -Werror により発生する。対応策は単純にビルド時に警告を無視するように指定するのみ。具体的に言うと以下のコマンドを実行してからビルドする。
 
$ export CFLAGS=-Wno-error=shorten-64-to-32

ruby-1.9.3-p385以降のインストールでバグあり - トリビアル・イシューズ


openssl と readline が古いとダメっぽいとのとなので、ついでに最新版に更新して rvm install 1.9.3 を実行。無事インストールできたよ。:-)

$ export CFLAGS=-Wno-error=shorten-64-to-32
$ brew install readline openssl
$ rvm install 1.9.3
$ rvm list 
rvm rubies
...
=> ruby-1.9.3-p392 [ x86_64 ]
動作環境
  • Mac OSX 10.7.5
  • rvm 1.18.21
  • homebrew 0.9.4
  • clang 4.2
  • openssl 1.0.1e
  • readline 6.2.4