As Wikipedia says, Rust is a multi-paradigm, high-level, general-purpose programming language designed for performance and safety, especially safe concurrency. Rust is syntactically similar to C++, but can guarantee memory safety by using a borrow checker to validate references. Rust achieves memory safety without garbage collection, and reference counting is optional.
Developing with Rust on Debian
Debian ships rustc (the Rust compiler), cargo (the Rust package manager and build system), rustfmt (the Rust code formatter), a number of packages written in Rust or including modules written in Rust, and a growing number of Rust crates (Rust libraries).
Using crates from Debian
Due to the way Rust and the Rust crates are packaged in Debian, packages shipping Rust crates are mainly useful when packaging other crates or Rust-based software for Debian. While you can use them for everyday development with Rust, their main use is as dependencies for other applications since Debian doesn't allow downloading source code at build-time.
To only use the local (Debian) version of crates, place the following snippet in a .cargo/config file at your projects' root:
[source] [source.debian-packages] directory = "/usr/share/cargo/registry" [source.crates-io] replace-with = "debian-packages"
.. and install any of its crate dependencies via apt install librust-CRATE-dev (or declare them in debian/control if it's for a package).
To identify which dependencies of a project are packaged you can use cargo-debstatus:
sudo apt install cargo-debstatus cargo debstatus
Using crates from the Internet
For everyday Rust development, you may find rustup useful (only available since Debian 13 trixie), as it provides a convenient way to install Rust toolchains and switch between them globally or on a per-project basis.
# Install rustup $ sudo apt install rustup # Use the latest stable Rust release from upstream $ rustup default stable # Read the official documentation "The Rust Programming Language" $ rustup docs --book # Update an existing installation to the latest release $ rustup update # More options $ rustup --help
Crosscompiling
See CrossCompiling for a general introduction.
You can compile for a different architecture (e.g. Risc-V) by adding the following to your ~/.cargo/config.toml:
[target.riscv64gc-unknown-linux-gnu] linker = "riscv64-linux-gnu-gcc" rustflags = ["-L", "/usr/lib/rustlib/riscv64gc-unknown-linux-gnu/lib"]
And then:
sudo dpkg --add-architecture riscv64 sudo apt update sudo apt install libstd-rust-dev:riscv64 libc6-dev:riscv64 cargo build --target riscv64gc-unknown-linux-gnu
Using Rust Analyzer
The Rust Analyzer should not be used with untrusted Rust source code because it executes arbitrary code.
The Rust Analyzer extension for VS Code comes with the binary of the analyzer, but it doesn’t come with the source code of the Rust standard library, which is required for the analyzer to operate. Debian ships the source code as rust-src.
Other editors require downloading the binary manually. Packaging is requested in 1052319. You can also install it with rustup.
$ rustup component add rust-analyzer rust-src
Packaging Rust applications and crates
For packaging:
Gnome applications -> see Gnome/Rust_Packaging
Crates -> see Teams/RustPackaging