4

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.

dan
  • 43,914
  • 47
  • 153
  • 254

2 Answers2

2

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.

Chris Mowforth
  • 6,689
  • 2
  • 26
  • 36
1

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.

Community
  • 1
  • 1
nes1983
  • 15,209
  • 4
  • 44
  • 64