我创建了一个简单的红宝石脚本
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
此脚本创建一个带有按钮的非常简单的 GUI。如果我使用 ocra gem 创建脚本.exe则使用命令
ocra script.rbw
生成的文件为 70 MB,大小对于带有按钮的简单窗口来说太大了。我做错了什么?我能做些什么来弥补这个障碍?Ocra 输出是这样的(输出使用命令"ocra script.rb"而不是"ocra script.rbw",但过程是相同的)
=== 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)
我用 cli script.rb 尝试相同的过程
puts "Hello World"
结果 : 2,6 Mb 仅用于打印你好世界。我能做什么?
Ocra 不是一个编译器,它是一个随时可以运行的红宝石。它需要红宝石,所有装载的宝石和脚本,并将其打包在一起。
当您调用 exe 时,它会提取所有内容并使用包含的 ruby 调用 ruby 脚本。脚本执行后,它会删除所有内容。如果脚本失败,则不会完成删除,并且您会在临时目录中找到大量文件。
在您使用 require 'gtk3'
的情况下,将加载 gtk3 支持的所有内容。似乎很多。
Hello World 的 2.6MB 不仅包含屏幕输出,还包含 ruby 能够执行的所有内容 - 即使它没有被执行,
你能做什么?尝试找到一个不需要太多的版本。