Coin-C Tumblr

Thread Safe libxml2 for iOS

My self-built framework for accessing Last.fm data does a lot of XML-parsing. I could have chosen for JSON, I guess, but I started of with XML and somehow stuck with it because changing it over seems like a waste of time to me.

That is, if my XML parsing is fast enough. With the successor of Last Concerts comes even more data fetching from Last.fm and thus more data parsing, and so performance has become an important aspect. Thanks to GCD it is easy to offload the XML parsing to a separate thread, but most libraries are not thread safe.

It is very unfortunate that this excellent comparison between XML parsing libraries does not mention this. It is also very disappointing that iOS does not ship with a thread-safe version of libxml2 (it ships with libxml2.2.7.3) instead of with a more recent version. Maybe I’m missing something.

So, having a need for a thread safe XML parser I decided to compile libxml2 myself. Here is the script that I got to do it, heavily inspired by this excellent description of cross-compiling open source software on the command line. Maybe it will serve somebody else as well.

You can find it embedded below, or else on pastie.org.