by: doug | December 30th, 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.
Sockets
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.
- etc
- fcntl
- iconv
- socket
- stringio
- strscan
- syck
- thread
- zlib
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"
- CONFIG = {}
- ...
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 scrips (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.
Sinatra
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 build. 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'
- Sinatra::Application.default_options.merge!(
- :run => false,
- :env => :production,
- :port => 80
- )
- get '/' do
- "Hello Sinatra!"
- end
- 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!
Leave a Reply
#
February 26th, 2009 at 12:20 AM
Very cool indeed. I've done the same with the Gumstix platform, with the real adventurous objective of getting a merb-based app running there. The biggest hurdle I have right now is the do_sqlite3 gem, which requires native extensions to be compiled. I've got no idea how to do this...or even an idea of where to start.
I've backed off the merb path, and am now opting for a skinnier Sinatra app. Data is still an issue and would love to be able to utilize DataMapper/sqlite3. Until then I think I'm gonna just hack YAML to a microSD card.
The LED is the easy part. :-)
March 3rd, 2009 at 04:22 AM
A note about the new sinatra version ...
Since 0.9.1 the server is selected in the following order ['thin', 'mongrel', 'webrick']. So if you don't have mongrel installed it will fallback to webrick.
Or set it in Sinatra, so you don't have to bother about Rack anymore:
require 'sinatra'
configure do set :server, 'webrick' end
get '/' do 'hello world' end
Cheers!
June 15th, 2010 at 08:32 PM
Is there any other magic required to get sockets working? I followed the first part of your tutorial and got Ruby running nicely on my ARM board (thanks!). I'm not able to require 'socket' though. I uncommented the socket line in ext/Setup, rebuilt Ruby with make && make install, but still no luck.