libxml-ruby and Windows

Posted by Pieter Bos Tue, 09 Oct 2007 12:41:25 GMT

So, my first post on movesonrails.com! You might not know me, but I am one of the Nedap Healthcare developers. Usually I don't work on Moves or even with ruby on rails, but I needed some functionality...

You might have seen a patch by Bart that allowed ActiveResource to be used with Libxml-ruby, with a dramatic performance increase. The downside was, you can't use libxml with Windows, limiting your applications to mac-os and linux. There was one build of libxml-ruby, which didn't really work, is an older version and missed some rather important files.

But now you can use libxml-ruby in windows! Just unpack this zip into your ruby directory, rename ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xmlparser.so to xmlparser.s_ and you'll have libxml 0.5.2.0 !

If you'd rather had libxml-ruby 0.3.8.4, you can download this zip instead, or even 0.5.1.0

To achieve this, I spent a morning compiling libxml with mingw. Just forget the following if you just want to use this, but for the sake of future version, this is what i had to do:

1 . install mingw and MSYS in the standard directories (c:\mingw)

2 . download the ruby source and compile, in a different directory than c:\ruby:

./configure --with-prefix=c:/mingw/ruby
    make
    make install

3 . download the zlib, iconv and libxml sources

4 . compile all of them with :

./configure --with-prefix=c:/mingw
    make
    make install

5 . download libxml-ruby

6 . now, the tricky part. You won't have rake (you didn't compile it) so we have to do a trick. Go to your libxml-ruby source directory and type:

    /c/mingw/ruby/bin/ruby ext/xml/extconf.rb
    make
    make install

7 . everything has been compiled. Just copy these files:

    to ruby\bin:
    c:\mingw\bin\iconv-2.dll
    c:\mingw\bin\libxml2-2.dll
    
    to ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml:
    C:\MinGW\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml\libxml_so.o
    
    to ruby\lib\ruby\site_ruby\1.8\xml
    C:\MinGW\ruby\lib\ruby\site_ruby\1.8\xml\libxml.rb
    

have fun with a 20 times faster XML parser :)

update! versions 0.5.2.0 and 0.3.8.4 also available!

download 0.5.2.0 or 0.3.8.4

Tags , , , , ,  | 11 comments

Solving some gem install problems

Posted by Andre Foeken Sun, 29 Jul 2007 16:08:14 GMT

Lately we have been having some issues installing gem that have to compile native extensions like libxml-ruby and termios.

The error we got from libxml was: "extconf failure: need libm". Strangely this was all caused by incorrect compile flags in the rbconfig.rb file.

To fix this (and other issues) you can customize the rbconfig.rb file to your specific computer.

Mine was located in:

 /usr/lib/ruby/1.8/universal-darwin8.0/rbconfig.rb

On leopard this is universal-darwin9.0. The file contains a lot of config definitions. I removed all traces of any other architecture then i386 (like -arch x86_64, etc). I also removed the 64 flag that was included.

After altering this in the entire file (quite a few replaces), everything compiled happily.

update

I was also having some issues with the SQLSessionStore plugin. Seems recent changes to ruby have made it a no-no to alter constants (no surprise there). So now in stead of doing

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS. update(:database_manager => SqlSessionStore)

You have to do:

dso = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS dso[:database_manager] = SqlSessionStore ActionController::CgiRequest.send(:remove_const, "DEFAULT_SESSION_OPTIONS") ActionController::CgiRequest.const_set("DEFAULT_SESSION_OPTIONS", dso)

Which is uglier, and still should not be possible :)

To make it work I also had to remove the require 'mysql' line from the plugins MySqlSession.rb file. Else it would crash rails with the following error:

warning: already initialized constant OPTIONS

Posted in ,  | Tags , , , , , , , , , , ,  | no comments

Speeding up Active Resource

Posted by Bart ten Brinke Thu, 19 Jul 2007 08:20:47 GMT

As I was trying to import 12 MB of XML, it quickly became very clear that the SimpleXML used in Hash.from_xml was not going to cut it. It took nearly four minutes to convert the xml data to a hash!

As Active Resource will probably be used to handle large xml files, I created a patch so that libxml is used to parse the xml. This made fetching the active resource go from 240 seconds to 12 seconds. That 20 times faster!

The net override (also included) makes downloading a factor four faster.

Find the patch here: http://dev.rubyonrails.org/ticket/9017

Posted in  | Tags , , , , ,  | no comments