Packing your Ruby application into a single executable.
MIT License
Packing your Ruby application into a single executable.
It takes less than 5 minutes to compile any project with Ruby Packer.
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!
require
and load
, including dynamic ones (e.g. load(my_path + '/x.rb')
)Here is the latest stable Ruby Packer release:
Whenever the master
branch CI succeeded, a Ruby Packer pre-release binary would be automatically generated. Here is the latest unstable pre-release build:
First install the prerequisites:
choco install squashfs
.nasm
works from your command line.Then download rubyc.exe
from either Unstable Pre-release or Stable Releases.
Optionally, put it under C:\Windows
or any other PATH
directories.
Open Visual Studio's "x64 Native Tools Command Prompt" and execute rubyc --help
therein.
First install the prerequisites:
brew install squashfs
Command Line Tools
via Xcode. You can findXcode -> Preferences -> Downloads
gcc
and the related toolchain containing make
Then download rubyc
from either Unstable Pre-release or Stable Releases.
Run chmod +x
to give it execution permissions and execute ./rubyc --help
.
First install the prerequisites:
sudo yum install squashfs-tools
sudo apt install squashfs-tools
gcc
or clang
Then download rubyc
from either Unstable Pre-release or Stable Releases.
Run chmod +x
to give it execution permissions and execute ./rubyc --help
.
rubyc [OPTION]... [ENTRANCE_FILE]
ENTRANCE_FILE refers to the path of an executable ruby script from your project, e.g. "bin/rails".
If ENTRANCE_FILE was not provided, a single raw Ruby interpreter executable would be produced.
-r, --root=DIR The path to the root of your application
-o, --output=FILE The path of the output file
-d, --tmpdir=DIR The directory for temporary files
--keep-tmpdir Keeps all temporary files that were generated last time
--openssl-dir The path to openssl
--make-args=ARGS Extra arguments to be passed to make
--nmake-args=ARGS Extra arguments to be passed to nmake
-i, --ignore-file=STRING Ignore file(s) from build
--debug Enable debug mode
--quiet Enable quiet mode
-v, --version Prints the version of rubyc and exit
-V, --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
--openssl-dir
Optionrubyc compiles its own version of openssl without any certifications. To be able to use ssl with rubyc it should know where to find the certifications.
By default this path is set to /usr/local/etc/openssl/
but can be overridden using the --openssl-dir
argument.
Keep in mind that users running your compiled package should have their certifications present in this directory as well.
--ignore-file
OptionIf you don't want certain files included in the build you can ignore them from the command line using -i.
rubyc -i ignore.file -i ignore-2.file -i "ignore*"
Alternatively you can create a .rubycignore
file in the root of your project to specify which files should be ignored.
I.e. packing the raw Ruby interpreter without packing any projects:
rubyc
./a.out (or a.exe on Windows)
Taking Ruby Packer itself as an example of the CLI utility to pack:
git clone --depth 1 https://github.com/pmq20/ruby-packer
cd ruby-packer
rubyc bin/rubyc
./a.out (or a.exe on Windows)
rails new yours
cd yours
rubyc bin/rails
./a.out server (or a.exe server on Windows)
rubyc
from SourceTo build rubyc
you must have a C compiler and the necessary toolchain to
build ruby and the libraries stuffed inside rubyc which include at least:
If you are unsure if your toolchain is complete then trying to build rubyc
will let you know you are missing something. Unfortunately it may tell you
with some unfamiliar message. Please file an issue here if this occurs.
Once your toolchain is set up run bundle
. To compile your own rubyc
run:
bundle exec rake rubyc
Or (if you want to compile with debug symbols):
ENCLOSE_IO_RUBYC_ADDTIONAL_ARGS=--debug bundle exec rake rubyc
This will produce a single rubyc
executable, which can
be put inside any of your PATH
locations, so that it can be directly
called from the command prompt. For example:
mv rubyc /usr/local/bin
Remember that rubyc includes all the files from the current directory in the built executable. You must delete the prior rubyc or your squashfs will continually grow larger and the embedded squashfs compile time will be very, very long.