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
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.
ruby ├── ruby │ └── <git checkout here> └── build │ └── <Makefile and other build root artifacts> └── install └── <make install results get put here>
../ruby/configure --prefix=$PWD/../install --enable-shared --with-openssl-dir="$(brew --prefix openssl)" --with-readline-dir="$(brew --prefix readline)" --disable-libedit
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:
-ginclude debug symbols - needed for C function labelling and decent debugger context (otherwise
lldbjust shows you assembly)
-O0minimal optimisations - this is needed to make sure that
cmakedoesn’t optimise out any local variables or useful information that you can use while debugging.
RUBY_DEVELenabled - I don’t actually know what this does yet.
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
ruby binaries. Which can be a pain.
make -j8 && make install
This will build and install
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).
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
is enough. Do this with
Once Ruby/miniruby is built you should be good to start development. See