Getting started with Rust#

Before you start#

Before we can use the SimpleSwitch™ SDK for Qt (version 6) we need to download the SDK extension. For this you need to run from the sourced SimpleSwitch™ SDK

GITHUB_TOKEN="<your personal access token for Github>" GITHUB_USERNAME="<your Github username>" simpleswitch-sdk-tool install rust
eval "$(simpleswitch-sdk-tool activate)"

Github personal access token

To create a Github personal access token see Github container registry (GHCR)

Using Rust with Cargo#

Using the Cargo tool, building a SimpleSwitch™ package can be done by sourcing the SDK environment and running the simpleswitch-generate-package script

. /opt/sc/0.1.0/sm2s-imx8plus/environment-setup-cortexa53-crypto-simplecoredistro-linux
mkdir helloworld
cd  helloworld
cargo init --vcs=git .
# # edit the code
cargo build --profile=release
simpleswitch-generate-package --name simpleswitch-example --template rust \
  --startup-command "/usr/bin/helloworld" --copy-dir target/${CARGO_BUILD_TARGET}/release/helloworld:/usr/bin/helloworld --work-dir simpleswitch
For more info about using Cargo, please see Cargo book:

Flash and debug on device a Rust application#

If you want to debug the application using GDB just replace the previous cargo build and simpleswitch-generate-package instructions by the following ones

cargo build
simpleswitch-generate-package --name simpleswitch-example --template rust \
  --startup-command "while true; do gdbserver :2159 /usr/bin/helloworld; done" --copy-dir target/${CARGO_BUILD_TARGET}/debug/helloworld:/usr/bin/helloworld --work-dir simpleswitch

To remote debugging a Rust application, you can see Remote debug a SimpleSwitch™ package

Deploy to the target#

Now it is time to deploy the generated SimpleSwitch™ container to the device. For this please see Deploy a SimpleSwitch™ package

External Rust packages#

To add external packages from your Rust workspace you can run

cargo add <package name>

see cargo add command help page, for more details.

Further reading#