Embedded Ruby Sings Sinatra

Embedded Ruby Sings Sinatra

Doug Bradbury
Doug Bradbury

December 30, 2008

Last Time I got ruby up and running on my Arm based embedded development platform. Here is a quick summary of what Santa and I did over Christmas.


Getting support for sockets built into Ruby turned out to not be hard at all. All I had to do has uncomment the extensions I wanted in ext/Setup. Here is everything I decided to turn on.


After a rebuild and reinstall, I could require and use socket. Welcome, Ruby, to the outside world!

Relocating Ruby

I decided to move Ruby to the ‘standard’ install directory (/usr/local/) instead of the root that I had done in the first iteration. This would avoid having to set the RUBYLIB environment variable and keep any mess I made out out of the main system /bin and /lib directories.

First I removed the --prefix from the configure script I had written last time. This will cause Ruby to build assuming the default install location (/usr/local/).

#! /bin/sh
export ARM_TOOLS=/usr/local/arm/gcc-4.2.3-glibc-2.3.3/arm-unknown-linux-gnu/bin
export CC=$ARM_TOOLS/arm-unknown-linux-gnu-gcc
export LD=$ARM_TOOLS/arm-unknown-linux-gnu-gcc
export AR=$ARM_TOOLS/arm-unknown-linux-gnu-ar
export RANLIB=$ARM_TOOLS/arm-unknown-linux-gnu-ranlib
export ac_cv_func_getpgrp_void=yes
export ac_cv_func_setpgrp_void=yes
./configure --host=arm-unknown-linux --enable-wide-getaddrinfo

After Ruby was built, but before installing it (make install), I hacked the DESTDIR in rbconfig.rb

TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/arm-linux")
DESTDIR = "/~/ruby/install"

This created the /usr/local tree inside my install directory. I created a /usr/local/ on my file system and copied that tree over. The only problem with this process is that the sh-bang line on the top of all of the Ruby scripts (irb, testrb, etc.) had the wrong path in them.

They had the install path on the host machine (/~/ruby/install/usr/local/bin/ruby) instead of the actual path on the target (/usr/local/bin/ruby). I changed those by hand.


Ahh, now the good part. Using a gem on an embedded system is an interesting problem. I first had to get rubygems installed on the network files system. I downloaded the source code and temporarily placed in on the target files system. On the target I ran the install command.

ruby setup.rb --no-rdoc --no-ri

I found it more convenient to install the gems from the host system instead of the target. It would be faster and the gem command had some Ruby dependencies that I hadn’t yet built.

I downloaded Sinatra and Rack and then manually installed them into my target’s file system on the host machine. Note that /arm/fs/ is the root of my networked file system. I switched off rdoc and ri to help keep the install small.

sudo gem install sinatra-0.3.2.gem -i /arm/fs/usr/local/lib/ruby/gems/1.8 --no-rdoc --no-ri
sudo gem install rack-0.4.0.gem -i /arm/fs/usr/local/lib/ruby/gems/1.8 --no-rdoc --no-ri

With Sinatra installed and ready to go, I wrote a quick Sinatra app. Sinatra runs on Mongrel by default, but I wanted to run on the lighter weight Webrick web server which was already in my ruby installation.

require 'rubygems'
require 'rack/handler/webrick'
require 'sinatra'

		:run => false,
		:env => :production,
		:port => 80
get '/' do
		"Hello Sinatra!"
Rack::Handler::WEBrick.run Sinatra.application

Drum roll please…

Next Steps

I've been plugging away on the Linux device and ruby extension side of the project. I’m still on the steep side of the learning curve, but making progress. I’m still after that elusive blinking LED!