Building Standalone FXRuby Applications with Exerb

Distributing FXRuby-based applications to end-users who don’t have Ruby (or FXRuby) installed on their computers can be a challenge. Fortunately, there are a number of freely available tools for building “standalone” versions of Ruby applications. In this post, we’re going to focus on how to use Exerb, developed by Yuya Kato, to build standalone FXRuby applications on Windows.

The first step is to download and install the latest Exerb distribution (version 4.2.0, as of this writing). It’s packaged as a ZIP file, which you’ll need to extract into some convenient place on your hard drive. Once that’s done, change directories into the exerb-4.2.0 directory and run the setup.rb script.

Now, to actually go through the process of building a standalone FXRuby application, let’s start with a simple example. We’ll use the hello.rb example program from the FXRuby source code distribution. The first step is to generate a “recipe” file for your Ruby application, which is basically a listing of all the files that Exerb should use to build the executable. You’ll use the mkexy tool to do this.

ruby -r exerb/mkexy hello.rb

The mkexy tool runs your application in a custom version of Ruby to analyze which libraries it requires while it’s running. Once you exit the application, mkexy spits out a recipe file (for this example, hello.exy) in the current working directory.

Now that you have a recipe, you’re ready to run Exerb to generate the executable.

exerb hello.exy

Note that the executable that Exerb creates is quite large, as it bundles both a copy of the Ruby interpreter as well as the FXRuby library code. When I did this experiment, the executable weighed in at close to 9 Mb. You can distribute this executable to other people who don’t have Ruby or FXRuby installed on their computers.

Now let’s look at a slightly more complicated example, the hello2.rb program. The complication is that this example uses an external file, a PNG icon that it loads from disk at runtime, as shown in this excerpt:

This is unfortunately something that Exerb doesn’t handle very well, but there is a workaround. What we must first do is dump the contents of the PNG icon to a Ruby string, and store the contents in a regular .rb file. Here’s some code to do that:

Now we need to modify the bit in hello2.rb that loads the icon data, so that it instead loads this Ruby code instead:

Now, run the mkexy tool as before to generate a recipe file (hello2.exy) and then exerb to generate the executable.

ruby -r exerb/mkexy hello2.rb exerb hello2.exy

There are at least a couple of other tools out there for building standalone Ruby applications, including Erik Veenstra’s RubyScript2Exe and Jeremy Hinegardner’s Crate. I’m not at all familiar with how those tools work, but if you’ve had luck building standalone FXRuby applications with either of these tools, I’d love to hear about your experience.

Posted December 30th, 2008 in FXRuby.

Comments are closed.