[ANN] RubyScript2Exe 0.2.0

I just want to say that RubyScript2Exe 0.2.0 [1] has been
released. Both Windows and Linux are supported.

gegroet,
Erik V.

[1] http://www.erikveen.dds.nl/rubyscript2exe/index.html

···

----------------------------------------------------------------

RubyScript2Exe transforms your Ruby script into a standalone
Windows or Linux executable. You can look at it as a
"compiler". Not in the sense of a source-code-to-byte-code
compiler, but as a "collector", for it collects all necessary
files to run your script on an other machine: the Ruby script,
the Ruby interpreter and the Ruby runtime library (stripped
down for this script). Anyway, the result is the same: a
standalone exe-file (Windows) or bin-file (Linux). And that's
what we want!

Because of the gathering of files from your own Ruby
installation, RubyScript2Exe creates an executable for the
platform it's being run on. No cross compile.

And when I say Windows, I mean both Windows (RubyInstaller,
MinGW and MSWin32) and Cygwin. But the generated exe under
Cygwin is very, very big, because its exe's are very big
(static?) and it includes cygwin1.dll, so it can run on
machines without Cygwin.

----------------------------------------------------------------

Erik Veenstra wrote:

I just want to say that RubyScript2Exe 0.2.0 [1] has been released. Both Windows and Linux are supported.

Is a change list available somewhere? I couldn't find one on the homepage.

Also while I'm writing to you, would it be possible to allow custom ..DLLs and resources to be added? I have an application that uses a C++ extension which loads more .DLLs -- RubyScript2Exe does not automatically include those and I can't find a way of manually including them that works. (I can unpack and repackage, but then the .DLLs will still not get loaded from the temporary directory.)

Being able to easily include own media would also be very nifty in my use case. (I'm writing games with Ruby -- it's always nice to have a single EXE distribution that contains all the game media.)

Thank you for a great library!

"Erik Veenstra" <pan@erikveen.dds.nl> wrote in message

I just want to say that RubyScript2Exe 0.2.0 [1] has been
released. Both Windows and Linux are supported.

Will this support all manner of 'require'd files, including those loaded by
the gems require-hack?

Thanks!

Erik Veenstra wrote:

> I just want to say that RubyScript2Exe 0.2.0 [1] has been
> released. Both Windows and Linux are supported.

Is a change list available somewhere? I couldn't find one on
the homepage.

It's there, really... The Download section [1] has a link to
both [2] and [3]. I think you are interested in [2].

Also while I'm writing to you, would it be possible to allow
custom .DLLs and resources to be added? I have an application
that uses a C++ extension which loads more .DLLs --
RubyScript2Exe does not automatically include those and I
can't find a way of manually including them that works. (I
can unpack and repackage, but then the .DLLs will still not
get loaded from the temporary directory.)

There's a link to Tar2RubyScript [4] on the page as well.
Tar2RubyScript generates a standalone Ruby script from an
existing directory, which contains a complete Ruby application
(scripts, DLL's and resources). This standalone Ruby script can
be converted to an executable with RubyScript2Exe.

That's how I distribute all my applications, complete with
resources, help files, licenses, readme, images, default
configurations, everything. Even including the graphical front
end (WXRuby or RubyWebDialogs [5]). And it just works...

Being able to easily include own media would also be very
nifty in my use case. (I'm writing games with Ruby -- it's
always nice to have a single EXE distribution that contains
all the game media.)

Thank you for a great library!

[1] http://www.erikveen.dds.nl/rubyscript2exe/index.html#6..Download
[2] http://www.erikveen.dds.nl/rubyscript2exe/download.html
[3] http://www.erikveen.dds.nl/rubyscript2exe/history.txt.html
[4] Tar2RubyScript - A Tool for Distributing Ruby Applications
[5] http://www.erikveen.dds.nl/rubywebdialogs/index.html

···

On Wed, 08 Dec 2004 15:16:02 +0100, Florian Gross wrote:

"Erik Veenstra" <pan@erikveen.dds.nl> wrote in message

> I just want to say that RubyScript2Exe 0.2.0 [1] has been
> released. Both Windows and Linux are supported.

Will this support all manner of 'require'd files, including
those loaded by the gems require-hack?

Never worked with gems before...

I did a test (on Linux) with the progressbar example. Yes,
RubyScript2Exe detects progressbar.rb [1] and yes, it is
included in the executable [2]. But when the executable is run,
require_gem only searches for progressbar.rb in its own dirs,
not in the regular places. Resulting in an Gem::LoadError. If I
catch this exception, it does work. See below.

I'll have a look at it.

Thanks.

gegroet,
Erik V.

[1] /usr/local/lib/ruby/gems/1.8/gems/progressbar-0.0.3/lib/progressbar.rb
[2] ./lib/progressbar.rb

···

----------------------------------------------------------------

Development machine:

[erik@devel]$ ruby rubyscript2exe.rb testgem.rb
Tracing testgem...
Gathering files...% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00
Copying files...
Copying /lib/ld-linux.so.2 ...
Copying /usr/local/bin/ruby ...
Copying /scratch/testgem.rb ...
Creating testgem.bin ...

Test machine:

[erik@test1]$ ./testgem.bin
Example progr: 100% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00

----------------------------------------------------------------

# Doesn't work.

require 'rubygems'
require_gem 'progressbar'

----------------------------------------------------------------

# Does work.

require 'rubygems'
begin
   require_gem 'progressbar'
rescue Gem::LoadError
   require 'progressbar'
end

----------------------------------------------------------------

This sounds cool. Anyone know what it would take to have this for OS X?
It would be cool to be able to use RubyCocoa or TKRuby or QTRuby and
then
make it into an executable easily.

Florian Gross wrote:

Erik Veenstra wrote:

> I just want to say that RubyScript2Exe 0.2.0 [1] has been
> released. Both Windows and Linux are supported.

Is a change list available somewhere? I couldn't find one on the

homepage.

Also while I'm writing to you, would it be possible to allow custom
.DLLs and resources to be added? I have an application that uses a

C++

extension which loads more .DLLs -- RubyScript2Exe does not
automatically include those and I can't find a way of manually

including

···

them that works. (I can unpack and repackage, but then the .DLLs will

still not get loaded from the temporary directory.)

Being able to easily include own media would also be very nifty in my

use case. (I'm writing games with Ruby -- it's always nice to have a
single EXE distribution that contains all the game media.)

Thank you for a great library!

Try:

  require 'rubygems'
  require 'progressbar'

Cheers,
Gavin

···

On Thursday, December 9, 2004, 2:47:29 AM, Erik wrote:

Will this support all manner of 'require'd files, including
those loaded by the gems require-hack?

[......]

----------------------------------------------------------------

# Doesn't work.

require 'rubygems'
require_gem 'progressbar'

----------------------------------------------------------------

# Does work.

require 'rubygems'
begin
   require_gem 'progressbar'
rescue Gem::LoadError
   require 'progressbar'
end

----------------------------------------------------------------

Erik Veenstra said:

I did a test (on Linux) with the progressbar example. Yes,
RubyScript2Exe detects progressbar.rb [1] and yes, it is
included in the executable [2]. But when the executable is run,
require_gem only searches for progressbar.rb in its own dirs,
not in the regular places. Resulting in an Gem::LoadError.

require_gem does not search for progressbar.rb. It searches for the
progressbar *gem* (progressbar.rb gets required as a side effect if the
gem specifies an autorequire file). Since you are not replicating the
gems metadata structure in your packaged app, its not surprizing that it
is not found.

There are a couple of ways of attacking this. You /could/ replicate the
gem metadata (not really recommended). Perhaps supplying a custom
require_gem that works in your packaged app. I think the only thing the
custom require_gem would need to do is do a require on that gems
autorequire file (if any).

Contact me (or another gem developer) if you need help pursuing this. We
would be glad to help.

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Erik Veenstra wrote:

Is a change list available somewhere? I couldn't find one on
the homepage.

It's there, really... The Download section [1] has a link to
both [2] and [3]. I think you are interested in [2].

Thanks, while this is not exactly what I was looking for it is still similar enough to be of help.

Also while I'm writing to you, would it be possible to allow
custom .DLLs and resources to be added? I have an application
that uses a C++ extension which loads more .DLLs --
RubyScript2Exe does not automatically include those and I
can't find a way of manually including them that works. (I
can unpack and repackage, but then the .DLLs will still not
get loaded from the temporary directory.)

There's a link to Tar2RubyScript [4] on the page as well.
Tar2RubyScript generates a standalone Ruby script from an
existing directory, which contains a complete Ruby application
(scripts, DLL's and resources). This standalone Ruby script can
be converted to an executable with RubyScript2Exe.

But will the .DLLs really be found when I use Tar2RubyScript? I think I tried this without success.

Florian Gross wrote: Erik Veenstra wrote:

> > I just want to say that RubyScript2Exe 0.2.0 [1] has been
> > released. Both Windows and Linux are supported.
>
> Thank you for a great library!

This sounds cool. Anyone know what it would take to have this
for OS X?

You need "FreePascal on the Macintosh" [1] and a machine with
OS X. Since I'm the only developer of RubyScript2Exe and not
possessing such a machine, it will probably never happen.
Unless somebody is able and willing to do the porting... Or
provides a SSH connection... I don't think it's to hard to do.

It would be cool to be able to use RubyCocoa or TKRuby or
QTRuby and then make it into an executable easily.

The bindings for QT and TK are detected and included in the
executable. QT and TK themselfs are not detected, because they
have nothing to do with Ruby. They have to be installed
manually.

gegroet,
Erik V.

[1] Free Pascal - Free Pascal on the Macintosh

···

On Fri, 10 Dec 2004 15:19:04 -0800, steven_todd_harri wrote:

"Gavin Sinclair" <gsinclair@soyabean.com.au> wrote in message

Try:

  require 'rubygems'
  require 'progressbar'

Will this allow nested (gem and non-gem) requires within 'progressbar' to
work?

Is the "ruby -r ubygems myfile.rb" and then just plain "require progressbar"
no longer recommended? Or the environment variable GEM_PATH (on WinXP) ?

I am trying to settle on one standard way to use my gems transparently i.e.
without something like 'require_gem' (or was that 'gem_require'?). While
GEM_PATH seems to work, it appears to cause problems with other apps or libs
that assume Rubys standard directory layout.

Advice?

> > Will this support all manner of 'require'd files,
> > including those loaded by the gems require-hack?
>
> [......]

Try:

require 'rubygems'

require 'progressbar'

$ grep * -wie def | grep -wie require
loadpath_manager.rb: def require(file)

Looks like RubyGems does an overwrite of Kernel.require:

module Kernel
   alias require__ require
   def require(file)
     Gem::LoadPathManager.search_loadpath(file) || Gem::LoadPathManager.search_gempath(file)
     require__(file)
   end
end

That will do the trick in our application. But what happens
when a library does a require_gem? Time for the next test. I
don't know Rails, but I think it has some dependencies. Just
giving it a shot...

Test 1:

$ cat test1.rb
require "rubygems"
require_gem "rails"

$ ruby test1.rb

Looks good. It's useless, but the dependencies are fullfilled.

Test 2:

$ cat test2.rb
require "rubygems"
require "rails"

$ ruby test2.rb
/usr/local/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require__': No such file to load -- rails (LoadError)
         from /usr/local/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require'
         from test2.rb:2

Oops! I think it hasn't anything to do with dependencies. The
trick doesn't work.

Any RubyGem hacker, out there?

gegroet,
Erik V.

"Jim Weirich" <jim@weirichhouse.org> wrote in message

Contact me (or another gem developer) if you need help pursuing this. We
would be glad to help.

Do you think tt may be good to have a gem-recommended way of dealing with
this more broadly? With gems gaining wider use this could be useful for any
app (rubscript, an IDE, etc.) that needs to know about ruby's directory
structure, and hence about gems.

> > Also while I'm writing to you, would it be possible to
> > allow custom .DLLs and resources to be added? I have an
> > application that uses a C++ extension which loads more
> > .DLLs -- RubyScript2Exe does not automatically include
> > those and I can't find a way of manually including them
> > that works. (I can unpack and repackage, but then the
> > .DLLs will still not get loaded from the temporary
> > directory.)
>
> There's a link to Tar2RubyScript [4] on the page as well.
> Tar2RubyScript generates a standalone Ruby script from an
> existing directory, which contains a complete Ruby
> application (scripts, DLL's and resources). This standalone
> Ruby script can be converted to an executable with
> RubyScript2Exe.

But will the .DLLs really be found when I use Tar2RubyScript?
I think I tried this without success.

I did it once. It was something like this:

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Newlocation the is path to "the internals of the package". (Of
course, it's a temp dir...)

But that only works when you directly access the DLL.
Otherwise, when you access the DLL indirectly, you have to
change the environment before starting the child process. Could
be done with:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
system("command")

You might have to combine them:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Not tested. Just an idea.

gegroet,
Erik V.

> I did a test (on Linux) with the progressbar example. Yes,
> RubyScript2Exe detects progressbar.rb [1] and yes, it is
> included in the executable [2]. But when the executable is
> run, require_gem only searches for progressbar.rb in its
> own dirs, not in the regular places. Resulting in an
> Gem::LoadError.

There are a couple of ways of attacking this. You /could/
replicate the gem metadata (not really recommended). Perhaps
supplying a custom require_gem that works in your packaged
app. I think the only thing the custom require_gem would need
to do is do a require on that gems autorequire file (if any).

RubyScript2Exe executes the application, in order to trace it,
with (simplified):

$ ruby -r require2lib app.rb

This require2lib sets an at_exit block. In this block, all
required and loaded files are copied to ./lib . This ./lib is
packed into the executable and recreated on the destination
machine just before doing something like:

$ ruby -I ./lib app.rb

That's part of the job RubyScript2Exe does to satisfy the
requirements (besides ruby.exe and ruby.dll and a bunch of
recursively determined dll's en so's).

This copying works for files required via require_gem as well,
because the old require is still done by require_gem, so they
show up in $". Checked that. It works. It's just that
rubygems.rb doesn't work properly on the targeted machine,
because it expects its own environment, which is not recreated.
My plan was to overwrite this rubygems.rb which a version of my
own, only implementing require_gem. I came up with the code
below.

Any RubyGems hackers willing to have a look at it? Just
shoot...

Thanks in advance.

gegroet,
Erik V.

···

----------------------------------------------------------------

at_exit do

     # Copy the required files to ./lib .

   $".each do |req|
     ...
   end

     # Overwrite rubygems.rb with my own version of require_gem.

   autorequire = {}

   Gem::Specification.list.each do |gem|
     unless gem.autorequire.nil?
       unless $".collect{|s| (s =~ /^#{gem.autorequire}\.\w+$/)}.compact.empty?
         autorequire[gem.name] = gem.autorequire
       end
     end
   end

   File.open("./lib/rubygems.rb", "w") do |f|
     f.puts "module Kernel"
     f.puts " def require_gem(file, version=nil)"
     f.puts " autorequire = %s" % autorequire.inspect
     f.puts " file = autorequire[file]"
     f.puts " require(file) unless file.nil?"
     f.puts " end"
     f.puts "end"
   end
end

----------------------------------------------------------------

Contact me (or another gem developer) if you need help
pursuing this. We would be glad to help.

(I tried, no response...)

"Gavin Sinclair" <gsinclair@soyabean.com.au> wrote in message
> Try:
>
> require 'rubygems'
> require 'progressbar'

Will this allow nested (gem and non-gem) requires within 'progressbar' to
work?

require 'foo' will always load the version from RubyGems, if you're
referring to that. Once you require 'rubygems', it overrides
Kernel.require and it is no longer possible to load the files in the
standard library dir, unless you use the GEM_SKIP env. variable.

Is the "ruby -r ubygems myfile.rb" and then just plain "require progressbar"
no longer recommended? Or the environment variable GEM_PATH (on WinXP) ?

ruby -rubygems foo is equivalent to doing a require 'rubygems'...

···

On Thu, Dec 09, 2004 at 01:22:30AM +0900, itsme213 wrote:

--
Hassle-free packages for Ruby?
RPA is available from http://www.rubyarchive.org/

itsme213 said:

I am trying to settle on one standard way to use my gems transparently
i.e.
without something like 'require_gem' (or was that 'gem_require'?). While
GEM_PATH seems to work, it appears to cause problems with other apps or
libs that assume Rubys standard directory layout.

Advice?

If you don't care what version you get, just do a normal require. In
addition, you need to make sure the rubygems library is loaded. You can
do this by:

* explicitly requiring 'rubygems' before requiring any file
  that would be in a gem.[1]
* explicitly starting ruby with a -rubygems command line option.
* Setting the RUBYOPT environment variable to 'rubygems'

If you /do/ care about which the version of a gem you are using, then use
a require_gem command with explicit versioning requirements. Again, make
sure the rubygems library is loaded using one of the above three
techniques.

Regarding your GEM_PATH comment, I'm not sure what you are getting at.
GEM_PATH is for specifying where multiple gem repositories are locally
stored. Were you refering to RUBYOPT?

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

[1] If you do choose to explicitly include rubygems, but don't
    want to depend on rubygems always being available, do this:

      begin
        require 'rubygems'
      rescue LoadError
      end

itsme213 said:

Do you think tt may be good to have a gem-recommended way of dealing with
this more broadly? With gems gaining wider use this could be useful for
any
app (rubscript, an IDE, etc.) that needs to know about ruby's directory
structure, and hence about gems.

Coincidently, on the rubygems-dev mailing list we just had a discussion on
the value of identifying an "API" for gems that identifies some kind of
programatic interface for doing gem related things. These kinds of
operations certainly fall into that category.

Thanks for the feedback. We certainly want to head in that direction.

···

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Long lines... Sorry.

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +
ENV["PATH"] system("command")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +
               ";" +
               ENV["PATH"]

system("command")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +
ENV["PATH"] api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P
P), "V")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +
               ";" +
               ENV["PATH"]

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Erik Veenstra wrote:

custom DLLs

Tar2RubyScript

But will the .DLLs really be found when I use Tar2RubyScript?
I think I tried this without success.

I did it once. It was something like this:

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

[...]

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
system("command")

Not doing either of those though. I'm just require()ing a Ruby library (C++ extension) that is dynamically linked against a few DLLs. One of those is fmod.dll, but there's also msvcp71.dll and msvcr71.dll and a custom one involved. I know that RubyScript2Exe is already able to bundle the DLLs that Ruby uses so an option for adding the specified DLLs in a similar way would be just what I need. I'm not sure if this involves doing a Win32-API call to tell Ruby to also look for DLLs at the location the executable was unpacked to. Does this sound possible?

Thanks a lot for helping out with this.