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 | sh

Then restart the shell:

source "$HOME/.cargo/env"

Verify the installation:

rustc --version
cargo --version

Example:

rustc 1.88.0
cargo 1.88.0

Windows

Download the installer:

Then open PowerShell:

rustc --version
cargo --version

On Windows, the following are additionally required:

  • Visual Studio Build Tools

  • MSVC C++ compiler

  • Windows SDK

Install via:

rustup default stable-x86_64-pc-windows-msvc

Managing the Rust toolchain

Show the current toolchain:

rustup show

Activate the stable version:

rustup default stable

Install updates:

rustup update

Installing development tools

Recommended components:

rustup component add rustfmt
rustup component add clippy

Verify:

rustup component list --installed

VS 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_world

Switch into the project:

cd hello_world

The structure:

hello_world
|
+-- Cargo.toml
|
+-- src
|
+-- main.rs

Cargo.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 build

The resulting binary is located at target/debug/hello_world.

Running the program

Directly with Cargo:

cargo run

Output:

Hello, Rust!

Release build

For optimized builds:

cargo build --release

The resulting binary is located at target/release/hello_world.

Release builds include:

  • Optimizations

  • Smaller runtime

  • Better performance

Rust formatting

Automatic formatting:

cargo fmt

Example:

fn main() {
    println!("Hello, Rust!");
}

Code analysis with Clippy

Clippy finds common mistakes:

cargo clippy

Example:

warning: this expression borrows a value that is already borrowed

Unit 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 test

Output:

test result: ok

Adding dependencies

Example:

Cargo.toml

[dependencies]
serde = "1.0"

Then:

cargo build

Cargo automatically fetches:

  • Crates

  • Versions

  • Dependencies

Cross compilation basics

Show installed targets:

rustup target list

Example for ARM64:

rustup target add aarch64-unknown-linux-gnu

Build:

cargo build --target aarch64-unknown-linux-gnu

Typical embedded targets:

thumbv7em-none-eabihf
thumbv8m.main-none-eabihf
riscv32imac-unknown-none-elf

Preparing for embedded Rust

Additional tools:

cargo install cargo-embed
cargo install cargo-binutils

ARM toolchain:

rustup target add thumbv7em-none-eabihf

Example platforms:

  • STM32

  • nRF52

  • ESP32

  • RP2040

Debugging

With GDB:

rust-gdb target/debug/hello_world

VS Code uses:

  • CodeLLDB

  • OpenOCD

  • J-Link

Typical development workflow

Change code
|
cargo fmt
|
cargo clippy
|
cargo test
|
cargo build --release

Summary

After this tutorial, a complete Rust development environment is in place.

Important commands:

CommandDescription

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