Thursday, March 13, 2008

Compiling ruby-xslt on Windows

After much head bashing I've gotten the ruby-xslt gem to compile on Windows. Roughly, here are the steps I went through:
  1. Make sure libxml-ruby is working. See my previous blog post on installing it for Windows.
  2. 'gem install ruby-xslt' this downloads the gem and attempts to compile and install. It fails, but it leaves all the files in your ruby\lib\...\gems folder. I got 0.9.5 version of ruby-xslt
  3. Download the latest versions of libxml2, libxslt, and libiconv with all the binaries, includes, and libs for Windows. I copied the *.dll files into my windows\system32 folder.
  4. Now the trial and error began. I had to tweak the Makefile to get the include and lib paths correct for my system.
  5. I was using the MS Visual Studio (VS) tools NMAKE and CL. A major issue was the version of these tools. I started off with the VS 2005, but discovered that it links to a different version of the C runtime that is not compatible with the dependent DLLs, like libxml2.dll, etc. I had to install VS 6.0, and this seemed to solve the problem.
  6. Next I needed to make some modifications to the xslt_lib.c file. It seemed to be using some non-ANSI C constructs that MS C compiler didn't like. These seemed to be C99 compliant stuff like dynamically allocated arrays, but apparently VS does not support C99.
  7. Finally, got a compiled and linked version that works. Since by this time I didn't feel like messing with gem install scripts, I just manually moved all the files into their normal ruby directories.
  • => \ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml folder
  • xslt.rb => \ruby\lib\ruby\site_ruby\1.8\xml
The changed files plus the pre-compiled DLL ( are available from the Aquifer SourceForge site.


complier said...

If you're willing to do everything under Cygwin then you can get it working that way. I couldn't get the binaries to work with pure Windows, so I used them under Apache in Cygwin, which works OK. There's a fair bit of trial and error, but you need to
1) include the libxml and libxslt libraries (I also included libxml2 to be safe)
2) install gems from the tarball from the command prompt in cygwin (there's a setup.rb file in there somewhere)
3) Fix up any errors with gems you get, a search on the web will give you the answers. I think this has to do with the tar-ball and the one-click gems being different so you may not hit this problem if you haven't already used the one-click ruby installer
4) Install apache under Cygwin and run it

complier said...

For that step 1) you include those libraries under Libs in Cygwin.
There's also step 3.5 where you install the libxml and ruby-xslt gems, I can't remember the libxml command, but ruby-xslt is
gem install ruby-xslt
from the Cygwin command prompt