I recently mentioned the fact that RubyScript2Exe 0.5.3 doesn't play well with recent versions of RubyGems. At the end of that post I mentioned that there are alternatives emerging for creating executables from your Ruby code, including Lars Christensen's OCRA, the One-Click Ruby Application Builder.
I've had a chance to take OCRA for a short test drive and it looks promising. Like Erik Veenstra's RubyScript2Exe, OCRA lets you "compile" your ruby code into an EXE file that you can distribute to others, without requiring that the users have Ruby installed on their PCs. To quote the OCRA page:
The executable is a self-extracting, self-running executable that contains the Ruby interpreter, your source code and any additionally needed ruby libraries or DLL.
OCRA can be installed via RubyGems: open a console window and type:
gem install ocra
It's also available from the RubyForge page. Version 1.0.2 is the latest as of this writing.
The syntax to compile a script is...
ocra.rb [option] your/script.rb
...where option is one or more of the following:
--dll dllname Include additional DLLs from the Ruby bindir.
--no-lzma Disable LZMA compression of the executable.
--quiet Suppress output.
--help Display this information.
--windows Force Windows application (rubyw.exe)
--console Force console application (ruby.exe)
--no-autoload Don't load/include script.rb's autoloads
Thus far, I have exercised only the --windows and --console options.
To create a non-console application, either use the --windows option or give your script the .rbw filename extension. Compiling a basic non-console script is as simple as opening a console window, navigating to the folder containing your script, and typing:
ocra.rb myscript.rbw
OCRA will then run your script to check for dependencies, gather the necessary files, and create your executable. An option to avoid fully running the script would be nice, similar to RubyScript2Exe's exit if RUBYSCRIPT2EXE.is_compiling? idiom.
OCRA uses LZMA compression, so the resulting executable is relatively small. A simple wxRuby app, for example, resulted in a 2.5 Mb executable. The same app compiled with RubyScript2Exe weighed in at over 9 Mb. Apps that do not require a GUI toolkit will be even smaller, perhaps 500k.
I haven't spent a lot of time with OCRA yet, but I think it shows great potential and I want to thank Lars Christensen for his efforts. If you have a need to distribute Ruby programs to non-technical users, you should check it out and pass your feedback along to Lars.
Thanks for stopping by!
7 comments:
"An option to avoid fully running the script would be nice, similar to RubyScript2Exe's exit if RUBYSCRIPT2EXE.is_compiling? idiom."
exit if Object.const_defined?(:Ocra)
Enjoy.
Thanks. With OCRA and your clear directions it produced an executable. However, when I tried to run the executable, nothing happened, even when I right clicked the .exe file and selected "Run as ..." and deselected the option to protect my computer and data before clicking OK. I am using wxRuby for the windowing interface and am wondering if that is not working within an OCRA created executable. Any thoughts would be appreciated.
Ross
rossgoodell@hotmail.com
@Ross:
I saved the following code...
http://pastie.org/487330
...as "wxtest.rbw".
I then opened a console window, navigated to the directory containing the above script, and executed the command:
ocra.rb wxtest.rbw
OCRA compiled the code into "wxtest.exe", which runs as it should, either from the command line or by double-clicking the file icon.
This is on Vista.
Hope that helps. Feel free to send me your code.
David
Thanks, BackOrder!
Your suggestion worked like a charm for me, and I mentioned it in my latest post here.
David
Thanks to David's help I discovered that my program works okay with the latest version of ocra (ocrasa.rb) after I installed the latest version of wxRuby (2.0.0), which also brought in Ruby 1.9.1.
Ross Goodell
rossgoodell@hotmail.com
I have used David's code:
http://pastie.org/487330
and the latest version of wxruby.
Having thread error:
C:/DOCUME~1/compile/LOCALS~1/Temp/seb1F.tmp/lib/ruby/site_ruby/1.8/rubygems.rb:2
11:in `synchronize': stopping only thread (ThreadError)
Install the latest rubygems version to avoid Thread error
Post a Comment