0% found this document useful (0 votes)
9 views49 pages

Rust OS Development: Setup & Basics

The document is an introduction to a course on OS development using Rust, highlighting the advantages of Rust over C, such as memory safety, high performance, and ease of concurrency. It outlines the expected outcomes, including setting up the development environment and learning basic Rust syntax. Additionally, it provides instructions for installing necessary tools and creating simple Rust projects using Cargo.

Uploaded by

Esele Eghogho
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views49 pages

Rust OS Development: Setup & Basics

The document is an introduction to a course on OS development using Rust, highlighting the advantages of Rust over C, such as memory safety, high performance, and ease of concurrency. It outlines the expected outcomes, including setting up the development environment and learning basic Rust syntax. Additionally, it provides instructions for installing necessary tools and creating simple Rust projects using Cargo.

Uploaded by

Esele Eghogho
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Getting Started with OS

Development
Course Introduction

George Uwagbale & Francis Enemuo 9/10/2025


SST/Computer Science SST Lab 1
Expected Outcomes

• Understand why Rust is better than C for this course.

• Setup environment for Rust development

• Successfully set up WSL/Ubuntu + VS Code + Rust toolchain.

• Learn basic Rust syntax.


Why Rust for OS Development
• Rust is a systems programming language focused on

speed, memory safety, and concurrency.

• Think of it as C++ with safety and modern design.

• It is used in:
This Photo by Unknown Author is licensed under CC BY-NC-ND

• Embedded system

• Web assembly

• CLI tool development

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Why Rust for OS Development
Memory Safety Without Garbage collection

One of Rust’s hallmark features is its ownership system,

which enforces memory safety at compile time. Unlike C

or C++, Rust eliminates common bugs like null pointer This Photo by Unknown Author is licensed under CC BY-NC-ND

dereferences and dangling pointers, all without relying

on a garbage collector.

Garbage Collection.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Why Rust for OS Development
High Performance Comparable to C/C++

Rust delivers blazing-fast performance akin to C and C++ because it compiles

directly to machine code and minimizes runtime overhead.

Its zero-cost abstractions ensure that features like iterators, pattern matching,

and trait-based polymorphism do not compromise execution speed.

• No Runtime Penalties: Rust’s abstractions are optimized to be as fast as

hand-written C code.

• Predictable Performance: Developers can write expressive and modular

code without worrying about hidden costs.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Why Rust for OS Development
Concurrency Made Safe and Easy

In modern system-level programming, concurrency is crucial for maximizing

hardware efficiency.

Rust simplifies and secures concurrent programming through its ownership

model:

• Data Race Prevention: Rust’s ownership system ensures that no two threads

can mutate the same data simultaneously.

• Concurrency Primitives: Libraries like tokio and async-std provide high-

performance tools for writing asynchronous and concurrent programs.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Why Rust for OS Development
Active and Growing Ecosystem

Rust’s ecosystem is robust and growing rapidly.

The community has developed libraries and tools that simplify complex tasks

like networking, file handling, and cryptography:

• Cargo: Rust’s package manager and build system make dependency

management seamless.

• [Link]: A vast repository of libraries ensures you have tools for virtually
Takeaway: Rust offers
every task.
C-level performance
• Cross-Platform Support: Rust supports major operating systems and can but prevents most bugs

target various architectures, making it ideal for embedded systems and OS- developers struggle
with.
level development.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Setting up Our Development Environment
Installing Visual Studio Code

• Download VS Code from [Link] then install it after downloading

• Install these VS Code extensions from the Extension Marketplace:

• Rust Analyzer

• Remote Explorer (If on Windows)


Setting up Our Development Environment
Why Do we need a Linux-like Environment?

• Systems programming requires tools that interact directly with hardware, like compilers,

linkers, and emulators. Linux provides these low-level development tools by default.

• Without Linux, setting up the toolchain on Windows/macOS is much harder.

• Windows and macOS are designed more for end-users, not for writing bare-metal

development.
This Photo by Unknown Author is licensed under
CC BY-SA

• If everyone works in Linux, it is easier for the instructor to guide and assist in debugging.
Setting up Our Development Environment
Choosing a Development Platform

• For Windows Users: Use WSL (Windows Subsystem for Linux) for Linux-like

enviroment

• For Mac Users: You’re already close to a Linux environment because macOS is

Unix-based, and Linux follows the Unix principles. Under the hood, macOS is built

on Darwin, derived from BSD (a Unix-like OS). This means your terminal and tools

behave very similarly to Linux.


Setting up Our Development Environment
Installing WSL (Windows Only)
• Prerequisites
• You must be running Windows 10 version 2004 and higher (Build 19041 and
higher) or Windows 11 to use the commands below. If you are on earlier
versions, please see how to manually install WSL.

• Open PowerShell as Administrator

• Run:
This Photo by Unknown Author is licensed
under CC BY-NC-ND

• This command will enable the features necessary to run WSL and install the

Ubuntu distribution of Linux. (This default distribution can be changed).

• Then restart your machine.


Setting up Our Development Environment
Installing WSL (Windows Only)

• After WSL has been downloaded and installed, you will be prompted to create a Unix user
account:

• Provide your preferred username after the colon.


Setting up Our Development Environment
Installing WSL (Windows Only)

• You will be prompted to set your password for your new Unix account. Please type in a secure
password that you can easily recall.

• When typing your password in the terminal, nothing will appear on the screen — not even *. This is a
Linux security feature to prevent shoulder surfing. Do not worry — your keystrokes are still being
recorded correctly. Just type your password and press Enter.
Setting up Our Development Environment
Installing WSL (Windows Only)

• If your password was successfully updated, then you have successfully installed WSL and the Ubuntu Linux
distribution
Setting up Our Development Environment
Setting up Ubuntu in WSL (Windows Only)

• Search ‘Ubuntu’ in your Windows search bar, you should see Ubuntu as an executable application,
please launch it:
Setting up Our Development Environment
Setting up Ubuntu in WSL (Windows Only)

• Of course, the username should be different for you.


Setting up Our Development Environment
Setting up Ubuntu in WSL (Windows Only)

• Update System:

Updates the package list and upgrades all installed packages to the latest version.

• Install build essentials (for compilers & tools):

Installs essential build tools, curl, and git.


Setting up Our Development Environment
Installing Rust Toolchain (WSL & Mac Users)

• Install Rustup (Rust installer/manager):

Downloads and runs the Rust installation script securely.

• Add environment variables:

Loads Rust’s environment variables into the current shell session.


Setting up Our Development Environment
Verify Installation (WSL & Mac Users)

• Verify that the Rust Compiler was installed:

• Verify that Cargo was installed:


Setting up Our Development Environment
Folder Structure (WSL & Mac Users)

• We need a folder where all our codes for this course would live:

• After creating the csc308 directory, navigate into it to make it your current working directory:
Rust Basics
Hello, World!

• To write our first Rust program, we need to make a new source file and call

it [Link]. Rust files always end with .rs extension.

• In our working directory, run:

• The above command creates a new file names [Link].

• To ensure that the [Link] file was created, we need to list out all the files

and directory in our current working directory, run:

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Rust Basics
Hello, World!

• You should see [Link], like so:

• Now open the file with the nano command-line text editor:

• You should see a window that looks like the image on the next slide

(Please go to the next slide).

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Rust Basics
Hello, World!
Rust Basics
Hello, World!

• Enter the code below:

• After entering the code, save the file (Ctrl + S).

• Then exit the nano text editor (Ctrl + X).

• Run the following commands to compile and run the Rust code:

• Compiles the Rust file

• Runs the compile Rust file


Rust Basics
Hello, World!

• Hello, world! should be printed to your terminal:

• We have just run a newly created program, so let us take a moment to examine each step in

the process.

• Before running a Rust program, you must compile it using the Rust compiler by entering the

rustc command and passing it the name of your source file, like this:

• From your C++ background, you will notice that this similar to gcc or clang. After compiling

successfully, Rust outputs a binary executable.


Rust Basics
Hello, World!

• You can see the executable by entering the ls command in your terminal.
Rust Basics
Hello, Cargo!

• Cargo is Rust’s build system and package manager.

• Cargo handles tasks such as building your code, downloading libraries that

your code depends on, and building those libraries. (These libraries are called

dependencies).

• Simple Rust programs, like the one we have written so far, has no

dependencies.

• As you write more complex Rust programs, you will add dependencies. Adding

dependencies will be much easier if you start your project with Cargo

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Rust Basics
Creating a Project with Cargo

• Navigate back to your csc308 directory in your terminal.

• Run the following commands:

• The first command creates a new cargo project – and a new directory – called hello_cargo.

• We named our project hello_cargo, and Cargo creates its files in a directory of the same name.

• The second command navigates into the hello_cargo directory.

• To view the project structure for the hello_world, let’s open our project in VS Code.
Rust Basics
Creating a Project with Cargo

• Launch VS Code.

• Connect to your Ubuntu WSL target from the Remote Explorer extension:

• Click on the arrow button.


Rust Basics
Creating a Project with Cargo

• You should see the WSL: Ubuntu sign below in VS Code window. Now open the hello_cargo folder in VS

Code
Rust Basics
Creating a Project with Cargo
Rust Basics
Creating a Project with Cargo
Rust Basics
Creating a Project with Cargo

• Open [Link] file. It should look like this:

• This file is in the TOML (Tom’s Obvious, Minimal Language) format, which is Cargo’s configuration format.

• The first line, [package], is a section heading that indicates that the following statements are configuring

a package. As we add more information to this file, we will add other sections.
Rust Basics
Creating a Project with Cargo

• The next three lines set the configuration information Cargo needs to compile your program: the name,

the version, and the edition of Rust to use.

• The last line, [dependencies], is the start of a section for you to list any of your project’s dependencies. In

Rust, packages of code are referred to as crates. We do not need any other crates for this project, so we

will use this dependencies section as is.


Rust Basics
Creating a Project with Cargo

• Now open the src/[Link] file. Cargo generated a “Hello, world!” program for you, just like the one from our

hello_world project.

• So far, the differences between our project and the project Cargo generated are that Cargo placed the

code in the src directory, and we have a [Link] configuration file in the top directory. Cargo expects

your source files to live inside the src directory.

• Let us build and run the hello_cargo project.

• In your hello_cargo directory, run cargo build:


Rust Basics
Creating a Project with Cargo

• The command creates an executable file in target/debug/hello_cargo, rather than in your current

directory.

• We just built the hello_cargo project, let us run it:

• Note: You can build and run a project in one step using cargo run.
Rust Basics - Data Types, Variables, and Control flow
Variables and Mutability

• Rust variables are immutable by default for safety. Use mut when you need to change a value.

• Explore:

• Try removing mut and see what happens.

• Why would Rust make immutability the default?


Rust Basics - Data Types, Variables, and Control flow
Data Types

• Rust is statically typed – every variable has a type known at compile time.

• Scalar Types:

• A scalar type represents a single value. Rust has four primary scalar types:

• Integers → i32, u32, i64, etc.

• Floats → f32, f64

• Boolean → bool

• Character → char

• Compound Types:

• Compound types can group multiple values into one type. Rust has two primitive compound types:

tuples and arrays.


Rust Basics - Data Types, Variables, and Control flow
Data Types

Category Type Example

Integer i32, u32 let age: i32 = 25;

Float f32, f64 let price: f64 = 19.99;

Boolean bool let is_active = true;

Character char let letter = 'R';

Tuple (i32, f64, char) let person = (25, 72.5, 'M');

Array [T; N] let nums = [1, 2, 3, 4, 5];


Rust Basics - Data Types, Variables, and Control flow
Data Types

• Example:

• s
Rust Basics - Data Types, Variables, and Control Flow
Control Flow (If / Else)

• Example:

• Explore:

• Add a new branch for score below 40 -> “Needs Remedial Practice.”

• Turn the above program into a function grade(score: i32) -> String.
Rust Basics - Data Types, Variables, and Control Flow
Control Flow (If / Else)

• Pro Tip :

• The if expression can also return values. How ?

• Example:
Rust Basics - Data Types, Variables, and Control Flow
Loops and Iteration

• Rust has three (3) loop constructs: loop, while, and for.

• loop (infinite until you break):


Rust Basics - Data Types, Variables, and Control Flow
Loops and Iteration

• while loop:

• for loop:
Rust Basics
Classwork 1 – Smart Weather Temperature Converter

• The Nigerian Meteorological Agency (NMA) is building a weather

analysis system. Currently, weather stations store temperatures in

Celsius, but the international reporting team prefers Fahrenheit.

You are tasked to write a Rust program that automatically

converts temperatures between these two units for the report

generation module.

This Photo by Unknown Author is licensed under CC BY

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Rust Basics
Classwork 2 – Café Discount Calculator

• You have been hired by Smart Café, a local coffee shop that’s

modernizing its billing system. They want their new system to

automatically calculate discounts for customers based on how

much they spend.

• The café offers:

• 10% discount for bills above ₦5,000

• 15% discount for bills above ₦10,000

• No discount otherwise

• Your task is to write a Rust program that calculates the final bill

amount after applying any applicable discount.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Assignment
EKEDC Smart Meter

• The Smart Energy Company (SEC) wants a small billing calculator for

customers.

They charge a base rate of ₦20 per kWh (unit of electricity).

• If a customer uses above 100 kWh, they pay ₦25 per unit instead.

• If usage is above 200 kWh, they pay ₦30 per unit.

• Your task is to write a Rust program that calculates and displays the total

electricity bill for a customer. Customers should be able to type in their

energy consumption.

Unlocking Potential. Building Responsible Leaders [Link] pau_Nigeria Pan-Atlantic University


Thank you.

[Link] pau_Nigeri Pan-Atlantic


a University

You might also like