Is it possible to compile a ruby script into an .exe on Windows? I have searched everywhere and I've tried the following (It looked like RubyScript2EXE, Shoes and Crate all seemed dead or abandoned.):
- http://ocra.rubyforge.org/
- http://exerb.sourceforge.jp/index.en.html
I'm using Ruby 1.8.7 on Windows 7 Ultimate (64bit.) from a clean system I do this:
- Install RubyInstaller 1.8.7-p358 from rubyinstaller.org
- gem install watir
- gem install ocra
- git clone git://github.com/snaury/exerb-mingw.git
- cd exerb-mingw
- ruby setup.rb
I have a fairly simple script that does this:
require 'rubygems'
require 'watir'
browser = Watir::Browser.new
browser.goto 'http://slashdot.org'
When I run Ocra I don't get any error messages, and nothing happens:
ocra --output test.exe test.rb
=== Loading script to check dependencies
Exerb seems like a better solution since it compiles to rbc, and it does actually do something:
ruby -r exerb/mkexy test.rb
# Window pops up and after I close it it writes out test.exy
C:\Users\jonathan\dev\Citation>exerb test.exy
C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:146:in `add_file_entry': test.
exy: no such file -- C:/Ruby187/lib/ruby/gems/1.8/gems/win32-api-1.4.8-x86-mingw32/lib/win32/ruby18/win32/api.so (RuntimeError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:86:in `create_archive'
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `each'
from C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb:85:in `create_archive'
from C:/Ruby187/bin/exerb.bat:67:in `main'
from C:/Ruby187/bin/exerb.bat:196
So it can't find win32/api.so. When I look in C:/Ruby187/lib/ruby/site_ruby/1.8/exerb/recipe.rb it looks like gems are not in the search path:
DIR: C:/Users/jonathan/dev/Citation
DIR: C:/Ruby187/lib/ruby/site_ruby/1.8
DIR: C:/Ruby187/lib/ruby/site_ruby/1.8/i386-msvcrt
DIR: C:/Ruby187/lib/ruby/site_ruby
DIR: C:/Ruby187/lib/ruby/vendor_ruby/1.8
DIR: C:/Ruby187/lib/ruby/vendor_ruby/1.8/i386-msvcrt
DIR: C:/Ruby187/lib/ruby/vendor_ruby
DIR: C:/Ruby187/lib/ruby/1.8
DIR: C:/Ruby187/lib/ruby/1.8/i386-mingw32
DIR: .
So after digging around I found out you can add search paths in the exy file like so:
path:
- C:/Ruby187/lib/ruby/gems/
- C:/Ruby187/lib/ruby/gems/1.8
- C:/Ruby187/lib/ruby/gems/1.8/gems
After this it does show these paths in search_path, but it still gives me the same error. Obviously there must be some way to get rubygems paths to be included in the exy?
So, how does someone build a .exe on Windows these days?
I made some progress with Exerb, I found out you can run mkexy with the -rrubygems option to pull this in. And this works GREAT for most ruby projects. I've tried it for a few ruby scripts that use a number of different libraries without problems. For example:
mkexy -rrubygems test.rb
exerb test.exy
test.exe === WORKS!
Unfortunately, it doesn't work for watir. When I run an .exe built with watir I get the following:
s4t-utils/claims.rb:24:in `user_is_bewildered': Error in the default values: :br
owser's value must be one of 'safari', 'firefox', or 'ie', and '' doesn't look r ight. (StandardError)