04 July, 2010

xapian, a pain in the jewels... er... gem

i really want to rant on about ruby gems with native extensions and cross platform pains, but i'd rather solve a problem than perpetuate one. as such, i'll tell my xapian gem story in hopes that others can learn from it.

i'm working on a little side RoR project that requires the xapian gem to be installed. an important thing to mention is that i just recently moved to mac as my development platform, so i am a little new with their build tools, but i understand a lot of it because of time spent on *nix platforms and goofing with cygwin on windows.

anyway, i knew i would need to build and install xapian both the core and the bindings. both of those built just fine. this had me feeling pretty good, someone made sure these guys built on osx as well.

then, i got to what should've been the easy part: sudo gem install xapian

ouch!

first of all, i found the gem was hardcoded to use sed from a location other than where it's installed on snow leopard, so instead of digging through the make, rake, conf, libtool, etc... files, i just created a symlink to the location where the build was looking for it.

it turns out that all of the problems i was going to experience were related to "hard coding" in the gem. it was because the gem's owner/packager packaged up his/her generated libtool script which was for linux, so any of the x-platform dependencies were foobar on my system.

being as i'm new to mac, i continued to pick away at the references in the should-have-been-dynamically-configured-but-wasn't failed gem install directory. i advanced things quite far by finding paths, host, and os references that were linux based (especially in libtool) and fixed them to point to osx resources. this worked just fine until i got to crti.o and friends, which don't have a 1-1 osx to gnu relationship. ugh, a ton learned about gcc on the mac and i was at a dead end. i was going to have to hack way more into c code than i wanted to to get this to compile this way.

then, i had a brilliant idea, see if the source for the gem was online, and there was a link to gitorious on the rubygems page for xapian. well, look at that! there's a commit to make it build on osx.

so, i cloned that repo (not really looking at which files came down) and tried to build it. hey, that won't build, there are only two files in the repo, a Rakefile and extconf.rb. well, there's a little comment in the Rakefile that you need to pay attention to:

# Download the xapian-bindings tarball, extract it, and drop this file in there.
# Then run rake build.
#
# Alternately, gem install xapian. It's on Gemcutter.

well, i have xapian-bindings pulled and already built, plus, i know that xapian gem on gemcutter works like ass on osx, so here's what i did:

  1. i copied the files into my xapian bindings directory
  2. sudo ruby extconf.rb
  3. rake build
  4. cd pkg
  5. sudo gem install xapian -l

and finally....

gem list includes: xapian (1.0.18)

so, if you want to use the xapian gem, learn from from my experience.

1 comment:

Flekkzo said...

Means that if you tried that under *BSD, Solaris, HP-Unix, or any other UNIX or UNIX-like OS you'd be boned. Even "Linux" with it's bad file structure might not even help you because of the many (pointless) distributions.

Two things, have you contacted the author(s) to see if a more permanent solution can be evolved? And did you remember to remove those unsightly links?

It's been quite some time since I used anything UNIXy in earnest and it brings back memories to hear about it. Most often of more stories like this though which is why I left said world.

That said I assume you just want to hack (in vim, when there be Emacs! *joke*) Ruby which is something I support. Ruby is a fun language!