rubyrubygemsfilesizeocra

gem ocra generates huge files


I created a simple ruby script

require 'gtk3'

def destroy( widget )
   Gtk.main_quit
end

Gtk.init
window = Gtk::Window.new :toplevel
window.set_title( "helloworld.rb" )
window.set_border_width( 10 )

window.signal_connect( "delete_event" ) {
   destroy(nil)
}

button = Gtk::Button.new :label => "Button"
window.add( button )
button.show
window.show
Gtk.main

This script creates a very simple GUI with a button. If I use ocra gem to create script.exe with command

ocra script.rbw

is generated a file of 70 mb, size too large for a simple window with button. What am I doing wrong? What can I do to aggirarare this obstacle? Ocra output is this (output with command "ocra script.rb" and not "ocra script.rbw", but the process is the same)

=== Loading script to check dependencies
=== Attempting to trigger autoload of Gem::ConfigFile
=== Attempting to trigger autoload of Gem::DependencyList
=== Attempting to trigger autoload of Gem::DependencyResolver
=== Attempting to trigger autoload of Gem::Installer
=== Attempting to trigger autoload of Gem::RequestSet
=== Attempting to trigger autoload of Gem::Source
=== Attempting to trigger autoload of Gem::SourceList
=== Attempting to trigger autoload of Gem::SpecFetcher
=== Attempting to trigger autoload of CGI::HtmlExtension
=== Detected gem ocra-1.3.4 (loaded, files)
===     6 files, 191218 bytes
=== Detected gem pkg-config-1.1.6 (loaded, files)
===     3 files, 29263 bytes
=== Detected gem cairo-1.14.1-x64-mingw32 (loaded, files)
===     572 files, 80204194 bytes
=== Detected gem glib2-2.2.4-x64-mingw32 (loaded, files)
===     2115 files, 104593625 bytes
=== Detected gem gobject-introspection-2.2.4-x64-mingw32 (loaded, files)
===     231 files, 13768036 bytes
=== Detected gem gio2-2.2.4-x64-mingw32 (loaded, files)
===     3 files, 49152 bytes
=== Detected gem atk-2.2.4-x64-mingw32 (loaded, files)
===     208 files, 4281497 bytes
=== Detected gem pango-2.2.4-x64-mingw32 (loaded, files)
===     465 files, 95081429 bytes
=== Detected gem gdk_pixbuf2-2.2.4-x64-mingw32 (loaded, files)
===     188 files, 5588250 bytes
=== Detected gem cairo-gobject-2.2.4-x64-mingw32 (loaded, files)
===     5 files, 95261 bytes
=== Detected gem gdk3-2.2.4-x64-mingw32 (loaded, files)
===     3841 files, 114129504 bytes
=== Detected gem gtk3-2.2.4-x64-mingw32 (loaded, files)
===     42 files, 2942499 bytes
=== Detected gem io-console-0.4.2 (loaded, files)
=== WARNING: Gem io-console-0.4.2 root folder was not found, skipping
=== Including 53 encoding support files (3576320 bytes, use --no-enc to exclude)

DL is deprecated, please use Fiddle
=== Building example.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
mingw32/vendor/local/bin/libcairo-2.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/cairo-1.14.1-x64-
......
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk_pixbuf2-2.2.4
-x64-mingw32/vendor/local/bin/libgdk_pixbuf-2.0-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgdk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/gdk3-2.2.4-x64-mi
ngw32/vendor/local/bin/libgtk-3-0.dll
=== Adding detected DLL C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/pango-2.2.4-x64-m
ingw32/vendor/local/lib/pango/1.8.0/modules/pango-basic-win32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/LIBEAY32.dll
=== Adding detected DLL C:/Ruby21-x64/bin/SSLEAY32.dll
=== Adding library files
=== Compressing 519431948 bytes
=== Finished building example.exe (95218080 bytes)

I try the same process with a cli script.rb

puts "Hello World"

Result : 2,6 Mb only to print Hello World. What can i do?


Solution

  • Ocra isn't a compiler, it's kind of a ready-to-run-ruby. It takes ruby, all loaded gems and scripts and pack it together.

    When you call the exe, it extract everything and calls the ruby-script with the included ruby. After the script was executed it deletes everything. If your script fails, the deletion is not done and you find a lot of files in a temporary directory.

    In your case with require 'gtk3' everything that gtk3 supports is loaded. It seems that's a lot.

    The 2.6MB for your Hello World does not contain only the screen output, but everything what ruby is able to do - even it is not executed,

    What you can do? Try to find a version, that don't need so much.