Churning Ruby into EXE #
I’m greatly impressed with RubyScript2Exe by Erik Veenstra, which wraps your Ruby script and all its dependencies (including Ruby) up in a nice executable for Windows users. I’m using it on MouseHole and I can count on one hand how long it took to get it working. Easier than riding a bike, more like learning to use a coaster.
The only caveat is getting used to the idea that when the user clicks on the executable, your application is going to get unpacked in a temporary directory elsewhere. So if you have images or config files you want to store alongside the .exe, you’ll need to use some of RubyScript2EXE’s constants.
APPLICATION_DIR = File.dirname(__FILE__) if defined? RUBYSCRIPT2EXE_APPEXE APPLICATION_DIR = File.dirname( RUBYSCRIPT2EXE_APPEXE ) end
Under RubyScript2EXE, the __FILE__
constant won’t work like you think it will. It’ll give you that same obscure temp directory. But you can still sniff out the application’s directory by checking for the RUBYSCRIPT2EXE_APPEXE
constant.
There aren’t a whole lot of Rake+RubyScript2EXE examples around, but if you’re using the traditional bin/, lib/, tests/
structure found in most RubyGems, the Rake recipe would look like:
RUBYSCRIPT2EXE = ENV['RUBYSCRIPT2EXE'] || File.join(Config::CONFIG['bindir'],'rubyscript2exe.rb') RUBY_MAIN_SCRIPT = ENV['RUBYMAINSCRIPT'] || 'bin/mouseHole.rb' EXEC_TARGET = File.join(RUBY_MAIN_SCRIPT.sub(/rb$/, 'exe') ) file :executable => [ RUBY_MAIN_SCRIPT ] do | t | unless File.exist?(RUBYSCRIPT2EXE) raise RuntimeError.new("rubyscript2exe.rb not found " + "pass with RUBYSCRIPT2EXE=/path/to/rubyscript2.rb") end sh %{ruby "#{RUBYSCRIPT2EXE}" #{RUBY_MAIN_SCRIPT}} File.move(EXEC_TARGET, 'build') puts "Created executable file build/#{EXEC_TARGET}.exe" end
bluetechnx
on a related topic…does anyone know why when I have AllInOneRuby.exe and rake.rb in the same directory I get no output when I try to use rake?
With normal Ruby+Rake on my system: ruby rake.rb -v rake version 0.6.0 C:\>
using allinoneruby.exe + rake: allinoneruby.exe rake.rb -v
C:\>
...which is odd…any help? Rake, allinoneruby and rubyscript2exe are awesome!!
Tsela
why, you made a small mistake: despite its name, RubyScript2Exe can also produce standalone Linux or Mac OS X executables. It’s written on the first line of the introduction of the online documentation of RubyScript2Exe . You make it look as if it is only available on Windows, while the tool itself is platform-agnostic.
That said, it’s great that you give a little publicity to this project. It looks great indeed!
why
Thanks, Tsela. You’re right on about that. Just ran it from my laptop and it left a little:
mouseHole_linux
executable right there.Aslak
Could RubyScript2Exe be used to wrap up something more complex, like, say a RoR app with all the extra non-ruby files the app will contain, as well as RoR itself and any other dependencies (rubygems) too?
why
Sure. I’ll bet it could be boiled down to a single Rake task. Since Rails depends on
__FILE__
quite a bit, it’d be best to use pragmas to be sure the accessories (public/, config/database.yml
) get included in the 2EXE archive.However, it would be even better if your app used he
APPLICATION_DIR
logic above inconfig/environment.rb
. That way you can includeconfig/database.yml
outside of the 2EXE archive so you can modify it for a specific installation’s needs.You’ll also need to hunt down binaries for MySQL, SQLite on Windows.
Dave Burt
... and MySQL binary hunting on Windows is hard.
rhubarb
How does this compare with Exerb? http://exerb.sourceforge.jp/index.en.html
srf
For Rails: http://www.erikveen.dds.nl/distributingrubyapplications/rails.html
Comments are closed for this entry.