Monday, March 21, 2011

Installing windows platform specific gem libxml-ruby with Bundler

I was facing some issue in installing 'libxml-ruby' gem on my windows machine with bundler. The entry in the Gemfile was :-

gem 'libxml-ruby', '1.1.3', :require => 'libxml'

This works perfect on unix machines, but fails on windows machine (which is my local development platform) during building native libraries.

The DevKit has already been set up on my machine. So I tried doing gem install first :-


So, I mentioned the platform while doing gem install and it worked as below :-

D:\>gem install libxml-ruby -v=1.1.3 --platform x86-mswin32-60
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed libxml-ruby-1.1.3-x86-mswin32-60
1 gem installed
Installing ri documentation for libxml-ruby-1.1.3-x86-mswin32-60...
Installing RDoc documentation for libxml-ruby-1.1.3-x86-mswin32-60...
D:\>


However, with bundle install, it gave the same error on the windows machine : ERROR: Failed to build gem native extension.
I tried specifying Gemfile :platforms option - 'mswin', 'mingw' for Windows platform, but it did not work.

Finally, the :path parameter rescued me out of the pain. With :path parameter, you can specify that a gem is located in a particular location on the file system. The ':path' option requires that the directory in question either contains a '.gemspec' for the gem, or that you specify an explicit version that bundler should use. So the bundler uses the gem from the source specified in the path and it resolved my issue with installing libxml-ruby gem with bundler on windows machine. The steps that I followed :-

(1) Download the libxml-ruby-1.1.3-x86-mswin32-60.gem gem from http://rubyforge.org/frs/?group_id=494 and do gem install
OR
gem install libxml-ruby -v=1.1.3 --platform x86-mswin32-60

(2)From app_root>gem unpack libxml-ruby-1.1.3-x86-mswin32-60

(3) Gemfile.lock :-

gem 'libxml-ruby-1.1.3-x86-mswin32-60', '1.1.3', :require => 'libxml', :path => 'vendor/gems/libxml-ruby-1.1.3-x86-mswin32-60'

(4) Now, when you execute bundle install, it will bundle the gem from the source specified in the :path -

Using libxml-ruby-1.1.3-x86-mswin32-60 (1.1.3) from source at vendor/gems/libxml-ruby-1.1.3-x86-mswin32-60

6 comments:

  1. I've been able to bundle it as specified, but I am still unable to start my server. It is complaining about:

    no such file to load -- libxml_ruby (MissingSourceFile)

    I believe that libxml_ruby is provided in the DLL files that come with the windows version of the gem. I do have those DLL files in my path so they can be found.

    Also the DLL files seemed to be loaded fine before switching to bundler. Any ideas why the DLL files are now not being loaded as needed?

    ReplyDelete
  2. @ben when you unpack a native gem it does not copy the libxml_ruby.so file inside vendor/gems/libxml_ruby*/lib
    That was a little painful to copy it manually.
    Hope this helps !

    ReplyDelete
  3. Thanks Amit !
    Hi Ben,
    Please let us know whether Amit's suggestion helped you to resolve your issue.

    ReplyDelete
  4. @Amit and @Niranjan yep it sure did. Hard to believe that is the one thing I didn't try, I never thought a windows box would ever use an .so file, but I was wrong. Thanks for pointing it out!

    ReplyDelete
  5. Nice thought of life by Niranjan by learning at least one thing everyday. Thanks for giving us tips on how to install libxml_ruby gem on windows machine with bundler.
    sap upgrade

    ReplyDelete