The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Churning Ruby into EXE

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Churning Ruby into EXE Posted: Sep 12, 2005 11:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Churning Ruby into EXE
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

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

Stolen from weft-qda. RubyScript2Exe is here.

Read: Churning Ruby into EXE

Topic: Katrina Hurricane Relief with Rails Previous Topic   Next Topic Topic: Star Wars Fantasies

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use