Compiling Rust for the Omega2

After receiving my Onion Omega2 from Indiegogo perk, I really wanted to see what was possible with it. So this would be a great opportunity for me to learn Rust and see what it takes to get it running on the Omega2.

I found a good blog from Shane Logsdon explaining how to get it to work with MacOS. I thought I create a simple guide how to compile Rust for the Omega2 on Linux (or windows WSL)

The Onion OS on the Omega2 is a modified version of the LEDE project and the microcontroller used in the Omega2 is the MediaTek Ralink MIPS MT7688. So our goal is to cross-compile rust for the MIPS platform.

This guide continues from on a previous guide where I explain how to compile LEDE (on windows).

Installing Rust

To install and configure rust we need to tell it how to install it and what targets it should support.

The IDE

For the IDE I use visual studio code, which is freely available from here, the following blog shows you how to configure the IDE to run and debug rust. But instead of the RustyCode extension I use the Rust extension which is more actively maintained and installs the dependencies needed automatically.

Tip: If you are unable to debug after following every instruction make sure you have configured rust to use GCC instead of MSVC (MSVC is default). There is a stackoverflow answer here.

We are now going to configure in visual studio code a task that enables us to compile a Rust application, the task is going to use the WSL to compile in Linux with the GCC compiler from the LEDE project we created in the previous guide.

Use CTRL + SHIFT + P and type task, select Configure TaskRunner and then select Other. Replace the existing content with the configuration below, be sure to replace the path with your location.

From now on its possible to execute CTRL + P and type the following to create a build ready for upload to the Omega2.

Now you are able to compile from within windows through the Linux Subsystem for the Omega2.

Creating a rust project and compile

We are almost ready to compile our program to run on the Omega2, first we need to create a rust project. Execute the following command to create a hello_world project in rust.

Next up is to create a config file for rust so that rust knows which linker to use for out target. Creating a directory .cargo and placing a file named config

The configuration will contain the following, replace <user> with your user of course.

Make sure you are in the directory of the project and execute the following to compile the application.

Copy and run it on the Omega2

I use scp to copy it to the /root/ directory on the Omega2, of course replace <ipadres> with the one of your Omega2.

Then use SSH to connect to the omega and give our hello_world executable rights by using the following command

And this will print “Hello, world from rust!”