4 ms·
Does this need ruby on the host? I'm asking because it's really difficult to have a portable ruby binary, only traveling ruby comes to mind
by ksnsnsj 2y ago
Does this need ruby on the host? I'm asking because it's really difficult to have a portable ruby binary, only traveling ruby comes to mind
- Alifatisk 2y agoI’ve gone down this rabbit hole, there are several options to almost achieve portability in Ruby. But making it portable and cross-platform like how Go has a single binary file has not been possible for me. You already mentioned Traveling Ruby, but there are also: OCRA (One-Click Ruby Application) RubyEncoder (commercial) DragonRuby? (It’s a game engine though) Ruby2exe (rb2exe) but I believe it’s dead enclose-io/ruby Ruby-packer portable-ruby project by homebrew RubyMotion (costs probably) Other ideas have been: Using TruffleRuby (GraalVM) and compile using nativeimage If you don’t use any gems, then maybe compile your script with opal.rb to js then bundle that js into single executable Use your script with MRuby and enjoy the benefits of C Run your script with JRuby and bundle the war file with warbler Compile the Ruby script with Crystal (maybe slight modifications has to be done with your code) and use the cross compile with static flag (Btw, running bundle install with the “—standalone” might ease with the bundling and distribution)
- Alifatisk 2y agoQuick update, I tried some of the options I provided, here's the result. OCRA seem to have a tiny issue with some missing files (fiber.so), so there are two forks that works pretty well with Ruby scripts that is also including gems. I tried both of them on a large script and it worked pretty well. The only downside is that it only supports Windows OCRAN (https://rubygems.org/gems/ocran https://rubygems.org/gems/ocran) Aibika (https://rubygems.org/gems/aibika https://rubygems.org/gems/aibika) Ignored RubyEncoder because it's commercial DragonRuby is a whole toolkit, so I am not sure if it offers a quick cli to bundle a ruby script with its gems. I tried rb2exe (https://rubygems.org/gems/rb2exe https://rubygems.org/gems/rb2exe) but it required exactly Ruby version 2.2.2 (docker pull txt3rob/ruby-2.2.2-docker) ruby2exe (https://rubygems.org/gems/ruby2exe https://rubygems.org/gems/ruby2exe) didn't work and looks abandoned enclose-io/ruby (https://github.com/enclose-io/ruby https://github.com/enclose-io/ruby) doesn't offer installation through RubyGems, same with Ruby-packer (https://github.com/pmq20/ruby-packer https://github.com/pmq20/ruby-packer), so not going to try it Portable-ruby (https://github.com/Homebrew/homebrew-portable-ruby https://github.com/Homebrew/homebrew-portable-ruby) is just a project where you download a folder which has portable Ruby in it, nothing else. It does not bundle your script with it RubyMotion costs, so I ignored it Using TruffleRuby had a bit more steps and was complex, so I skipped it MRuby did work, but not with the gems I was using, so I had to rely on their own libraries (https://mruby.org/libraries https://mruby.org/libraries) Crystal did work on simpler scripts but I had to adjust the code a bit to make it valid for the Crystal compiler.
- Alifatisk 2y agoThis talk might interest you https://www.youtube.com/watch?v=DMNDw4fYu60 https://www.youtube.com/watch?v=DMNDw4fYu60