Development Environment Setup
Overview
Building the Rust SDK requires two toolchains:
Toolchain |
Source |
Purpose |
|---|---|---|
Rust toolchain |
Rust official |
Compile Rust code and link the ELF firmware |
ARM bare-metal toolchain |
Realtek |
Provides |
Install the Rust Toolchain
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile minimal
$ source ~/.cargo/env
Note
Users in mainland China may set the following mirrors before installing:
$ export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
$ export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup
Install MSYS2:
winget install MSYS2.MSYS2
Open MSYS2 MSYS from the Start menu and run:
$ pacman -Syu
$ pacman -S --needed mingw-w64-x86_64-gcc
Open System Properties → Advanced → Environment Variables and add
C:\msys64\mingw64\bin to the user Path if it is not already present.
Install rustup in PowerShell:
Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile "$env:TEMP\rustup-init.exe"
& "$env:TEMP\rustup-init.exe" -y --default-host x86_64-pc-windows-gnu --default-toolchain none --profile minimal
Open a new PowerShell window after installation completes.
Note
Users in mainland China may set the following mirrors before installing:
$env:RUSTUP_DIST_SERVER = "https://mirrors.tuna.tsinghua.edu.cn/rustup"
$env:RUSTUP_UPDATE_ROOT = "https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup"
These can also be added as permanent system environment variables.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none --profile minimal
$ source ~/.cargo/env
Note
Users in mainland China may set the following mirrors before installing:
$ export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
$ export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup
Install the Nightly Toolchain
rust-toolchain.toml at the repository root pins the required nightly version, components, and
cross-compilation target. rustup installs everything automatically the first time rustc is run
inside the repository.
Run the following from the Rust SDK root:
$ cd <workdir>/rust
$ rustc --version
cd <workdir>/rust
rustc --version
$ cd <workdir>/rust
$ rustc --version
The first run triggers an automatic download and installation (may take a few minutes).
Install the ARM Bare-Metal Toolchain
Refer to the following guide to install the Realtek ASDK toolchain:
Verify Installation
$ rustup show active-toolchain
nightly-x86_64-unknown-linux-gnu (overridden by '.../rust/rust-toolchain.toml')
$ rustup target list --installed | grep thumbv8m.main-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
$ arm-none-eabi-nm --version
GNU nm (Realtek ASDK-12.x.x ...) 2.xx.x
> rustup show active-toolchain
nightly-x86_64-pc-windows-gnu (overridden by '.../rust/rust-toolchain.toml')
> rustup target list --installed | findstr thumbv8m
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
> where.exe x86_64-w64-mingw32-gcc
C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe
> arm-none-eabi-nm --version
GNU nm (Realtek ASDK-12.x.x ...) 2.xx.x
$ rustup show active-toolchain
nightly-aarch64-apple-darwin (overridden by '.../rust/rust-toolchain.toml')
$ rustup target list --installed | grep thumbv8m.main-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
$ arm-none-eabi-nm --version
GNU nm (Realtek ASDK-12.x.x ...) 2.xx.x