|< << >> >|

Racket on Android (2012/07/21)

A smart smartphone

The recent smartphones have quite impressive specs. E.g. the Samsung Galaxy S III comes with a 1.5 GHz quad-core processor and a GPU. It would be interesting though to run a real programming language on one of those phones. I am quite interested in the Racket programming language (also see Wikipedia) which offers full meta-programming and compile-time macros. I managed to cross-compile Racket to run on an Android phone HTC Desire S. I’ll describe the steps here. Hopefully I’ll find time to improve things and package it in some way.

Build

To cross-compile Racket for ARM you first need to compile Racket for the host system. The GCC cross-compiler and the Racket interpreter are then used during the cross-compilation.

#!/bin/sh
ARCHIVE=$HOME/Documents/programming/racket-5.2.1-src-unix.tgz
rm -Rf /tmp/build
mkdir -p /tmp/build/host
cd /tmp/build/host
tar xzf $ARCHIVE
BUILD_HOST=/tmp/build/host/racket*
cd $BUILD_HOST/src
./configure
make install
mkdir -p /tmp/build/cross
cd /tmp/build/cross
tar xzf $ARCHIVE
BUILD_CROSS=/tmp/build/cross/racket*
cd $BUILD_CROSS/src
./configure --host=arm-linux-gnueabi
make \
  RUN_THIS_RACKET_CGC=$BUILD_HOST/src/racket/racketcgc \
  RUN_THIS_RACKET_MMM=$BUILD_HOST/src/racket/racket3m \
  RUN_THIS_RACKET_MAIN_VARIANT=$BUILD_HOST/src/racket/racket3m \
  HOSTCC=/usr/bin/gcc \
  HOSTCFLAGS="-g -O2 -Wall -pthread -I./include" \
  STRIP_DEBUG="arm-linux-gnueabi-strip -S" 
make \
  RUN_THIS_RACKET_CGC=$BUILD_HOST/src/racket/racketcgc \
  RUN_THIS_RACKET_MMM=$BUILD_HOST/src/racket/racket3m \
  RUN_THIS_RACKET_MAIN_VARIANT=$BUILD_HOST/src/racket/racket3m \
  HOSTCC=/usr/bin/gcc \
  HOSTCFLAGS="-g -O2 -Wall -pthread -I./include" \
  STRIP_DEBUG="arm-linux-gnueabi-strip -S" \
  install
cd $BUILD_CROSS/src/racket
arm-linux-gnueabi-gcc -static -o racket3m  gc2/main.o libracket3m.a  -ldl -lm  -ldl -lm -rdynamic

The last command is used to replace the racket3m binary with a statically linked version.

Installation

First I installed Android Terminal Emulator. I also installed Kevin Boone’s kbox_shell which allows you to run BusyBox without requiring to jailbreak the phone (I don’t think BusyBox is required to run Racket but it is nice to have the various Linux shell utilities). I really recommend to install Hacker’s Keyboard to have a full PC keyboard on your phone.

Android Terminal Emulator

Then one needs to copy the following files to the mobile phone:

  • The racket3m binary is copied to the mobile in a location where it can be accessed from the terminal (e.g. /data/data/jackpal.androidterm/shared_prefs/kbox/bin/racket if you have kbox_shell installed).
  • Several Racket modules located in /tmp/build/cross/racket-5.2.1/collects/… need to be copied to $HOME/.racket/5.2.1/collects on the mobile phone. The libraries are
    • racket
    • syntax
    • setup
    • config
    • compiler
    • planet
    • mzlib
    • scheme
    • unstable
    • mzscheme

Racket on Android Unfortunately the full Racket language takes 90 seconds (!) to load on the HTC Desire S. Once loaded, the REPL is very responsive though.

Racket interpreter running on Android

Hopefully I get ffi and the readline library working to have an improved command line.

Any comments and suggestions are welcome

Update

It is possible to only load the Racket base language. Running the following command

racket -I racket/base

brings up the REPL in 7 seconds. Thanks Robby for the helpful comment!

Update

Racket 5.3.0 furthermore needs the following module to be installed:

  • s-exp

Update

I haven’t managed to build Racket with the Android NDK (see my thread on the Racket mailing list). Building Racket with the Android NDK would be preferable because otherwise it is impossible to dynamically load Android libraries in order to access Android specific functionality.

blog comments powered by Disqus

Latest News

...

2013/09/04

Creating a calculator with Bison, Flex, and Automake
More...

2012/11/07

The choice of programming language plays a fundamental role in the implementation of machine vision systems ...
More...

2012/08/02

Building a dynamically linked C program for Android
More...

2012/07/21

Running the Racket programming language on an Android phone
More...

2012/06/10

Comparison of the Clojure programming language with Scheme/LISP
More...

2011/10/20

Can we attract good and bad things with our mind?
More...

2011/09/25

Detecting the corners of a calibration grid
More...

2011/07/22

Synchronised audio/video display with Ruby and HornetsEye
More...

...