The Dark Balloon

A weblog by Hao Lian.
A terrible secret guarded by golems.
A note that thanks you for being born, all those years ago.

§
How to install ParseTree and RubyInline on Windows and, gasp, get them to work

ParseTree converts Ruby code to a sex expression. RubyInline is magic.

First, gem install rubyinline and gem install parsetree.

Install Visual C++ Express and the newest Microsoft Platform SDK, which is Vista SDK currently. If you wait for 2008 edition, VC++ Express will automatically install Platform SDK for you. This takes a while to download, so kidnap and chloroform a friend with spare bandwidth.

Modify C:\Ruby\lib\ruby\1.8\i386-mswin32\rbconfig.rb, which will vary depending on where you installed Ruby. If your platform is not i386-mswin32, navigate to the correct directory. Change the CONFIG["CFLAGS"] line to CONFIG["CFLAGS"] = "-MD -Zi -O2b2x".

Open up a Windows 32-bit debugging console from Platform SDK’s many Start Menu subdirectories. In addition, drag the file Microsoft Visual Studio 8\VC\vcvarsall.bat in your Program File to the console, which will paste the full file path. Press Enter. Now you have the necessary bin, include, and lib variables.

Navigate to the highly redundant C:\Ruby\lib\ruby\gems\1.8\gems path. Go into RubyInline’s folder and edit lib\inline.rb. Around line 379 and 392, manually patch the file per my poorly generated diff using a text editor or SNOBOL, which will fix quotation marks, a method call, a compiler flag, and manifest molestation.

In Inline#generate, change the file, line = line per my poorly described bug.

Now, in your console, cd to ...\gems\RubyInline-version\demo and type ruby hello.rb. You should see Hello World. If not, search Google. Common problems include missing bin/include variables, in which case use set var=%var%;c:\new\directory for the path or include variables. If the C++ compiler screws up, Google and try modifying rbconfig.rb.

OK, you have RubyInline working now. ParseTree is much simpler now that the hard part is finished. Simply wrap every builder.add_compile_flag call around line 258 of ...gems\ParseTree-version\lib\parse_tree.rb with an if /win32/ !~ RUBY_PLATFORM ... end except the -Wall since that’s the only one that works with VC++. Now run ruby ...\demo\printer.rb to make sure it works.

Congratulations. You have conquered the dragon that is compiling on Windows.

[(2007 August 8) .]

Could you provide pre-compiled win32 RubyInline and ParseTree gems (like those available on rubyforge for eventmachine and mongrel) for those of us not brave enough to conquer such terrifying dragons ourselves.

—Aman Gupta on 2007.09.19 (13:45)

Oh, both RubyInline and ParseTree are written in 100% Ruby. They merely generate C code that your computer itself must parse. As such, there’s no magical binaries I can provide to ease the process. I think the authors work primarily in Linux where compilation is as easy as opening a browser. Most of the bugs arise, though, from poor interfacing with Visual C++, so it’s better than most libraries written with a Linux-like system in mind.

Oops, I didn’t realize the compiler was a runtime dependency and not just for the building stage.

RubyInline comes with a utility called inline_package that might help. I will investigate further.

Using the package_inline tool Inline now allows you to package up

your inlined object code for distribution to systems without a

compiler (read: windows)!

The documentation is sparse, but from what I can tell looking at inline.rb, RubyInline looks in lib/inline/ for the appropriate binary (the one generated and saved into ~/.rubyinline/) before trying to compile it. So, all you have to do is copy the binary from INLINEDIR/ (or HOME/.rubyinline/) into …/gems/ParseTree-version/lib/inline/. To confirm RubyInline is using this binary from the ParseTree lib dir, look out for this warning when ParseTree is loaded: “WARNING: /Users/aman/.ruby_inline exists but is not being used”

If that works, its just a matter of packaging up a new gem that includes this file in lib/inline/

—Aman Gupta on 2007.09.19 (23:22)

I managed to put together some gems at http://web.mit.edu/~agp/www/parsetree-win32/. These should be available via rubyforge soon for all to enjoy. More details at http://groups.google.com/group/sequel-talk/browse_frm/thread/c013650e0801c061

—Aman Gupta on 2007.09.23 (15:55)

Abandon your ideas.

Use Markdown+, but not HTML. In code blocks, beware angle brackets.