Practical Work

Git Repository

❎ First of all, you need to request to join the 4SE02/2425 group on the Telecom GitLab using this link.

Once this is done, the instructors will be able to create your personal repository where you can store your practical work.

Installation of rustup

An utility to manage the installation of Rust on a computer is rustup. Once rustup is installed, it takes care of downloading and locally installing (without privileges) the compiler and executables versions, especially for cross-compilation.

❎ Install rustup, either from your Linux distribution's package system or from the rustup.rs website. If you choose the second method, you will need to reload your environment after the installation of rustup so that the directories it uses are added to your PATH.

Note: The Rust ecosystem works not only on GNU/Linux but also on macOS and Windows. In this practical work, we will assume your installation is on GNU/Linux. You are free to use another operating system as long as you don't expect assistance with your system from us.

Note: If you reach the maximum quota assigned to you on the school's computers, you can use the directory /home/users/LOGIN (where LOGIN is to be replaced with your Unix account name), which is created locally when you log in. By setting the environment variable RUSTUP_HOME to /home/users/LOGIN/rustup in your initialization files, you can instruct rustup to store all its data in this directory rather than in ~/.rustup. Don't forget to delete the ~/.rustup directory to free up space. You will also need to repeat this operation if you log in to another computer in the TP rooms.

Installation of the "stable" compilation toolchain

Rust's compilation toolchain comes in three major families:

  • stable: a tested and proven version, updated every six weeks
  • beta: a test version intended to become the next stable version
  • nightly: a development version, allowing testing of experimental features, some of which are intended to enter the next beta version

By default, rustup has installed the latest stable version:

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /usr/local/rustup

stable-x86_64-unknown-linux-gnu (default)
rustc 1.84.1 (e71f9a9a9 2025-01-27)

On a development system, you may find several versions of development chains, targets, etc., for example:

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/johndoe/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain
--------------------------------------

armv7-unknown-linux-gnueabihf
thumbv6m-none-eabi
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-unknown
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)

You can update all installed components with rustup update.

❎ Make sure, especially for those who already had rustup installed, that you are using the latest stable version of Rust by running rustup update.

What comes with development chains:

  • cargo: the all-purpose tool that knows how to call others, it's almost the only one we will use directly through its commands (cargo build, cargo doc, cargo fmt, cargo clippy, etc.)
  • rustc: the Rust compiler
  • rustdoc: the documentation generator
  • rustfmt: the code formatter
  • clippy: the code linter

Editor

You are free to use the code editor of your choice. For editing Rust, we recommend Visual Studio Code with the rust-analyzer extension, which allows you to analyze your code directly from your editor. The Error Lens extension also warns of errors as you write code but may seem a bit intrusive at times.

Formatting and style

Rust comes with a very handy linter tool named Clippy which detects anti-patterns, weird or inefficient coding styles, and suggest ways of doing better using a more idiomatic Rust style.

⚠️ We expect you to regularly use cargo clippy to run Clippy on your code, and to apply the suggestions or change your code until Clippy does not complain anymore.

You may also:

  • deactivate some Clippy lints with the #[allow(clippy::some_lint_name)] attribute applied to an item (be prepared to come with a good justification for doing so);
  • use Clippy in an even stricter mode, by using cargo clippy -D clippy::pedantic.

⚠️ We also expect you to format your code according to the Rust standard. Fortunately, this is easy to do using cargo fmt.