Using Rust with the Kubos SDK¶
The Kubos SDK Vagrant box comes with support for Rust, Cargo, and several helper tools to integrate C-based Kubos libraries with Rust projects.
Note
All of the following instructions are assumed to be run inside of the Kubos SDK Vagrant environment.
Cargo-Kubos¶
A special Kubos SDK tool has been created for build interoperability between Rust projects and C projects: cargo kubos. This tool allows Rust projects to correctly compile against existing C libraries and also provides cross-compiler compatibility for existing Kubos hardware targets.
New Project¶
A new Rust project can be created by running either of the following commands:
Executable project:
cargo new --bin bin_name
Library project:
cargo new lib_name
Cargo will create the project folder and a basic folder structure.
Compiling¶
Compiling a Rust project is done from within the project’s folder. The command is:
cargo kubos -c build
Running this command as-is will compile the current Rust project with the native Linux compiler.
Running¶
Running a local Rust project must also be done from within the project’s folder. The command to run an executable project is:
cargo kubos -c run
Note
This command will only work for executable projects, not library projects.
Cross-compiling¶
The Kubos SDK supports cross-compiling Rust projects through the cargo kubos
tool.
The syntax for cross-compiling is:
cargo kubos -c build -t [target]
The following targets are currently supported:
kubos-linux-beaglebone-gcc
- Beaglebone Blackkubos-linux-pumpkin-mbm2-gcc
- Pumpkin MBM2kubos-linux-isis-gcc
- ISIS iOBC
Flashing¶
Note
The addition of Rust to the Kubos SDK is pretty recent and SDK tooling is currently undergoing revision to make the flashing process smoother!
Flashing Rust projects is currently done using the Kubos CLI. It is a bit of a process laid out in the following steps:
- Make sure the target hardware is attached to your computer via a serial cable.
- Cross-compile the Rust project for the desired target.
- Navigate to an existing example kubos module like
kubos-linux-example
. - Run
kubos linux -a
. - Run
kubos -t [target] build
using the same target you cross-compiled with. - Run
kubos flash $(find `pwd`/rel/path/to/project -name project_name -type f)
. It is important here that you put the relative path to your rust project after the`pwd`
. Another option iskubos flash /absolute/path/to/rust/binary
. - Assuming all went well you will now see
kubos flash
sending your compiled binary over to the target.
Running on Target¶
The following steps will allow you to run Rust binaries which have been flashed to a Linux target:
- Make sure the target hardware is attached to your computer via a serial cable.
- Run
minicom kubos
from inside of the Vagrant box. - Enter the username
kubos
and the passwordKubos123
. - Navigate to the folder
/home/system/usr/local/bin
. - This folder is the default destination for flashed files. Your binaries should
be here. You can now run them with
./{binary-name}
.