From: Kevin Smith Date: 2000-12-27T11:49:10+09:00 Subject: [ruby-talk:8099] Converting a Ruby app into an executable Well, today was an interesting day. I had some ideas about how to create a standalone executable out of a Ruby program. I almost made it, but hit a brick wall. I'll share, in case this sparks any ideas for other folks. The app is named "rex", for Ruby-EXecutable. My plan was: 1. Create a rexmake.rb utility to convert a collection of .rb files into one big .rex file: a. Start with the "main" .rb file b. Replace each require of another .rb file with the .rb file itself c. Remember all requires, and strip subsequent requires of the same file d. Now I have a HUGE .rex file that contains all the .rb code for the app e. Display the list of .so (or .dll) files that are still required 2. Create a rex.c app: a. Embed the Ruby interpreter b. Look at the end of the executable itself to find the HUGE source file c. Write that source to a tempfile d. Invoke the interpreter pointing to the tempfile 3. Glue it together: a. Append a .rex file to a copy of the rex app b. Include necessary signatures for error- checking I completed steps 1 and 2, and have been doing step 3 manually. For a simple app, it works great. You end up with a single executable that contains the interpreter and all the required Ruby code. You still need the shared libraries (if any) to be available at run-time. Is this worth packaging up and putting in the RAA? But for complex apps (like mine) there are a few problems: 1. Tests for (__FILE__ == $0) are true, so debugging code wants to execute. I worked around this in my tests by manually deleting the two places it was happening. I can't think of an automated solution, but it would probably be an acceptable documented limitation. 2. $LOAD_PATH is not set in the embedded interpreter environment. I worked around this by appending the necessary search paths at run-time. This could be automated. 3. When I require 'gtk', I get a runtime error that rb_eRuntimeError is undefined. It would appear that still more of the normal Ruby runtime environment is missing from the embedded interpreter. I haven't looked to see if there's an easy solution to this. By the way, I can run my HUGE .rex file through the normal Ruby interpreter, and it works just fine. It's about 8000 lines and 160k. Thoughts? Kevin