將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等。
麻省理工學院