Psphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget$/translations/zh_CN/rust/quick-startmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/zh_TW/rust/quick-startmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/it_IT/rust/quick-startmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ja_JP/rust/quick-startmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ko_KR/rust/quick-startmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/pt_BR/rust/quick-startmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/sp_SP/rust/quick-startmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh>/var/lib/git/docbuild/linux/Documentation/rust/quick-start.rsthKubhsection)}(hhh](htitle)}(h Quick Starth]h Quick Start}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hKThis document describes how to get started with kernel development in Rust.h]hKThis document describes how to get started with kernel development in Rust.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXGThere are a few ways to install a Rust toolchain needed for kernel development. A simple way is to use the packages from your Linux distribution if they are suitable -- the first section below explains this approach. An advantage of this approach is that, typically, the distribution will match the LLVM used by Rust and Clang.h]hXGThere are a few ways to install a Rust toolchain needed for kernel development. A simple way is to use the packages from your Linux distribution if they are suitable -- the first section below explains this approach. An advantage of this approach is that, typically, the distribution will match the LLVM used by Rust and Clang.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXAnother way is using the prebuilt stable versions of LLVM+Rust provided on `kernel.org `_. These are the same slim and fast LLVM toolchains from :ref:`Getting LLVM ` with versions of Rust added to them that Rust for Linux supports. Two sets are provided: the "latest LLVM" and "matching LLVM" (please see the link for more information).h](hKAnother way is using the prebuilt stable versions of LLVM+Rust provided on }(hhhhhNhNubh reference)}(h7`kernel.org `_h]h kernel.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]name kernel.orgrefuri'https://kernel.org/pub/tools/llvm/rust/uh1jhhubhtarget)}(h* h]h}(h] kernel-orgah ]h"] kernel.orgah$]h&]refurijuh1j referencedKhhubh8. These are the same slim and fast LLVM toolchains from }(hhhhhNhNubh)}(h":ref:`Getting LLVM `h]hinline)}(hj-h]h Getting LLVM}(hj1hhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1j/hj+ubah}(h]h ]h"]h$]h&]refdocrust/quick-start refdomainj<reftyperef refexplicitrefwarn reftarget getting_llvmuh1hhhhKhhubh with versions of Rust added to them that Rust for Linux supports. Two sets are provided: the “latest LLVM” and “matching LLVM” (please see the link for more information).}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hAlternatively, the next two "Requirements" sections explain each component and how to install them through ``rustup``, the standalone installers from Rust and/or building them.h](hoAlternatively, the next two “Requirements” sections explain each component and how to install them through }(hjZhhhNhNubhliteral)}(h ``rustup``h]hrustup}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjZubh;, the standalone installers from Rust and/or building them.}(hjZhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hFThe rest of the document explains other aspects on how to get started.h]hFThe rest of the document explains other aspects on how to get started.}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(h Distributionsh]h Distributions}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h Arch Linuxh]h Arch Linux}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(haArch Linux provides recent Rust releases and thus it should generally work out of the box, e.g.::h]h`Arch Linux provides recent Rust releases and thus it should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hjhhubh literal_block)}(h$pacman -S rust rust-src rust-bindgenh]h$pacman -S rust rust-src rust-bindgen}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK$hjhhubeh}(h] arch-linuxah ]h"] arch linuxah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hDebianh]hDebian}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK(ubh)}(hDebian 13 (Trixie), as well as Testing and Debian Unstable (Sid) provide recent Rust releases and thus they should generally work out of the box, e.g.::h]hDebian 13 (Trixie), as well as Testing and Debian Unstable (Sid) provide recent Rust releases and thus they should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK*hjhhubj)}(h6apt install rustc rust-src bindgen rustfmt rust-clippyh]h6apt install rustc rust-src bindgen rustfmt rust-clippy}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK-hjhhubeh}(h]debianah ]h"]debianah$]h&]uh1hhjhhhhhK(ubh)}(hhh](h)}(h Fedora Linuxh]h Fedora Linux}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK1ubh)}(hcFedora Linux provides recent Rust releases and thus it should generally work out of the box, e.g.::h]hbFedora Linux provides recent Rust releases and thus it should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK3hjhhubj)}(h4dnf install rust rust-src bindgen-cli rustfmt clippyh]h4dnf install rust rust-src bindgen-cli rustfmt clippy}hj&sbah}(h]h ]h"]h$]h&]hhuh1jhhhK6hjhhubeh}(h] fedora-linuxah ]h"] fedora linuxah$]h&]uh1hhjhhhhhK1ubh)}(hhh](h)}(h Gentoo Linuxh]h Gentoo Linux}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj<hhhhhK:ubh)}(hcGentoo Linux provides recent Rust releases and thus it should generally work out of the box, e.g.::h]hbGentoo Linux provides recent Rust releases and thus it should generally work out of the box, e.g.:}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK {} }: pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc rust-bindgen rustfmt clippy ]; RUST_LIB_SRC = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }h]h{ pkgs ? import {} }: pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc rust-bindgen rustfmt clippy ]; RUST_LIB_SRC = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKJhjhhubeh}(h]nixah ]h"]nixah$]h&]uh1hhjhhhhhKEubh)}(hhh](h)}(hopenSUSEh]hopenSUSE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKRubh)}(hopenSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus they should generally work out of the box, e.g.::h]hopenSUSE Slowroll and openSUSE Tumbleweed provide recent Rust releases and thus they should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjhhubj)}(h/zypper install rust rust-src rust-bindgen clangh]h/zypper install rust rust-src rust-bindgen clang}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKWhjhhubeh}(h]opensuseah ]h"]opensuseah$]h&]uh1hhjhhhhhKRubh)}(hhh](h)}(hUbuntuh]hUbuntu}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK[ubh)}(hrUbuntu 25.10 and 26.04 LTS provide recent Rust releases and thus they should generally work out of the box, e.g.::h]hqUbuntu 25.10 and 26.04 LTS provide recent Rust releases and thus they should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hjhhubj)}(h6apt install rustc rust-src bindgen rustfmt rust-clippyh]h6apt install rustc rust-src bindgen rustfmt rust-clippy}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK`hjhhubh)}(h5In addition, ``RUST_LIB_SRC`` needs to be set, e.g.::h](h In addition, }(hj$hhhNhNubjc)}(h``RUST_LIB_SRC``h]h RUST_LIB_SRC}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj$ubh needs to be set, e.g.:}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKbhjhhubj)}(hFRUST_LIB_SRC=/usr/src/rustc-$(rustc --version | cut -d' ' -f2)/libraryh]hFRUST_LIB_SRC=/usr/src/rustc-$(rustc --version | cut -d' ' -f2)/library}hjDsbah}(h]h ]h"]h$]h&]hhuh1jhhhKdhjhhubh)}(hLFor convenience, ``RUST_LIB_SRC`` can be exported to the global environment.h](hFor convenience, }(hjRhhhNhNubjc)}(h``RUST_LIB_SRC``h]h RUST_LIB_SRC}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjRubh+ can be exported to the global environment.}(hjRhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKfhjhhubh)}(hhh](h)}(h24.04 LTS and olderh]h24.04 LTS and older}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjrhhhhhKjubh)}(hThough Ubuntu 24.04 LTS and older versions still provide recent Rust releases, they require some additional configuration to be set, using the versioned packages, e.g.::h]hThough Ubuntu 24.04 LTS and older versions still provide recent Rust releases, they require some additional configuration to be set, using the versioned packages, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKlhjrhhubj)}(hapt install rustc-1.85 rust-1.85-src bindgen-0.71 rustfmt-1.85 \ rust-1.85-clippy ln -s /usr/lib/rust-1.85/bin/rustfmt /usr/bin/rustfmt-1.85 ln -s /usr/lib/rust-1.85/bin/clippy-driver /usr/bin/clippy-driver-1.85h]hapt install rustc-1.85 rust-1.85-src bindgen-0.71 rustfmt-1.85 \ rust-1.85-clippy ln -s /usr/lib/rust-1.85/bin/rustfmt /usr/bin/rustfmt-1.85 ln -s /usr/lib/rust-1.85/bin/clippy-driver /usr/bin/clippy-driver-1.85}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKphjrhhubh)}(hiNone of these packages set their tools as defaults; therefore they should be specified explicitly, e.g.::h]hhNone of these packages set their tools as defaults; therefore they should be specified explicitly, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjrhhubj)}(hmake LLVM=1 RUSTC=rustc-1.85 RUSTDOC=rustdoc-1.85 RUSTFMT=rustfmt-1.85 \ CLIPPY_DRIVER=clippy-driver-1.85 BINDGEN=bindgen-0.71h]hmake LLVM=1 RUSTC=rustc-1.85 RUSTDOC=rustdoc-1.85 RUSTFMT=rustfmt-1.85 \ CLIPPY_DRIVER=clippy-driver-1.85 BINDGEN=bindgen-0.71}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKxhjrhhubh)}(h|Alternatively, modify the ``PATH`` variable to place the Rust 1.85 binaries first and set ``bindgen`` as the default, e.g.::h](hAlternatively, modify the }(hjhhhNhNubjc)}(h``PATH``h]hPATH}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh8 variable to place the Rust 1.85 binaries first and set }(hjhhhNhNubjc)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh as the default, e.g.:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK{hjrhhubj)}(hPATH=/usr/lib/rust-1.85/bin:$PATH update-alternatives --install /usr/bin/bindgen bindgen \ /usr/bin/bindgen-0.71 100 update-alternatives --set bindgen /usr/bin/bindgen-0.71h]hPATH=/usr/lib/rust-1.85/bin:$PATH update-alternatives --install /usr/bin/bindgen bindgen \ /usr/bin/bindgen-0.71 100 update-alternatives --set bindgen /usr/bin/bindgen-0.71}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK~hjrhhubh)}(hM``RUST_LIB_SRC`` may need to be set when using the versioned packages, e.g.::h](jc)}(h``RUST_LIB_SRC``h]h RUST_LIB_SRC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh< may need to be set when using the versioned packages, e.g.:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjrhhubj)}(hKRUST_LIB_SRC=/usr/src/rustc-$(rustc-1.85 --version | cut -d' ' -f2)/libraryh]hKRUST_LIB_SRC=/usr/src/rustc-$(rustc-1.85 --version | cut -d' ' -f2)/library}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjrhhubh)}(hLFor convenience, ``RUST_LIB_SRC`` can be exported to the global environment.h](hFor convenience, }(hj%hhhNhNubjc)}(h``RUST_LIB_SRC``h]h RUST_LIB_SRC}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj%ubh+ can be exported to the global environment.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjrhhubh)}(hIn addition, ``bindgen-0.71`` is available in newer releases (24.04 LTS), but it may not be available in older ones (20.04 LTS and 22.04 LTS), thus ``bindgen`` may need to be built manually (please see below).h](h In addition, }(hjEhhhNhNubjc)}(h``bindgen-0.71``h]h bindgen-0.71}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjEubhw is available in newer releases (24.04 LTS), but it may not be available in older ones (20.04 LTS and 22.04 LTS), thus }(hjEhhhNhNubjc)}(h ``bindgen``h]hbindgen}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjEubh2 may need to be built manually (please see below).}(hjEhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjrhhubeh}(h] lts-and-olderah ]h"]24.04 lts and olderah$]h&]uh1hhjhhhhhKjubeh}(h]ubuntuah ]h"]ubuntuah$]h&]uh1hhjhhhhhK[ubeh}(h] distributionsah ]h"] distributionsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hRequirements: Buildingh]hRequirements: Building}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hAThis section explains how to fetch the tools needed for building.h]hAThis section explains how to fetch the tools needed for building.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hTTo easily check whether the requirements are met, the following target can be used::h]hSTo easily check whether the requirements are met, the following target can be used:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hmake LLVM=1 rustavailableh]hmake LLVM=1 rustavailable}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hThis triggers the same logic used by Kconfig to determine whether ``RUST_IS_AVAILABLE`` should be enabled; but it also explains why not if that is the case.h](hBThis triggers the same logic used by Kconfig to determine whether }(hjhhhNhNubjc)}(h``RUST_IS_AVAILABLE``h]hRUST_IS_AVAILABLE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubhE should be enabled; but it also explains why not if that is the case.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hhh](h)}(hrustch]hrustc}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h2A recent version of the Rust compiler is required.h]h2A recent version of the Rust compiler is required.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hIf ``rustup`` is being used, enter the kernel build directory (or use ``--path=`` argument to the ``set`` sub-command) and run, for instance::h](hIf }(hj hhhNhNubjc)}(h ``rustup``h]hrustup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh9 is being used, enter the kernel build directory (or use }(hj hhhNhNubjc)}(h``--path=``h]h--path=}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh argument to the }(hj hhhNhNubjc)}(h``set``h]hset}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh$ sub-command) and run, for instance:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hrustup override set stableh]hrustup override set stable}hjMsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hzThis will configure your working directory to use the given version of ``rustc`` without affecting your default toolchain.h](hGThis will configure your working directory to use the given version of }(hj[hhhNhNubjc)}(h ``rustc``h]hrustc}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj[ubh* without affecting your default toolchain.}(hj[hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hZNote that the override applies to the current working directory (and its sub-directories).h]hZNote that the override applies to the current working directory (and its sub-directories).}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hCIf you are not using ``rustup``, fetch a standalone installer from:h](hIf you are not using }(hjhhhNhNubjc)}(h ``rustup``h]hrustup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh$, fetch a standalone installer from:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh block_quote)}(hNhttps://forge.rust-lang.org/infra/other-installation-methods.html#standalone h]h)}(hLhttps://forge.rust-lang.org/infra/other-installation-methods.html#standaloneh]j)}(hjh]hLhttps://forge.rust-lang.org/infra/other-installation-methods.html#standalone}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubeh}(h]rustcah ]h"]rustcah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hRust standard library sourceh]hRust standard library source}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hbThe Rust standard library source is required because the build system will cross-compile ``core``.h](hYThe Rust standard library source is required because the build system will cross-compile }(hjhhhNhNubjc)}(h``core``h]hcore}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h"If ``rustup`` is being used, run::h](hIf }(hjhhhNhNubjc)}(h ``rustup``h]hrustup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh is being used, run:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hrustup component add rust-srch]hrustup component add rust-src}hj&sbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hThe components are installed per toolchain, thus upgrading the Rust compiler version later on requires re-adding the component.h]hThe components are installed per toolchain, thus upgrading the Rust compiler version later on requires re-adding the component.}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hOtherwise, if a standalone installer is used, the Rust source tree may be downloaded into the toolchain's installation folder::h]hOtherwise, if a standalone installer is used, the Rust source tree may be downloaded into the toolchain’s installation folder:}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hcurl -L "https://static.rust-lang.org/dist/rust-src-$(rustc --version | cut -d' ' -f2).tar.gz" | tar -xzf - -C "$(rustc --print sysroot)/lib" \ "rust-src-$(rustc --version | cut -d' ' -f2)/rust-src/lib/" \ --strip-components=3h]hcurl -L "https://static.rust-lang.org/dist/rust-src-$(rustc --version | cut -d' ' -f2).tar.gz" | tar -xzf - -C "$(rustc --print sysroot)/lib" \ "rust-src-$(rustc --version | cut -d' ' -f2)/rust-src/lib/" \ --strip-components=3}hjPsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hIn this case, upgrading the Rust compiler version later on requires manually updating the source tree (this can be done by removing ``$(rustc --print sysroot)/lib/rustlib/src/rust`` then rerunning the above command).h](hIn this case, upgrading the Rust compiler version later on requires manually updating the source tree (this can be done by removing }(hj^hhhNhNubjc)}(h1``$(rustc --print sysroot)/lib/rustlib/src/rust``h]h-$(rustc --print sysroot)/lib/rustlib/src/rust}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj^ubh# then rerunning the above command).}(hj^hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]rust-standard-library-sourceah ]h"]rust standard library sourceah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hlibclangh]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(h``libclang`` (part of LLVM) is used by ``bindgen`` to understand the C code in the kernel, which means LLVM needs to be installed; like when the kernel is compiled with ``LLVM=1``.h](jc)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh (part of LLVM) is used by }(hjhhhNhNubjc)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubhw to understand the C code in the kernel, which means LLVM needs to be installed; like when the kernel is compiled with }(hjhhhNhNubjc)}(h ``LLVM=1``h]hLLVM=1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hcLinux distributions are likely to have a suitable one available, so it is best to check that first.h]hcLinux distributions are likely to have a suitable one available, so it is best to check that first.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hOThere are also some binaries for several systems and architectures uploaded at:h]hOThere are also some binaries for several systems and architectures uploaded at:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h(https://releases.llvm.org/download.html h]h)}(h'https://releases.llvm.org/download.htmlh]j)}(hjh]h'https://releases.llvm.org/download.html}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hNOtherwise, building LLVM takes quite a while, but it is not a complex process:h]hNOtherwise, building LLVM takes quite a while, but it is not a complex process:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hThttps://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm h]h)}(hShttps://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvmh]j)}(hj)h]hShttps://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm}(hj+hhhNhNubah}(h]h ]h"]h$]h&]refurij)uh1jhj'ubah}(h]h ]h"]h$]h&]uh1hhhhKhj#ubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hPlease see Documentation/kbuild/llvm.rst for more information and further ways to fetch pre-built releases and distribution packages.h]hPlease see Documentation/kbuild/llvm.rst for more information and further ways to fetch pre-built releases and distribution packages.}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]libclangah ]h"]libclangah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(hbindgenh]hbindgen}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj[hhhhhKubh)}(h`The bindings to the C side of the kernel are generated at build time using the ``bindgen`` tool.h](hOThe bindings to the C side of the kernel are generated at build time using the }(hjlhhhNhNubjc)}(h ``bindgen``h]hbindgen}(hjthhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjlubh tool.}(hjlhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[hhubh)}(h]Install it, for instance, via (note that this will download and build the tool from source)::h]h\Install it, for instance, via (note that this will download and build the tool from source):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj[hhubj)}(h"cargo install --locked bindgen-clih]h"cargo install --locked bindgen-cli}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhj[hhubh)}(hX``bindgen`` uses the ``clang-sys`` crate to find a suitable ``libclang`` (which may be linked statically, dynamically or loaded at runtime). By default, the ``cargo`` command above will produce a ``bindgen`` binary that will load ``libclang`` at runtime. If it is not found (or a different ``libclang`` than the one found should be used), the process can be tweaked, e.g. by using the ``LIBCLANG_PATH`` environment variable. For details, please see ``clang-sys``'s documentation at:h](jc)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh uses the }(hjhhhNhNubjc)}(h ``clang-sys``h]h clang-sys}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh crate to find a suitable }(hjhhhNhNubjc)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubhU (which may be linked statically, dynamically or loaded at runtime). By default, the }(hjhhhNhNubjc)}(h ``cargo``h]hcargo}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh command above will produce a }(hjhhhNhNubjc)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh binary that will load }(hjhhhNhNubjc)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh0 at runtime. If it is not found (or a different }(hjhhhNhNubjc)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubhS than the one found should be used), the process can be tweaked, e.g. by using the }(hjhhhNhNubjc)}(h``LIBCLANG_PATH``h]h LIBCLANG_PATH}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh/ environment variable. For details, please see }(hjhhhNhNubjc)}(h ``clang-sys``h]h clang-sys}(hj<hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhjubh’s documentation at:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj[hhubj)}(hnhttps://github.com/KyleMayes/clang-sys#linking https://github.com/KyleMayes/clang-sys#environment-variables h](h)}(h.https://github.com/KyleMayes/clang-sys#linkingh]j)}(hjZh]h.https://github.com/KyleMayes/clang-sys#linking}(hj\hhhNhNubah}(h]h ]h"]h$]h&]refurijZuh1jhjXubah}(h]h ]h"]h$]h&]uh1hhhhKhjTubh)}(h`_ language server can be used with many editors to enable syntax highlighting, completion, go to definition, and other features.h](hThe }(hj hhhNhNubj)}(h3`rust-analyzer `_h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]name rust-analyzerj https://rust-analyzer.github.io/uh1jhj ubj)}(h# h]h}(h]id1ah ]h"] rust-analyzerah$]h&]refurij uh1jj&Khj ubh language server can be used with many editors to enable syntax highlighting, completion, go to definition, and other features.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj hhubh)}(h``rust-analyzer`` needs a configuration file, ``rust-project.json``, which can be generated by the ``rust-analyzer`` Make target::h](jc)}(h``rust-analyzer``h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh needs a configuration file, }(hj hhhNhNubjc)}(h``rust-project.json``h]hrust-project.json}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh , which can be generated by the }(hj hhhNhNubjc)}(h``rust-analyzer``h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj ubh Make target:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM:hj hhubj)}(hmake LLVM=1 rust-analyzerh]hmake LLVM=1 rust-analyzer}hj3 sbah}(h]h ]h"]h$]h&]hhuh1jhhhM=hj hhubeh}(h] rust-analyzerah ]h"]h$]j ah&]uh1hhjhhhhhM4j&Kubeh}(h]requirements-developingah ]h"]requirements: developingah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Configurationh]h Configuration}(hjS hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjP hhhhhMAubh)}(hX``Rust support`` (``CONFIG_RUST``) needs to be enabled in the ``General setup`` menu. The option is only shown if a suitable Rust toolchain is found (see above), as long as the other requirements are met. In turn, this will make visible the rest of options that depend on Rust.h](jc)}(h``Rust support``h]h Rust support}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhja ubh (}(hja hhhNhNubjc)}(h``CONFIG_RUST``h]h CONFIG_RUST}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhja ubh) needs to be enabled in the }(hja hhhNhNubjc)}(h``General setup``h]h General setup}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhja ubh menu. The option is only shown if a suitable Rust toolchain is found (see above), as long as the other requirements are met. In turn, this will make visible the rest of options that depend on Rust.}(hja hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMChjP hhubh)}(hAfterwards, go to::h]hAfterwards, go to:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMHhjP hhubj)}(h@Kernel hacking -> Sample kernel code -> Rust samplesh]h@Kernel hacking -> Sample kernel code -> Rust samples}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMJhjP hhubh)}(hAAnd enable some sample modules either as built-in or as loadable.h]hAAnd enable some sample modules either as built-in or as loadable.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMNhjP hhubeh}(h] configurationah ]h"] configurationah$]h&]uh1hhhhhhhhMAubh)}(hhh](h)}(hBuildingh]hBuilding}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMRubh)}(heBuilding a kernel with a complete LLVM toolchain is the best supported setup at the moment. That is::h]hdBuilding a kernel with a complete LLVM toolchain is the best supported setup at the moment. That is:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMThj hhubj)}(h make LLVM=1h]h make LLVM=1}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMWhj hhubh)}(hXUsing GCC also works for some configurations, but it is very experimental at the moment.h]hXUsing GCC also works for some configurations, but it is very experimental at the moment.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhj hhubeh}(h]buildingah ]h"]buildingah$]h&]uh1hhhhhhhhMRubh)}(hhh](h)}(hHackingh]hHacking}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhM^ubh)}(hTo dive deeper, take a look at the source code of the samples at ``samples/rust/``, the Rust support code under ``rust/`` and the ``Rust hacking`` menu under ``Kernel hacking``.h](hATo dive deeper, take a look at the source code of the samples at }(hj' hhhNhNubjc)}(h``samples/rust/``h]h samples/rust/}(hj/ hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj' ubh, the Rust support code under }(hj' hhhNhNubjc)}(h ``rust/``h]hrust/}(hjA hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj' ubh and the }(hj' hhhNhNubjc)}(h``Rust hacking``h]h Rust hacking}(hjS hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj' ubh menu under }(hj' hhhNhNubjc)}(h``Kernel hacking``h]hKernel hacking}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1jbhj' ubh.}(hj' hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM`hj hhubeh}(h]hackingah ]h"]hackingah$]h&]uh1hhhhhhhhM^ubeh}(h] quick-startah ]h"] quick startah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j j j"jjjjjjjj9j6jjjjjjjjj|jyjjjjjjjXjUjjjM jJ jS jP j j j j rust-analyzerj j j j j j j u nametypes}(j j"jjjj9jjjjj|jjjjXjjM jS j j j j j j uh}(j hjjjjjjjjj6jjj<jjjjjjjyjrjjjjjjjUjjj[jJ jjP jj jV j j jC j j j j jP j j j j u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}j KsRparse_messages]hsystem_message)}(hhh]h)}(h0Duplicate implicit target name: "rust-analyzer".h]h4Duplicate implicit target name: “rust-analyzer”.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]j alevelKtypeINFOsourcehnjlineKuh1j hj hhhhhM8ubatransform_messages] transformerN include_log] decorationNhhub.