将Ruby应用程序打包到一个可执行文件中。
用Ruby Packer编译任何项目不到5分钟。
无论您如何开发它,只要它在Plain Ruby中起作用,就无需在应用程序中修改一行代码!
视窗,
macos和
Linuxrequire和load ,包括动态的(例如load(my_path + '/x.rb') )这是最新稳定的红宝石包装工:
| 操作系统 | 拱。 | 可执行 |
|---|---|---|
| 视窗 | x64 | https://gw.alipayobjects.com/os/rmsportal/wxwlpruttreynvvxjmtr.zip |
| macos | x64 | https://gw.alipayobjects.com/os/enclose-prod/b812fa0f-d52b-44f1-8233-65ab87070707cf1f/rubyc-v0.4.4.0-darwin-x64.gz |
| Linux | x64 | https://gw.alipayobjects.com/os/enclose-prod/1fd23e6b-d48f-4ed0-94dddd-f0f539960253/rubyc-v0.4.0-linux-x64.gz |
每当master Branch CI成功时,都会自动生成Ruby Packer预释放二进制文件。这是最新不稳定的预发行构建:
| 操作系统 | 拱。 | 可执行 |
|---|---|---|
| 视窗 | x64 | https://github.com/pmq20/ruby-packer/releases/download/windows-x64/rubyc.exe |
| macos | x64 | https://github.com/pmq20/ruby-packer/releases/download/darwin-x64/rubyc |
| Linux | x64 | https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc |
在Windows上安装首先安装先决条件:
choco install squashfs 。nasm 。然后从不稳定的预发行或稳定版本中下载rubyc.exe 。可选地将其放在C:Windows或任何其他PATH目录下。打开Visual Studio的“ X64本机工具命令提示符”并执行rubyc --help 。
在MacOS上安装首先安装先决条件:
brew install squashfsCommand Line Tools 。您可以在菜单Xcode -> Preferences -> Downloads下找到它gcc和相关工具链,其中包含make然后从不稳定的预发行或稳定版本中下载rubyc 。运行chmod +x以赋予其执行权限并执行./rubyc --help 。
在Linux上安装首先安装先决条件:
sudo yum install squashfs-toolssudo apt install squashfs-toolsgcc或clang然后从不稳定的预发行或稳定版本中下载rubyc 。运行chmod +x以赋予其执行权限并执行./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选项Rubyc编译了自己的版本的OpenSSL,没有任何认证。为了能够将SSL与Rubyc一起使用,应该知道可以在哪里找到认证。
默认情况下,此路径设置为/usr/local/etc/openssl/ ,但可以使用--openssl-dir参数覆盖。
请记住,运行您的编译软件包的用户也应在此目录中存在其认证。
--ignore-file选项如果您不希望构建中包含某些文件,则可以使用-i从命令行中忽略它们。
rubyc -i ignore.file -i ignore-2.file -i "ignore*"
另外,您可以在项目的根部创建一个.rubycignore文件,以指定应忽略哪些文件。
IE打包了RAW RUBY解释器,而无需打包任何项目:
rubyc
./a.out (or a.exe on Windows)
以Ruby Packer本身为例,可以包装CLI实用程序:
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要构建rubyc您必须有一个C编译器和必要的工具链来构建Ruby和塞满Rubyc的库,其中至少包括:
如果您不确定工具链是否完成,那么尝试构建rubyc会让您知道您缺少一些东西。不幸的是,它可能会以一些陌生的信息告诉您。如果发生这种情况,请在此处提出问题。
设置工具链后,运行bundle 。编译自己的rubyc运行:
bundle exec rake rubyc
或(如果要使用调试符号进行编译):
ENCLOSE_IO_RUBYC_ADDTIONAL_ARGS=--debug bundle exec rake rubyc
这将产生单个rubyc可执行文件,可以将其放置在您的任何PATH位置中,以便可以从命令提示符直接调用。例如:
mv rubyc /usr/local/bin
请记住,Rubyc在构建的可执行文件中包含来自当前目录的所有文件。您必须删除先前的Rubyc ,否则您的南瓜将不断增长,并且嵌入式壁球的编译时间将非常非常长。
Minqi Pan等。
麻省理工学院