How can I compile a standalone Ruby script into a standalone AOT compiled macruby executable?
I would like to write a command line tool in MacRuby that can be distributed.
macrubyc
is your friend. The simple hello world example, In a terminal:
chris$ echo 'puts("Hello, world!")' > hello.rb
chris$ macrubyc hello.rb -o hi
chris$ ./hi
Hello, world!
chris$ file hi
hi: Mach-O 64-bit executable x86_64
chris$
There are a few things to bear in mind, the most important being that the binary needs a macruby runtime to link against. On your machine you can just run the 'hi' programme as I did above, but when you're shipping it to macs without macruby installed you'll have to statically compile it into the executable.
See the macrubyc manpage for more details.
The traditional way is to deliver your command line utility as an uncompiled ruby script. If you prefix it with
#!/usr/bin/env macruby
and set the file executable with
$ chmod a+x myfile.rb
then from the user's point of view, it just runs, as if it was a binary.
If you do want to deliver it as a binary, that question has been asked here.