Skip to content

Commit b126341

Browse files
committed
docs: rust: quick-start: add section on Linux distributions
Now that we are starting to support several Rust compiler and `bindgen` versions, there is a good chance some Linux distributions work out of the box. Thus, provide some instructions on how to set the toolchain up for a few major Linux distributions. This simplifies the setup users need to build the kernel. In addition, add an introduction to the document so that it is easier to understand its structure and move the LLVM+Rust kernel.org toolchains paragraph there (removing "depending on the Linux version"). We may want to reorganize the document or split it in the future, but I wanted to focus this commit on the new information added about each particular distribution. Finally, remove the `rustup`'s components mention in `changes.rst` since users do not need it if they install the toolchain via the distributions (and anyway it was too detailed for that main document). Cc: Jan Alexander Steffens <heftig@archlinux.org> Cc: Johannes Löthberg <johannes@kyriasis.com> Cc: Fabian Grünbichler <debian@fabian.gruenbichler.email> Cc: Josh Stone <jistone@redhat.com> Cc: Randy Barlow <randy@electronsweatshop.com> Cc: Anna (navi) Figueiredo Gomes <navi@vlhl.dev> Cc: Matoro Mahri <matoro_gentoo@matoro.tk> Cc: Ryan Scheel <ryan.havvy@gmail.com> Cc: figsoda <figsoda@pm.me> Cc: Jörg Thalheim <joerg@thalheim.io> Cc: Theodore Ni <43ngvg@masqt.com> Cc: Winter <nixos@winter.cafe> Cc: William Brown <wbrown@suse.de> Cc: Xiaoguang Wang <xiaoguang.wang@suse.com> Cc: Andrea Righi <andrea.righi@canonical.com> Cc: Zixing Liu <zixing.liu@canonical.com> Cc: Nathan Chancellor <nathan@kernel.org> Tested-by: Benno Lossin <benno.lossin@proton.me> Tested-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20240709160615.998336-14-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 981ad93 commit b126341

File tree

2 files changed

+81
-17
lines changed

2 files changed

+81
-17
lines changed

Documentation/process/changes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ Rust (optional)
9090

9191
A recent version of the Rust compiler is required.
9292

93-
Each Rust toolchain comes with several "components", some of which are required
94-
(like ``rustc``) and some that are optional. The ``rust-src`` component (which
95-
is optional) needs to be installed to build the kernel. Other components are
96-
useful for developing.
97-
9893
Please see Documentation/rust/quick-start.rst for instructions on how to
9994
satisfy the build requirements of Rust support. In particular, the ``Makefile``
10095
target ``rustavailable`` is useful to check why the Rust toolchain may not

Documentation/rust/quick-start.rst

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,93 @@ Quick Start
55

66
This document describes how to get started with kernel development in Rust.
77

8+
There are a few ways to install a Rust toolchain needed for kernel development.
9+
A simple way is to use the packages from your Linux distribution if they are
10+
suitable -- the first section below explains this approach. An advantage of this
11+
approach is that, typically, the distribution will match the LLVM used by Rust
12+
and Clang.
13+
14+
Another way is using the prebuilt stable versions of LLVM+Rust provided on
15+
`kernel.org <https://kernel.org/pub/tools/llvm/rust/>`_. These are the same slim
16+
and fast LLVM toolchains from :ref:`Getting LLVM <getting_llvm>` with versions
17+
of Rust added to them that Rust for Linux supports. Two sets are provided: the
18+
"latest LLVM" and "matching LLVM" (please see the link for more information).
19+
20+
Alternatively, the next two "Requirements" sections explain each component and
21+
how to install them through ``rustup``, the standalone installers from Rust
22+
and/or building them.
23+
24+
The rest of the document explains other aspects on how to get started.
25+
26+
27+
Distributions
28+
-------------
29+
30+
Arch Linux
31+
**********
32+
33+
Arch Linux provides recent Rust releases and thus it should generally work out
34+
of the box, e.g.::
35+
36+
pacman -S rust rust-src rust-bindgen
37+
38+
39+
Debian
40+
******
41+
42+
Debian Unstable (Sid), outside of the freeze period, provides recent Rust
43+
releases and thus it should generally work out of the box, e.g.::
44+
45+
apt install rustc rust-src bindgen rustfmt rust-clippy
46+
47+
48+
Fedora Linux
49+
************
50+
51+
Fedora Linux provides recent Rust releases and thus it should generally work out
52+
of the box, e.g.::
53+
54+
dnf install rust rust-src bindgen-cli rustfmt clippy
55+
56+
57+
Gentoo Linux
58+
************
59+
60+
Gentoo Linux (and especially the testing branch) provides recent Rust releases
61+
and thus it should generally work out of the box, e.g.::
62+
63+
USE='rust-src rustfmt clippy' emerge dev-lang/rust dev-util/bindgen
64+
65+
``LIBCLANG_PATH`` may need to be set.
66+
67+
68+
Nix
69+
***
70+
71+
Nix (unstable channel) provides recent Rust releases and thus it should
72+
generally work out of the box, e.g.::
73+
74+
{ pkgs ? import <nixpkgs> {} }:
75+
pkgs.mkShell {
76+
nativeBuildInputs = with pkgs; [ rustc rust-bindgen rustfmt clippy ];
77+
RUST_LIB_SRC = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
78+
}
79+
80+
81+
openSUSE
82+
********
83+
84+
openSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus
85+
they should generally work out of the box, e.g.::
86+
87+
zypper install rust rust1.79-src rust-bindgen clang
88+
889

990
Requirements: Building
1091
----------------------
1192

1293
This section explains how to fetch the tools needed for building.
1394

14-
Some of these requirements might be available from Linux distributions
15-
under names like ``rustc``, ``rust-src``, ``rust-bindgen``, etc. However,
16-
at the time of writing, they are likely not to be recent enough unless
17-
the distribution tracks the latest releases.
18-
19-
Prebuilt stable versions of LLVM+Rust are provided on `kernel.org
20-
<https://kernel.org/pub/tools/llvm/rust/>`_. These are the same slim and fast
21-
LLVM toolchains from :ref:`Getting LLVM <getting_llvm>` with versions of Rust
22-
added to them that Rust for Linux supports, depending on the Linux version. Two
23-
sets are provided: the "latest LLVM" and "matching LLVM" (please see the link
24-
for more information).
25-
2695
To easily check whether the requirements are met, the following target
2796
can be used::
2897

0 commit comments

Comments
 (0)