Installing Thrift on Snow Leopard
Yesterday I spent the day with Thrift. Thrift is a framework developed at Facebook for “gluing” together programming languages. The Thrift framework enables efficient and scalable communication between C++, Java, Python, PHP, XSD, Ruby, C#, Perl, Objective C, Erlang, Smalltalk, OCaml, and Haskell. Thrift allows you to chose the right programming language for the job at hand. With Thrift you won’t have to chose between development speed and performance – you can have your cake and eat it too. If you are an employer, you can relax language restraints and focus on finding the smartest people. Thrift is still very much in its infancy, and documentation on getting it to work is sparse. I hope to shed some light on Thrift and make it just a little bit easier to get up and running. This post will focus on installing Thrift. I will write a follow-up post on how to use Thrift to communicate between PHP and C++.
If Thrift is still very new and lacks documentation – why bother learning it? Especially when there are more mature alternatives like Google’s Protocol Buffer and SOAP. The answer depends on your requirements. I write web-based financial applications. I use PHP as my server-side scripting language, and C++ for the heavy-lifting. As of this writing, Protocol Buffer does not support PHP, and the SOAP protocol has too much overhead for the high-speed finance world. Furthermore, I think Thrift has more potential than both alternatives and will gain in popularity as more people learn it. Also apparently Thrift was developed by Google engineers working at Facebook who missed using Protocol Buffer, so they re-built it and expanded its feature set. You can find more information on the differences between Thrift and Protocol Buffer at: https://stuartsierra.com/2008/07/10/thrift-vs-protocol-buffers.
I will be first to say that installing Thrift was a pain. I spent about four hours getting everything to work. However, most of this time was spent finding up-to-date information. I hope to get you up in running in less than an hour. This tutorial is aimed for Snow Leopard users, but I’m sure it would apply to Leopard developers as well. I am assuming you have Xcode installed. I will also say that I am not a Unix expert – this build worked for me – I am not entirely sure about the current state of my computer (ie. what dependencies I installed in the past), but I will try to make this tutorial as generic as possible. First we’ll need to install a few dependencies before we can start installing Thrift. Update: Do not try and install these dependencies or thrift using macports. There are some inconsistencies with the macport builds. (Thanks Jonathan!)
Boost is a set of C++ libraries that Thrift depends on. You can download it at: https://www.boost.org/users/download/. I downloaded Version 1.41.0. Once it’s downloaded, you’ll need to unzip it. For this I just use The Unarchiver, but using the gzip terminal command works too.
Now we’ll use the information provided with the install to build Boost, you can find that information by navigating to the unzipped boost directory and going to: index.html > “Getting Started Guide” > “Getting Started on Unix variants (e.g. Linux, Mac OS)” > “5.1 Easy Build and Install” The steps described in the documentation are as follows:
sudo ./bjam install
The install will take a while! This is a good time to take a break from your computer – grab a coffee, do some push-ups. Once Thrift is all set up you’ll have plenty of time to soak up the LCD rays… back with a sweat? Great! Well, that should do it. You should find evidence of boost in: /usr/local/include/ and /usr/local/lib/.
The next dependency we’ll need is libevent. Libevent is an over-the-network event notification API. Now that’s a mouthful.. I’m pretty sure Thrift uses it to do client / server communication between the programming languages. The good news is you won’t have any time to exercise – this is a quick build. Download libevent from: https://monkey.org/~provos/libevent/. I downloaded libevent-1.4.13-stable.tar.gz. Navigate to where you downloaded it, unzip it, cd into the unzipped directory, the run the following commands:
sudo make install
I’m not entirely sure where the build ends up, but Thrift will yell at you if something went wrong so let’s move on.
Alright! We’re so close. Let’s install thrift. You can download thrift from https://incubator.apache.org/thrift/download/. I downloaded thrift-incubating-0.2.0.tar.gz. After it finishes downloading, unzip it, navigate into the directory and run the following commands:
sudo make install
And you’re done! You will find the thrift build in /usr/local/bin You should be able to run thrift from the terminal.
Now that wasn’t too bad! If you have any problems with building anything do not hesitate to ask – I will do my best to answer your questions. Stay tuned for the next article on how to establish communication between PHP and C++ using Thrift!