Packing your Ruby application into a single executable. http://enclose.io

1. Ruby Packer

Packing your Ruby application into a single executable.

1.1 Features

  • Works on Linux, Mac and Windows
  • Creates a binary distribution of your application
  • Supports natively any form of require and load, including dynamic ones (e.g. load(my_path + ‘x.rb’)
  • Features zero-config auto-update capabilities to make your compiled project to stay updated
  • Native C extensions are fully supported
  • Rails applications are fully supported
  • Open Source, MIT Licensed

1.2 Get Started

It takes less than 5 minutes to compile any project with Ruby Compiler.

You won’t need to modify a single line of code in your application, no matter how you developed it as long as it works in plain Ruby!

Architecture Latest Stable
macOS x86-64 http://enclose.io/rubyc/rubyc-darwin-x64.gz
Linux x86-64 http://enclose.io/rubyc/rubyc-linux-x64.gz
Windows x86-64 http://enclose.io/rubyc/rubyc-x64.zip
For previous releases, cf. http://enclose.io/rubyc

1.3 Install on macOS

1.3.1 First install the prerequisites:

  • SquashFS Tools 4.3:
brew install squashfs
  • Xcode

You also need to install the Command Line Tools via Xcode. You can find this under the menu Xcode -> Preferences -> Downloads
This step will install gcc and the related toolchain containing make

  • Ruby

Then,

curl -L http://enclose.io/rubyc/rubyc-darwin-x64.gz | gunzip > rubyc
chmod +x rubyc
./rubyc --help

1.4 Usage

If ENTRANCE was not provided, then a single Ruby interpreter executable will be produced. ENTRANCE can be either a file path, or a “x” string as in bundle exec “x”.

rubyc [OPTION]... [ENTRANCE]
  -r, --root=DIR                   The path to the root of the application
  -o, --output=FILE                The path of the output file
  -d, --tmpdir=DIR                 The directory for temporary files
  -c, --clean-tmpdir               Cleans temporary files before compiling
      --keep-tmpdir                Keeps all temporary files that were generated last time
      --make-args=ARGS             Extra arguments to be passed to make
      --nmake-args=ARGS            Extra arguments to be passed to nmake
      --auto-update-url=URL        Enables auto-update and specifies the URL to get the latest version
      --auto-update-base=STRING    Enables auto-update and specifies the base version string
      --debug                      Enable debug mode
  -v, --version                    Prints the version of rubyc and exit
      --ruby-version               Prints the version of the Ruby runtime and exit
      --ruby-api-version           Prints the version of the Ruby API and exit
  -h, --help                       Prints this help and exit

Examples

Producing a single Ruby interpreter executable

rubyc
./a.out (or a.exe on Windows)

Compiling a CLI tool

git clone --depth 1 https://github.com/pmq20/ruby-compiler
cd ruby-compiler
rubyc bin/rubyc
./a.out (or a.exe on Windows)

Compiling a Rails application

rails new yours
cd yours
rubyc bin/rails
./a.out server (or a.exe server on Windows)

Compiling a Gem

rubyc --gem=bundler --gem-version=1.15.4 bundle
./a.out (or a.exe on Windows)

Reference

pmq20/ruby-packer: Packing your Ruby application into a single executable.
https://github.com/pmq20/ruby-packer

将您的 Ruby 应用编译成单个可执行文件 · Ruby China
https://ruby-china.org/topics/34684

RubyConf 2017: Packing your Ruby application into a single executable // Speaker Deck
https://speakerdeck.com/pmq20/rubyconf-2017-packing-your-ruby-application-into-a-single-executable

Ruby Packer – Enclose.IO
http://enclose.io/rubyc

打赏

Leave a Reply

Your email address will not be published. Required fields are marked *