MacBookにThriftの環境を構築
「WEB+DB PRESS Vol.46」のRecent Perl Worldに載っていたThrifの記事が面白かったので、とりあえずMacBookに環境構築してみました。
ちなみにThriftはFacebook発の多言語RPCフレームワーク。もちろんオープンソース。異なる言語で書かれたプログラムを、RPCでつなげるというフレームワークです。
以下のfacebookのサイトからソースをダウンロード。
http://developers.facebook.com/thrift/
ダウンドーロしたファイルを適当なディレクトリに移動(僕の場合ルート直下にprogramingディレクトリを作成してそこに移動)
./configureを実行。
tar xfv thrift-20080411p1.tar cd thrift-20080411p1 ./configure
すると以下のようなエラーが。
checking for boostlib >= 1.33.1... configure: error: We could not detect the boost libraries (version 1.33 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in. See http://randspringer.de/boost for more documentation.
boostライブラリがないよ、というエラー。WEB+DB PRESSにも「C++の拡張ライブラリであるBoostが利用されており、必須である」とあるので、Boostをインストール。
http://www.boost.org/のDownloadリンクから、boostのソースをダウンロード(boost_1_36_0.tar)。
programingディレクトリにファイルを移動して、./configureを実行。
tar xfv boost_1_36_0.tar cd bost_1_36_0 ./configure make sudo make install
これでもう一度Thriftのインストールへ。
cd ../thrift-20080411p1 ./configure make sudo make install
今度はエラーなく終了。
各言語からThriftを利用するためには言語別のライブラリが必要になるので、それらをインストールします。今回は、PerlとRubyとPythonのライブラリをインストールします。
perlcd lib/perl perl Makefile.PL sudo make installruby
cd ../rb ruby setup.rb config ruby setup.rb setup ruby setup.rb installpython
cd ../py python setup.py install
これでThriftの準備完了。WEB+DB PRESSに掲載されているサンプルのhello.thriftを作成して保存します。
#!/usr/bin/thrift
service Hello
{
string hello(1:string name)
}
で、以下のコマンドでC++、Perl、Ruby、Pythonのコードを生成します。
thrift --gen cpp --gen perl --gen rb --gen py hello.thrift
gen-cpp、gen-perl、gen-py、gen-rbフォルダが生成されていれば成功です。
