Building IronRuby on cygwin
For the past few years I have found cygwin to be an indispensable tool on windows. Since I already have my Ruby environment configured in cygwin, I thought I’d try to get IronRuby building from cygwin. It took a bit of tweaking but in the end it was relatively simple and I enjoyed spelunking around in the IronRuby build file - trunk/Rakefile.
The first change is due to the fact that case matters in ‘nix and therefore cygwin, but of course it does not on Windows. On line 27 of Rakefile you’ll find the code block:
if ENV['mono'].nil? FRAMEWORK_DIR = Pathname.new(ENV['windir'].dup) + 'Microsoft.NET' + 'Framework' + 'v2.0.50727' else ...
The problem for cygwin is that the environment variable is actually named WINDIR (uppercase), which to cygwin is not the same as windir (lowercase). Modifying the Rakefile to ..ENV[’WINDIR’].dup… gets us almost there.
The second change is due to the differences in paths in ‘nix/cygwin and Windows. Since we’re running under cygwin for the most part we want the ‘nix/cygwin paths as is. However the Rakefile has to delegate off to the .NET compilers to build IronRuby. They expect Windows paths. So we need to change /cygdrive/c/ to C:\. Pretty simple. The other change I discovered is that although Windows accepts a ‘/’ (forward slash) as a valid path separator, the csc compiler does not.
On line 193 of the Rakefile you’ll find the method self.exec(cmd) in the Commands class. At the top of the method add the lines:
if RUBY_PLATFORM =~ /cygwin/ cmd.gsub!(//cygdrive/c//, 'C:\') cmd.gsub!(/([A-Za-z0-9])//, '1\') end
These are the only changes needed in the Rakefile. However you might run into one more problem as I did. I had originally checked out the IronRuby source in my home directory ~/code/ironruby/ which expands to C:\\Documents and Settings\\jason\\My Documents\\home\\code\\ironruby\\. This becomes a problem in cygwin because the Rakefile passes the full path to each .cs file in the project. The linux kernel and therefore cygwin only allow a 128K buffer for passing arguments. If the IronRuby source is located in a long path you might get the error too many arguments. I “fixed” this by putting the IronRuby source in a shorter path (C:\ironruby).
Voila! You should be successfully building on cygwin.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
January 12th, 2008 at 7:01 pm
By the way, Linux now supports variable argument length so you are not limited to 128K buffer.
Gory details here:
http://kernelnewbies.org/Linux_2_6_23
January 13th, 2008 at 8:08 pm
Seo:
Thanks for the heads up! We’ll have to see when this makes it to cygwin.
January 13th, 2008 at 8:09 pm
FYI … the above fix needs to modified a bit to both build IronRuby (requires windows-ized paths) and run the tests which need cygwin paths