mruby.sh

OpenWRT mruby Package

written by Daniel Bovensiepen on 2014-05-05 14:15 UTC

Two years ago I created a first mruby package for OpenWRT. It was based on cmake, the best way at that point to cross compile mruby to other platforms. Since then a lot has happened. First of all mrbgems were introduced by end of 2012. With 117 gems available today the best way to customise your very own mruby. In 2013 we moved the complete build system of mruby to Ruby (rake). With that we made it much easier to build Ruby in lots of different fashions. mrbgems was part of the rake build system from the very beginning, we actually never managed to introduce mrbgems to cmake. So in the end we dropped make and cmake and were left with the far more elegant rake.

I was still using OpenWRT in combination with mruby for so many use cases and due to the removal of cmake the old package didn’t worked anymore. So a new package was created but never released. I spent the last couple of hours to fix that, by making the package more clean and usable. So here it is…

New features

The original mruby package for OpenWRT had actually no options. You could only choose to compile it or leave it. With the introduction of mrbgems I consider it absolute necessary to provide the flexibility of mruby directly via the user-interface.

First of all you select under Languages->mruby the mruby package:

openwrt_mruby_1

Now you have three options:

Under the Binaries sub-menu you can select which executables should be build:

openwrt_mruby_2

The GEMs (Core) sub-menu gives access to all core gems which should be built into mruby:

openwrt_mruby_3

The sub-menu GEMs (External) lists a few GEMs not belonging to the main repository:

openwrt_mruby_4

How does it work?

The main task of the package is to generate the build_config.rb file. This is done by simply defining a new toolchain class which takes the OpenWRT environment variables for the host and target compiler toolchain. Additionally to support the selection of GEMs I generate a so called GEMBox, a feature I introduce some time ago which enables mruby to make use of a GEM group. For OpenWRT this makes it easier to customise the used GEMs due to the reason that only the GEMBox has to be dynamically generated. The build_config.rb is always the same.

How to use it

The package feed is available on GitHub. It can be simply integrated into OpenWRT by adding the following line to feeds.conf.default:

src-git mruby https://github.com/FlowGroup/openwrt-mruby.git

Installation works with the ./scripts/feeds script.

Next things…

Only a handful of external GEMs are currently integrated into the package. This selection is not random but consist of the GEMs I used for several projects and which I know are cross-compilable to many different platforms. The biggest issue which has to be solved before supporting more GEMs is to handle dependencies outside of mruby. For example I like the mruby-thread GEM from mattn but it can’t be currently used with OpenWRT due to the reason that it depends on libpthread. This library is available in OpenWRT but this package is currently not resolving the dependency. After solving this problem more GEMs can be added to the package.


available also via rss