How to deploy Eclipse Theia on a Raspberry Pi

September 12, 2018 | 4 min Read

Eclipse Theia is a platform to create IDEs and custom (modeling) tools based on  web technology (Typescript, CSS and HTML). Please see this article for details about this new Eclipse project.

One advantage of using web technology and more in particular Eclipse Theia is that the tool can then be accessed directly in the browser without any installation or client set-up. However, this only works, if the tool based on Theia has been deployed somewhere. This could be a cloud server, a docker container, or in our case a Raspberry Pi! You might wonder why you would want to deploy a browser tool on a Raspberry Pi. First of all, a Raspberry is probably the cheapest server you can imagine, so if, for whatever reason, you cannot deploy and access your tool in the cloud, a Raspberry still allows a local client/server deployment. More interestingly, Raspberry Pis are often used to control or orchestrate embedded use cases. That means, the Raspberry executes some software which can control devices that are connected to it. In this scenario, having the tooling to develop this software running on the Raspberry provides a very consistent set-up. You could then ship a Raspberry which includes the software and the tooling -  all on one device.

Anyway, since when do we need a reason to deploy something on a Raspberry Pi? It is just fun, so let us get going!

At this point we assume that you already installed the runtime dependencies of Theia, namingly Node.js v8 and Yarn.

The main issue we will have to deal with is a mismatch of processor architectures. The Raspberry Pi is powered by an ARM processor, while your development machine is likely an x86 based architecture. While it is certainly possible to build Theia directly on the Raspberry, you might want to instead use your regular computer for this. Doings so will save you the hassle of setting up the full build environment on the Raspberry and compilation will also be much faster.

However, you cannot simply copy your Theia build from a x86 based machine onto the Raspberry. This might seem odd at first because after all it is JavaScript based. However, Theia uses certain interfaces to make use of native OS functionality. For example, the terminal feature is based on the node-pty module, which forks native OS processes in the background and redirects their output. These interfaces include some C or C++ code, which must be compiled for the architecture Theia is running on. To be able to build code for the ARM architecture on your regular x86 machine you need a so called “cross-compiler”. As the name implies it will allow you to compile code for a target architecture that is different from the architecture the building machine itself is running on. The Raspberry Linaro provides a cross-compiler which you can find on github. Clone this repository as a preparation and point the paths to it later (see below).

First, compile Theia as usual using

yarn install

This will build Theia for your current architecture (x86). Now we need to re-compile the native bits using our cross compiler. To do that we have to set two environment variables, defining the C and CPP compiler to use. You can set them like so:

export CC=/opt/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc
export CXX=/opt/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++

Make sure to accordingly adapt the locations to your installation.

Afterwards, you need to run the following command line in the Theia project root directory to re-compile the native code parts for a

npm rebuild --target_arch=arm

Finally, unset the cross-compiler using:

unset CC CXX

That’s it! Copy your project directory onto your Raspberry and start it as usual:

Note: There is currently a time out issue when running Theia on a slow machine like a Raspberry Pi. You can avoid this problem by appending --no-cluster to the yarn start command. With this option, everything will run in the same process rather than separate worker processes. The progress of this issue is being tracked on github.

If you are interested in building web-based tools or integrate Theia into your tool chain for embedded devlopment, please have a look at our consulting and support options for Eclipse Theia.

Jonas, Maximilian & Philip

Jonas Helming, Maximilian Koegel and Philip Langer co-lead EclipseSource. They work as consultants and software engineers for building web-based and desktop-based tools. …