How can I compile a standalone Ruby script into a standalone AOT macro executable?

How can I compile a standalone Ruby script into a standalone executable with AOT macro compilation?

I would like to write a command line tool in MacRuby that can be distributed.

+4
source share
2 answers

macrubyc is your friend. An example of a simple greeting 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 you need to keep in mind, the most important thing is that a binary macro requires an associated macro-level environment. On your computer, you can simply run the β€œhi” program, as I said above, but when you send it to macs without installing macruby, you will have to statically compile it into an executable file.

See the macrubyc man page for more information.

+2
source

The traditional way is to provide your command line utility as an uncompressed ruby ​​script. If you prefix it with

 #!/usr/bin/env macruby 

and install the executable with

 $ chmod a+x myfile.rb 

then from the point of view of the user, it just starts as if it were binary.

If you want to deliver it as a binary file, this question is asked here.

+1
source

All Articles