Wednesday, May 11, 2011

Installing Thin (Rubygem) on Windows

After struggling for nearly 2 days, I finally managed to get the Thin gem installed on my Windows system. I enjoy developing Ruby on Rails, but I don't want to work with Linux environments. I always develop on Windows, and now that my project is entering the final stages, I was looking for a small webserver that allows me to deploy the project on. This is where Thin comes into play.

You can try to use rubygems for installing the Thin gem, and it might actually work. I always prefer to use the latest version for my gems to ensure I have all potential bugs solved and know I'm working with the most recent version.
The problem I encountered with Thin is that it did not compile from source because of 2 reasons:

1: The paths generated by Rake are wrong
If you try to run the rake command on the Thin source, you'll eventually encounter an error saying it cannot make the target ruby.h for the thin_parser. The exact error I encountered looks like this:

make: *** Er is geen regel om doel '/C/Ruby/include/ruby-1.9.1/ruby.h' te maken,
nodig voor 'thin.o'. Gestopt.

I'm sorry it's in dutch, but the output should be similar regardless of the language your Windows OS is in. As you can see from the error message, it's looking for a file called '/C/Ruby/include/ruby-1.9.1/ruby.h'. I've personally never seen such a path in Windows, and this is what causing the problems. Apparently the mkmf library in ruby has an issue generating the correct paths under Windows. Fortunatly this is nothing that can't be fixed.

If you take a look inside the /tmp//thin_parser/ you will find a file called 'Makefile'. using a texteditor you can open this file and you'll see the following content:

#### Start of system configuration section. ####

srcdir = ../../../../ext/thin_parser
topdir = /C/Ruby/include/ruby-1.9.1
hdrdir = /C/Ruby/include/ruby-1.9.1
arch_hdrdir = C:/Ruby/include/ruby-1.9.1/$(arch)
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby


2 of the three paths are completly wrong for Windows. To fix the problem, make sure the lines look like this:

#### Start of system configuration section. ####

srcdir = ../../../../ext/thin_parser
topdir = C:/Ruby/include/ruby-1.9.1
hdrdir = C:/Ruby/include/ruby-1.9.1
arch_hdrdir = C:/Ruby/include/ruby-1.9.1/$(arch)
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby


Ofcourse, make sure the paths actually match your Ruby installation, or it still won't work ! Save the file and open a command line to the path of the make file. Just run the make command and the object files will be properly generated.

Problem 1 solved.


2: The GEM cannot be compiled into a GEM file.
After solving problem one, we need to tackle problem two. You CANNOT run the 'rake compile' anymore or your makefile will be overwritten and your object files will be removed. So please don't do this.

If you run the 'rake gem' command, you'll probably receive the following error message:

C:\Source\git\thin>rake gem
(in C:/Source/git/thin)
NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be
removed on or after 2011-10-01.
Gem::Specification#has_rdoc= called from tasks/gem.rake:16.
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
rake aborted!
Don't know how to build task 'COPYING'


It seems there's something wrong with the gem command. The commands for rake can be found in the /tasks folder of your Thin source directory. Inside that folder is a file called 'gem.rake'. Open the file with a text editor and look at line #27:

s.files = %w(COPYING CHANGELOG README Rakefile) +
Dir.glob("{benchmark,bin,doc,example,lib,spec,tasks}/**/*") - Dir.glob("lib/thin_parser.*") +
Dir.glob("ext/**/*.{h,c,rb,rl}")


All looks well except for that COPYING. There is no such file inside the source directory and this is what causes the problem. Remove the word COPYING from that line, save the file and run the 'rake gem' command again.
The gem should now be compiled. To install the gem use the command line to navigate to the pkg folder and run the following command : 'gem install thin-version.gem'

2 comments:

  1. An update to all this, if you have minGW installed, you can avoid all this mingling by running all the commands through the msys shell.

    The shell is smart enough to translate all the paths to Windows paths and this allows the commands to function properly.

    Still doesn't solve errors in the source code however.

    ReplyDelete
  2. Alright,

    received word from the Author today that these problems are fixed in Thin, so this topic is no longer required.

    ReplyDelete