Goal
This tutorial describes setting up a complete Rust development environment and creating a first Hello World project.
By the end, the following skills are covered:
Installing the Rust compiler
Using the Cargo build system
Creating Rust projects
Compiling and running applications
Running tests
Setting up a development environment with VS Code
Prerequisites
Supported operating systems:
Linux
Windows 10/11
macOS
Recommended:
Git installed
VS Code installed
Command-line knowledge
Installing Rust
Rust is installed via the official rustup tool.
Linux / macOS
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | shThen restart the shell:
source "$HOME/.cargo/env"Verify the installation:
rustc --version
cargo --versionExample:
rustc 1.88.0
cargo 1.88.0Windows
Download the installer:
Then open PowerShell:
rustc --version
cargo --versionOn Windows, the following are additionally required:
Visual Studio Build Tools
MSVC C++ compiler
Windows SDK
Install via:
rustup default stable-x86_64-pc-windows-msvcManaging the Rust toolchain
Show the current toolchain:
rustup showActivate the stable version:
rustup default stableInstall updates:
rustup updateInstalling development tools
Recommended components:
rustup component add rustfmt
rustup component add clippyVerify:
rustup component list --installedVS Code setup
Install the following extensions:
rust-analyzer
CodeLLDB
Even Better TOML
Recommended settings:
{
"rust-analyzer.checkOnSave.command": "clippy",
"editor.formatOnSave": true
}Creating the first Rust project
Rust uses Cargo as its build system and package manager.
Create a new project:
cargo new hello_worldSwitch into the project:
cd hello_worldThe structure:
hello_world
|
+-- Cargo.toml
|
+-- src
|
+-- main.rsCargo.toml
The file describes the project:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
# [dependencies]Hello World implementation
File: src/main.rs
Content:
fn main() {
println!("Hello, Rust!");
}Building the program
Debug build:
cargo buildThe resulting binary is located at target/debug/hello_world.
Running the program
Directly with Cargo:
cargo runOutput:
Hello, Rust!Release build
For optimized builds:
cargo build --releaseThe resulting binary is located at target/release/hello_world.
Release builds include:
Optimizations
Smaller runtime
Better performance
Rust formatting
Automatic formatting:
cargo fmtExample:
fn main() {
println!("Hello, Rust!");
}Code analysis with Clippy
Clippy finds common mistakes:
cargo clippyExample:
warning: this expression borrows a value that is already borrowedUnit tests
Rust has a built-in test framework.
Example:
#[cfg(test)]
mod tests {
#[test]
fn hello_test() {
assert_eq!(2 + 2, 4);
}
}Run the tests:
cargo testOutput:
test result: okAdding dependencies
Example:
Cargo.toml
[dependencies]
serde = "1.0"Then:
cargo buildCargo automatically fetches:
Crates
Versions
Dependencies
Cross compilation basics
Show installed targets:
rustup target listExample for ARM64:
rustup target add aarch64-unknown-linux-gnuBuild:
cargo build --target aarch64-unknown-linux-gnuTypical embedded targets:
thumbv7em-none-eabihf
thumbv8m.main-none-eabihf
riscv32imac-unknown-none-elfPreparing for embedded Rust
Additional tools:
cargo install cargo-embed
cargo install cargo-binutilsARM toolchain:
rustup target add thumbv7em-none-eabihfExample platforms:
STM32
nRF52
ESP32
RP2040
Debugging
With GDB:
rust-gdb target/debug/hello_worldVS Code uses:
CodeLLDB
OpenOCD
J-Link
Typical development workflow
Change code
|
cargo fmt
|
cargo clippy
|
cargo test
|
cargo build --releaseSummary
After this tutorial, a complete Rust development environment is in place.
Important commands:
| Command | Description |
|---|---|
cargo new | Create project |
cargo build | Compile |
cargo run | Run |
cargo test | Run tests |
cargo fmt | Format |
cargo clippy | Code analysis |
rustup update | Update toolchain |
Next steps
For embedded systems developers:
no_std Rust
HAL libraries
Device crates
Embedded trait architecture
Rust driver development
Rust AUTOSAR-adjacent abstraction layers