Abhijit Speaks :

On Life, Technology, Stocks and Movies

Merb on Windows – Not there quite yet??

with 4 comments

I was beginning with a new web app, so I thought I’d give ‘merb’ a try. Sometimes, you just don’t choose the right thing. So I started dutifuly as one starts in the ruby world with

‘gem install merb’

perhaps that was not a very sensible thing to do. It started downloading and installing gems that it felt necessary. Things were moving fine till it came to a gem ‘dm-types’, which had  a depenedency on ‘bcrypt-ruby’. Frankly so far I was not paying attention to what was happening inside… simplying hitting enter like a layman. To install bcrypt-ruby, the native extension needs to be built. To build that native extension, I hit the error ‘nmake’ not found. Thankfully, I had visual studio installed, so when I appended the necessary path to the path environment variable, I moved a step forward when it spit out a million errors. This got resolved when i found “patch” for bcrypt-ruby for windows. This is when i thought I am almost there. Thats when my luck hit a roadblock where I hit upon the “MSC_VERSION unmatch” error. Basically, my native ‘ruby’ was compiled for visual studio 6 and such ruby does not like extensions built using other versions of Visual Studio due to MSVCRT dependencies. Perhaps I could have commented those lines and moved ahead, but didn’t do that. It seems people have done it for other projects when they encountered this problem.

I decided, lets work around this by building the bcrypt-ruby using ‘mingw’, no need to explain, this did not work either. Then back to googling again to find a version of ruby that was built for mingw. Thats when I found a lot of work that is done by luis lavena around this and could finally find a git repository where the sources for installer were there.  Unfortunately for me, all the installation process was built using rake. I had never paid serious attention to rake before. So this means learning ‘rake’ (atleast a little bit)  so as to understand whats happening inside. This basically downloads mingw/msys/ruby and a bunch of other dependencies and builds ruby.

Like previous things this did not work out of the box, I hit upon a nasty ’sourceforge redirect bug’. Basically, it is a side-effect of sourceforge’s smart mirror redirecting. What happens is – if you request a file on a sourceforge that doesn’t exist, sourceforge redirects it to next mirror using HTTP 302 and then next and next, this goes to a point where the number of file descriptors limit is reached. The way around that was to figure out the ‘exact names’ of the msys latest files. So finally managed to download all the required files that were required to build and went a step further.(This experience tells me that downolading msys/mingw as a part of building ruby isn’t perhaps the best choice)

When I started building ruby inside this the Win32API extension won’t built ‘cos the new ‘mingw make (3.81)’ did not like the windows style paths (C:\something\something). Previous versions of make would still build the Win32API and other APIs.  Thankfully there was a patch to mkmf.rb that fixed this problem and I could build ruby using mingw. The next step was to actually create the ruby installer. Luis’s package contains two installers one for the rubt runtime and one for the ruby devkit. Creating a working ‘devkit installer’ is not going to work because there are references to few gnu utilities hardcoded in the ‘wix config file’. However I could manage to create the runtime installer and install the ‘mingw-ruby’ on my windows.(I’d not get into the details of Paraffin and other paraphernalia thats required to get started with Windows wix, for I understand nothing of that)

Ofcourse then irb would break because it doesn’t like the “RUBYOPT” environment variable set by ‘original windows ruby’. Unsetting this finally, I came to a point where I could again do a “gem install merb”. I was really curious to find out whether I could really build the bcrypt-ruby. However, I didn’t even reach that far when my do_sqlite3 build failed due to a header not found (looks like I need to install some devel library for that). This when I hit the ’stop loss’. ‘cos I realised this path is fraught with danger. Because I have no idea where I will hit the next road block.

Now, I am going to relook at the whole exercise again. Possible choices are -

1. To build ruby for mingw from scratch (like without having the native mswin32 ruby) and go step by step installing all the components of the merb stack. But then I don’t know for how many components the native components will have to be built?

2, To explore whether the new one click ruby installer is built with Visual Studio Express (and then simply build the bcrypt-ruby with windows patch and move on)

3. To just get the basic merb stuff that is required for me to get started continue working on the web app and in parallel perform #1 above.

Right now undecided about which path to take, perhaps I’d take option #3 above, if it turns out that #2 is not the best choice. For now this has got ‘reniced’ to a lower priority.

Perhaps there’s still an easier way out somewher, which I have not figured out yet. Hopefully I will.

Written by gabhijit

February 15, 2009 at 4:35 am

Posted in ruby rails

Tagged with ,

4 Responses

Subscribe to comments with RSS.

  1. A few corrections to your points here:

    1. currently rubyinstaller repository (master branch) doesn’t use mingw32-make 3.81, but uses a older version instead.

    2. Noone of the WiX packages where updated to either p287 or latest RubyGems.

    3. RUBYOPT is an aberration. Latest One-Click installer make that optional, since is a real problem to many other developers. What version to you have installed?

    4. To build any extension that requires dependency on externals (any DO adapter or either sqlite3-ruby, mysql, etc) You need development headers and libraries. That’s the rule, no matter what platform you’re using.

    5. Indeed bcrypt-ruby needs patches for Windows, but that’s beyondt he scope of RubyInstaller Project.

    6. Both DataMapper and Merb team are working in improve the Windows user experience of these gems, and all work is being done in the “next” branch for adapters like MySQL, SQLite3 and PostgreSQL.

    In response to your points:

    1. Good luck in that, you will find that will be a even worse experience build by hand, and will require you workaround many limitations of both MinGW and MSYS installation and setup.

    2. You mean build ruby with Visual Studio Express? I’m saying this since RubyInstaller repository is prepared for MinGW.

    Take in consideration all the CRT issues linking to a different version of MSVCRT will be related to your quest.

    3. Right now most of DataMapper is working, except for these small pieces libe bcrypt which gem developers need to be contacted.

    Hope this shed some light in your quest.

    Regards.

    Luis Lavena

    February 15, 2009 at 7:01 pm

  2. Luis,

    Thanks for your comments. If it appears that my intention was to critisize the work of RubyInstaller, I must apologize, for that certainly was not my intention. Infact, it did give me a very good starting point.

    The whole idea is it’s not so trivial to get started with Merb on windows with ‘gem install merb’.

    1. The trouble with the current config (inside config/ruby_installer.rb) is that ‘most of the MSYS files don’t get downloaded from the sourceforge because they are not available on sourceforge. (It might be so that I accidently selected wrong version of make than 3.79, but that again buttresses my point below.)

    2. I didn’t have any troubles with runtime MSI, but with devkit MSI (this again perhaps got to do with #1 above)
    I don’t think I am going to build ruby using visual studio express myself. I will look around if there is anything like that.

    3. I fully agree RUBYOPT is not a problem of RubyInstaller.

    4. Agreed

    5. I had found a patch for bcrypt ruby somewhere (will have to dig it again)

    The problem that I faced with MSYS was quite nasty (and it’s not so much an installer problem than it is sourceforge problem or rather a side-effect). One of the reasons why I thought it might not be a good idea to have mingw/msys downloaded and installed during the build process was that both these projects themselves are moving targets. Chasing them is an additional trouble, instead it might be a good idea to have a mingw/msys environment on the PC and then build and periodically see if the builds break with newer versions of MSYS/mingw.

    Thanks for your responses again.

    gabhijit

    February 16, 2009 at 2:38 am

  3. Part of the download and preparation of MinGW/MSYS was a decision I took since manually installing that requires more instructions than the actual needed.

    The problem with sourceforge not finding those downloads is because I’ve based the old recipes in old versions of these components.

    A new set of recipes, based on latest tools was created:

    http://github.com/oneclick/rubyinstaller/blob/dsl/recipes/tools/msys.rake

    This is part of the new DSL, which I’m updating to build both 1.8.6 and 1.9.1

    The idea with suing the rubyinstaller repository is for other developers to hack and provide patches and help out getting Ruby working.

    Sorry for making this a painful experience, but didn’t found the time to update the master recipes to match the new packages.

    Luis Lavena

    February 16, 2009 at 11:03 am

  4. Oh well, Mea culpa that I didnt look around well enough to find out about this… I have been a bit lazy to learn ‘git’ and use it..

    gabhijit

    February 16, 2009 at 1:14 pm


Leave a Reply