Single executable binary of Ruby gem - ruby

What options are available to create a single binary that contains my Ruby gem along with a Ruby runtime?
My goal is to be able to share the executable with another developer and they could simply run the executable from their command line passing it required arguments similar to Vagrant.
P.S. The program is intended to be run in a *nix operating systems with Ruby versions >= 2.5.

There's ruby-packer but the repo has been dead for a while. There are forks with Ruby 2.5. It can produce binaries for Linux, Mac, Windows and probably some others.
For linux based systems you could use AppImage (there are some scripts found on google that put a ruby in the image) or maybe Snapcraft.
When you have ruby-packer and the dependencies installed, it's just a matter of rubyc -o binary-name gem-executable-name in the app's directory. Takes about 15 minutes to compile.

Related

Is it possible to run sdl2-config on Windows?

It seems there are several times when running the sdl2-config script bundled with SDL2 would be useful (such as checking which libraries need to be linked to). But it doesn't seem possible to run this script natively on Windows.
I'm using I've been using mingw for all my C compiling needs so far, if that helps. Is there any way I can run this script on Windows?
Yes, sure!
However, that script is just a Bash script, so you need to install Cygwin which has Bash built in. It is not recommended to use the native (Win10) port of the Bash shell, since it is not behaving as expected.
If you don't already have it installed, then the tricky part is how to install SDL2 using Cygwin. IMHO, that should probably be avoided, as it tend to cause a lot of weird problems (for other packages).
However, there is already a Cygwin package if you want to try it.
apt-cyg install mingw64-x86_64-SDL2 libSDL2-devel libSDL2_2.0_0 # etc

Convention for including executable in gem, both Unix and Windows

I am writing a gem intended to be used on both Unix-type platforms and Windows and that includes an executable. How should the executable be named? Under Unix-type platforms it would normally have the form someprog and contain a shebang "#!/usr/bin/env ruby"; under Windows it would normally have the form someprog.rb, and rely on a file association of the ".rb" extension with Ruby. But for a gem that is meant for both platforms, what is the proper way of handling it?
It turns out that I don't have a problem after all - I can simply use the Unix convention of naming the executable someprog with a shebang* and without an extension and it will work on both Unix-type and Windows platforms. Apparently, the gem installation process results in a "facilitator" script being installed that calls the actual script under both types of OS's.
*Presumably, I don't even need the shebang under Unix, but I like to have it anyway.

Installing Primer3

I need to install Primer3 for my research in Windows, and I really have no idea of how to go about it. I was following the instructions mentioned here.
I'm getting to the part where I need to run
mingw32-make TESTOPTS=--windows
and I keep getting an error saying:
'mingw32-make' is not recognized as an internal or external command,
operable program or batch file.
Just for reference, I went into the minGW Installation manager and got the ming32-make packages, including the bin, doc, lang, and lic ones, because I really had no idea which one was the correct one.
If someone could help me, I would be very grateful! Installing these niche programs without an installation wizard is a challenge!
You will need to install mingw32-make. This is a
Windows of port of GNU Make,
a software-build tool that is supported on all operating systems,
indeed the daddy of such tools.
But make alone will not suffice. To build primer3 you will
need a Windows port of the whole GNU toolchain for building software
from source code. Without that, running make by itself will
just expose the absence of the GCC compiler and linker that it
expects to do its bidding.
This is quite a lot of software, but it is easy and quick to install and there
are several open-source offerings. I suggest you go to TDM GCC
and download the TDM64 bundle. This will give you an executable installer.
Just run it and you will end up with the complete GNU toolchain, including,
mingw32-make, in your chosen installation directory.
It will also install in your Windows launch menu the MinGW command prompt.
Launch this and you will be presented with a Windows commandline console
with its environment set up to find and run any of the GNU tools.
In this console change directory to your primer3-X.Y.Z/test directory
and then run mingw32-make TESTOPTS=--windows as per documentation.
Be forwarned that the self-tests of primer3 that are executed to
verify the build may take 1/2 hr. to 1 hr. to run, depending on your
hardware, but they will finish successfully with the steps I've
described, barring problems specific to your machine. It is a foolproof-simple build.
All the built executables are deposited in the primer3-X.Y.Z/src
directory. You may want to move them somewhere more convenient
in in your PATH.
It does seem oddly amateurish that the documentation simply
directs you to run mingw32-make with no preliminary account of
what that is or how to install it, while on the other hand it
advises that you must install perl and strongly recommends a
specific perl distribution; but evidently primer3 is open-source
scientfic software and its documentation is not bad by the standard
of that genre.

Can Elixir or Erlang programs be compiled to a standalone binary?

It says that Elixir has a tool called elixirc and Erlang has a tool called erlc to compile modules for use. It says immediately after this that you can then run code with the elixir command line tool.
Is there a way to compile a binary executable with Elixir or Erlang? (one which I can chmod +x binary_name and then run from the same directory with ./binary_name)
Escripts support that to some extent but you still need Erlang installed in your machine. See this answer for more information: Elixir or Hex portable package format?
Make sure you checkout Distillery. It does what you need, without having to deal with Rebar.
Add this to your mix.exs file's dependencies then run mix release.
defp deps do
[{:distillery, "~> 0.9"}]
end
Their documentation is great:
Home - Distillery Documentation
You can use tools like rebar to generate a release that also contains the erts, which makes it possible to run said release on a machine where erlang is not installed. But the erts included corresponds to the operating system on which the release was built, i.e. windows binaries if built on windows.
You can use Elixir's built-in releases as of Elixir 1.9. It is a lightweight alternative to Distillery.
Caveats:
It will not create anything remotely like Go does with a single binary executable that you can run almost anywhere. Also your target will have to match the CPU architecture and OS.
To build a release run:
mix release
Read more here:
https://hexdocs.pm/mix/Mix.Tasks.Release.html
There are a few tools now that allow you to create a self contained executable binary that doesn't require any dependencies on the target machine. They support multiple platforms.
Bakeware: https://github.com/bake-bake-bake/bakeware
Burrito: https://github.com/burrito-elixir/burrito

How to run ruby programs on Windows 7?

Does anyone know how to run/compile Ruby programs on Windows 7? For example you can compile Java in Eclipse, but I can't seem to find one for Ruby.
http://rubyinstaller.org/ - "The easy way to install Ruby on Windows".
Will give you the language and execution environment - everything you should need to get started.
Ruby isn't compiled, but rather interpreted. You need to install Ruby using the above link given by #ilollar.
Then, if you have the source code of a program in the file some_ruby.rb, you will execute this in cmd:
ruby some_options.rb
This is the general form of a ruby command:
ruby [ruby options] [program name] [program options]
Here is a free online book that will answer most of the question you have about Ruby if you are just starting out: http://ruby.learncodethehardway.org/book/
It's called "Learn Ruby the Hard Way", but don't let the name throw you off - the book is actually pretty easy to follow and doesn't assume you know anything about programming.
It will get you started writing Ruby and running programs for the first time.
Like ilollar said, the Ruby Installer is the best way to put Ruby on your Windows computer.
I'm currently running Ruby on Windows 7 writing Rails applications. You can do a lot on Windows with Ruby, however, you can't do everything. There are bundles of files that you can download that will help you write your Ruby programs - they are called Gems. Some gems will not run on Windows - The Ruby Racer and some versions of EventMachine are two that immediately come to mind.
This can be frustrating, but if it ever happens you can install a version of Linux in a virtual machine on your Windows computer so that you can use these gems without having to get a new machine.
You can also install Linux to run alongside Windows without having to reformat or mess with the partitions on your hard drive. There is a program called 'Wubi' that will install Ubuntu (a version of Linux) to run inside your Windows machine. It will actually let you pick Windows or Linux when you start your machine.
But all this is stuff to think about later on. You can certainly develop Ruby on Windows for now.
Also, in case you want to run just Ruby interactively, find the location where it is installed and browse to the bin subdirectory. For me this was \RailsInstaller\Ruby1.9.3\bin. In this directory there should be a file irb.bat. Double-click on it and you'll get a Ruby console session.
You can create window executables with ocra. That way you can create the app and push the app to another pc that does not have Ruby installed on it.

Resources