@@ -5,17 +5,93 @@ Quick Start
55
66This 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
990Requirements: Building
1091----------------------
1192
1293This 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-
1995To easily check whether the requirements are met, the following target
2096can be used::
2197
@@ -29,16 +105,15 @@ if that is the case.
29105rustc
30106*****
31107
32- A particular version of the Rust compiler is required. Newer versions may or
33- may not work because, for the moment, the kernel depends on some unstable
34- Rust features.
108+ A recent version of the Rust compiler is required.
35109
36110If ``rustup `` is being used, enter the kernel build directory (or use
37- ``--path=<build-dir> `` argument to the ``set `` sub-command) and run::
111+ ``--path=<build-dir> `` argument to the ``set `` sub-command) and run,
112+ for instance::
38113
39- rustup override set $(scripts/min-tool-version.sh rustc)
114+ rustup override set stable
40115
41- This will configure your working directory to use the correct version of
116+ This will configure your working directory to use the given version of
42117``rustc `` without affecting your default toolchain.
43118
44119Note that the override applies to the current working directory (and its
@@ -65,9 +140,9 @@ version later on requires re-adding the component.
65140Otherwise, if a standalone installer is used, the Rust source tree may be
66141downloaded into the toolchain's installation folder::
67142
68- curl -L "https://static.rust-lang.org/dist/rust-src-$(scripts/min-tool -version.sh rustc ).tar.gz" |
143+ curl -L "https://static.rust-lang.org/dist/rust-src-$(rustc - -version | cut -d' ' -f2 ).tar.gz" |
69144 tar -xzf - -C "$(rustc --print sysroot)/lib" \
70- "rust-src-$(scripts/min-tool -version.sh rustc )/rust-src/lib/" \
145+ "rust-src-$(rustc - -version | cut -d' ' -f2 )/rust-src/lib/" \
71146 --strip-components=3
72147
73148In this case, upgrading the Rust compiler version later on requires manually
@@ -101,26 +176,22 @@ bindgen
101176*******
102177
103178The bindings to the C side of the kernel are generated at build time using
104- the ``bindgen `` tool. A particular version is required.
179+ the ``bindgen `` tool.
105180
106- Install it via (note that this will download and build the tool from source)::
181+ Install it, for instance, via (note that this will download and build the tool
182+ from source)::
107183
108- cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen-cli
184+ cargo install --locked bindgen-cli
109185
110- ``bindgen `` needs to find a suitable ``libclang `` in order to work. If it is
111- not found (or a different ``libclang `` than the one found should be used),
112- the process can be tweaked using the environment variables understood by
113- ``clang-sys `` (the Rust bindings crate that ``bindgen `` uses to access
114- ``libclang ``):
186+ ``bindgen `` uses the ``clang-sys `` crate to find a suitable ``libclang `` (which
187+ may be linked statically, dynamically or loaded at runtime). By default, the
188+ ``cargo `` command above will produce a ``bindgen `` binary that will load
189+ ``libclang `` at runtime. If it is not found (or a different ``libclang `` than
190+ the one found should be used), the process can be tweaked, e.g. by using the
191+ ``LIBCLANG_PATH `` environment variable. For details, please see ``clang-sys ``'s
192+ documentation at:
115193
116- * ``LLVM_CONFIG_PATH `` can be pointed to an ``llvm-config `` executable.
117-
118- * Or ``LIBCLANG_PATH `` can be pointed to a ``libclang `` shared library
119- or to the directory containing it.
120-
121- * Or ``CLANG_PATH `` can be pointed to a ``clang `` executable.
122-
123- For details, please see ``clang-sys ``'s documentation at:
194+ https://github.com/KyleMayes/clang-sys#linking
124195
125196 https://github.com/KyleMayes/clang-sys#environment-variables
126197
@@ -164,20 +235,6 @@ can be installed manually::
164235The standalone installers also come with ``clippy ``.
165236
166237
167- cargo
168- *****
169-
170- ``cargo `` is the Rust native build system. It is currently required to run
171- the tests since it is used to build a custom standard library that contains
172- the facilities provided by the custom ``alloc `` in the kernel. The tests can
173- be run using the ``rusttest `` Make target.
174-
175- If ``rustup `` is being used, all the profiles already install the tool,
176- thus nothing needs to be done.
177-
178- The standalone installers also come with ``cargo ``.
179-
180-
181238rustdoc
182239*******
183240
0 commit comments