Skip to content

Packing your Ruby application into a single executable.

License

Notifications You must be signed in to change notification settings

metanorma/ruby-packer

 
 

Repository files navigation

Ruby Compiler

Ahead-of-time (AOT) Compiler designed for Ruby, that just works.

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')
  • Native C extensions are fully supported
  • Rails applications are fully supported
  • Open Source, MIT Licensed

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!

Install on macOS

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 https://github.com/metanorma/ruby-packer/releases/download/v0.6.0/rubyc-darwin-x64 > rubyc
chmod +x rubyc
./rubyc --help

Install on Linux

First install the prerequisites:

  • SquashFS Tools 4.3
    • sudo yum install squashfs-tools
    • sudo apt-get install squashfs-tools
  • gcc or clang
  • GNU Make
  • Ruby

Then,

curl -L https://github.com/metanorma/ruby-packer/releases/download/v0.6.0/rubyc-linux-x64 > rubyc
chmod +x rubyc
./rubyc --help

Install on Windows

First install the prerequisites:

Then download rubyc-x64.zip, and this zip file contains only one executable. Unzip it. Optionally, rename it to rubyc.exe and put it under C:\Windows (or any other directory that is part of PATH). Execute rubyc --help from the command line.

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
      --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)

Bootstrapping Ruby Compiler itself

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 CLI tool

git clone --depth 1 https://github.com/pmq20/node-compiler
cd node-compiler
rubyc bin/nodec
./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 bundle
./a.out (or a.exe on Windows)

How to make a patch of Ruby source

curl -sSL --create-dirs -o .archives/ruby-2.6.3.tar.gz https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.gz
tar xzf .archives/ruby-2.6.3.tar.gz && mv ruby-2.6.3 ruby && git add -f ruby && git commit -m 'Ruby' && git am .patches/ruby/*
# make changes
git add -f ruby
git commit -m 'new changes'
git rebase -i master
# reorder and squash commits as you would like
# 8 is number of commits to extract as patches
git format-patch -8 -o .patches/ruby
git add .patches/ruby
git commit -m 'new changes'
git rebase -i master
# remove all commits except the last one (start from "Ruby" up to the commit with the patch changes)
# it's done

See Also

  • Libsquash: portable, user-land SquashFS that can be easily linked and embedded within your application.

About

Packing your Ruby application into a single executable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 89.6%
  • Makefile 10.4%