eightbitraptor[wiki]

Building Ruby

Lots of good resources into how we can build Ruby in Koichi’s Ruby Hack challenge.

Basic gist for building is that it’s best to separate the source tree from the build artifacts. Ruby uses a two phase build where it builds a binary called miniruby and then uses that in the second stage build to build the actual ruby binary (and others). And this process creates a bunch of build artifacts that make clean doesn’t appear to clean up, hence keeping this separate from your actual code checkout.

This causes a couple challenges with setting up editors: see [setting-up-vscode-for-mri], where some of the include files are in your build dir which the editor doesn’t know about yet.

Getting the build structure ready

  ruby
    ├── ruby
    │   └── <git checkout here>
    └── build
    │   └── <Makefile and other build root artifacts>
    └── install
        └── <make install results get put here>

Alternative configure

Aaron recommended doing:

begin
  set -lx debugflags '-g'
  set -lx optflags '-O0'
  set -lx RUBY_DEVEL 'yes'
  ../ruby/configure --prefix=~../install --disable-install-doc --with-openssl-dir=(brew --prefix)/opt/openssl
end

This will make sure that every time Ruby builds either itself or any of the included gems it always builds with:

It’s also possible to compile without this and then edit the generated Makefile, but this doesn’t apply these to any gems that are built - just the main miniruby and ruby binaries. Which can be a pain.

Building and installing

This will build and install ruby, irb, gem, bundler et al and dump them in your configured install directory. This takes time (rougly 5 minutes on my work MacBook Pro, longer on my personal Surface Pro).

Building for development

This obviously depends on what your working on, but for my purposes, where I’m predominantly in the GC or the VM, just building the initial miniruby binary is enough. Do this with

make miniruby

Once Ruby/miniruby is built you should be good to start development. See