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'

Tuesday, May 10, 2011

Ruby on Rails

Well,

Let me start of saying that I love Ruby on Rails. The syntax of the language, the possibilities, the speed at which you can develop. There's currently nothing that can beat it in my oppinion. Ask any Ruby on Rails developer and he will probably tell you the same.

However, what they don't tell you, is that it's becomming a serious pain over the years to get most things running on Windows machines. Alot of the gems that are beeing used either drop support for Windows systems, or never included it to begin with. And honestly it's starting to piss me off.

"Deploying Ruby on Rails is easy". Quoted literally from the Ruby on Rails page. Let me tell you, it's not !
The page lists various installations and tricks that can make the deployment of such an application seem like childsplay. Let's go over them shall we?

- Fusion Passenger Mod : No Windows Support --> Failed on the "easy" part
- Proxy Setups : Tried it and failed miserably. only NGINX got what I wanted
- JRuby : Not even going there...

I've been working with the rubygems system for quiet some time now. The system is simply marvelous, except for the flaw that alot of gems don't compile under Windows.
Now before you start jumping around talking about compilers etc:
- I have the Ruby DevKit installed and configured
- I have a complete msys minGW system setup with make etc, all working from commandline

The problem is that some gems cannot compile without alot of stuff installed beforehand or having specific requirements installed.
Are all gems bad then? No, definitly not. There's some out there that have great documentation of all the required gems that need to be installed and some even describe on which sources/libraries/applications need to be available to compile the gems.

Unfortunatly not all gems are like that. Some simply state they do not support Windows. Then i'm asking, what's the point of creating open-source projects that are supposed to be platform independant? I mean, that's the point of Ruby on Rails is it not?