Rust

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it (how to get started).

Rust is a general-purpose, multi-paradigm, compiled, programming language.

Installation

USE flags

A recommended USE flag to enable is system-llvm, but it can lead into a failed build due to possible LLVM version differences

USE flags for dev-lang/rust Systems programming language from Mozilla

clippy Install clippy, Rust code linter
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
dist Install dist tarballs (used for bootstrapping)
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
miri Install miri, an interpreter for Rust's mid-level intermediate representation (requires USE=nightly, sometimes is broken)
nightly Enable nightly (UNSTABLE) features (NOTE: it does not install nightly version, just enables features marked as nightly at time of release)
parallel-compiler Build a multi-threaded rustc (experimental, not tested by upstream)
profiler Build the profiler runtime and rust-demangler tool (needed for '-C profile-generate' or '-C instrument-coverage' codegen opts)
rls Install rls, Rust Language Server (used with IDEs supporting RLS protocol)
rust-src Install rust-src, needed by developer tools and for build-std (cross)
rustfmt Install rustfmt, Rust code formatter
system-bootstrap Bootstrap using installed rust compiler
system-llvm Use the system LLVM installation
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
verify-sig Verify upstream signatures on distfiles
wasm Build support for the wasm32-unknown-unknown target

USE flags for dev-lang/rust-bin Systems programming language from Mozilla

clippy Install clippy, Rust code linter
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
prefix Defines if a Gentoo Prefix offset installation is used
rls Install rls, Rust Language Server (used with IDEs supporting RLS protocol)
rust-src Install rust-src, needed by developer tools and for build-std (cross)
rustfmt Install rustfmt, Rust code formatter
verify-sig Verify upstream signatures on distfiles

Emerge

Emerge the package base

root #emerge --ask dev-lang/rust

There's also an binary package provided due to the long compile times.

root #emerge --ask dev-lang/rust-bin

Distcc MAKEOPTS

Rust does not support distcc compiling and may require local package.env defined to avoid excessive IO consumption when building on distcc tuned hosts. (i.e. MAKEOPTS="-j30 -l4", 30 is greater than 4 local CPU cores )

--local-load is not honored, so an appropriate --jobs value in relation to the locally available build resources must be passed:

FILE /etc/portage/env/nodistcc-makeopts.conf
MAKEOPTS="-jN"
FILE /etc/portage/package.env/rust
dev-lang/rust nodistcc-makeopts.conf

Configuration

Eselect Rust

There is an eselect available to switch between different Rust slots. Usage in the usual way, get a numbered list of installed Rust versions with:

user $eselect rust list

Set the version of rust with the number x via:

user $eselect rust set x

Usage

Development

While the purpose of Gentoo's Rust package is mainly to provide a build environment to emerge other packages that use Rust, it is still possible to develop in Rust with this package. The Rust compiler, rustc, is installed and available as soon as the package is emerged. However, there are certain other things to consider when developing in Rust. In a generic installation of Rust (one that is not done with Gentoo's Rust package) things are usually updated and installed with Rustup. This will not work with the Rust toolchain that is installed with Gentoo. Instead additional Rust things that would be installed by Rustup are installed via USE flags of the dev-lang/rust package.

An other way is to install another Rust for development separately with the instructions from the Rust documentation. Additionally there is the Gentoo Rust overlay with further packages for development and software written in Rust.

Language servers

For code autocompletion and highlighting, two language servers are available in the Rust universe: Rust-analyzer and and the Rust Language Server.

Rls comes with the Rust package when the USE flag rls is enabled. Rust-analyzer is a separate package. Rust-analyzer can be installed from the GURU overlay as a package or from Gentoo's Rust overlay as a USE flag of their dev-lang/rust package.

In order for the language server to autosuggest code from the Rust standard library emerge dev-lang/rust with the rust-src USE flag.

Code formatting

Rust comes with its own built in code formatter. Emerge rust with USE flag rustfmt to use it. Code formatting is invoked in a project directory with cargo fmt

Code linting

Rust also comes with a officially supported code linter called clippy. In order to use it with Gentoo's dev-lang/rust package, emerge it with the clippy USE flag.