sphinx.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]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}(hhhhhNhNubah}(h]h ]h"]h$]h&]name kernel.orgrefuri'https://kernel.org/pub/tools/llvm/rust/uh1hhhubhtarget)}(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)}(hjh]h Getting LLVM}(hjhhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1jhjubah}(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 }(hjFhhhNhNubhliteral)}(h ``rustup``h]hrustup}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjFubh;, the standalone installers from Rust and/or building them.}(hjFhhhNhNubeh}(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.}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(h Distributionsh]h Distributions}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjvhhhhhKubh)}(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&]uh1hhjvhhhhhKubh)}(hhh](h)}(hDebianh]hDebian}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK(ubh)}(hDebian Testing and Debian Unstable (Sid), outside of the freeze period, provide recent Rust releases and thus they should generally work out of the box, e.g.::h]hDebian Testing and Debian Unstable (Sid), outside of the freeze period, 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&]uh1hhjvhhhhhK(ubh)}(hhh](h)}(h Fedora Linuxh]h Fedora Linux}(hjhhhNhNubah}(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}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK6hjhhubeh}(h] fedora-linuxah ]h"] fedora linuxah$]h&]uh1hhjvhhhhhK1ubh)}(hhh](h)}(h Gentoo Linuxh]h Gentoo Linux}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj(hhhhhK:ubh)}(hGentoo Linux (and especially the testing branch) provides recent Rust releases and thus it should generally work out of the box, e.g.::h]hGentoo Linux (and especially the testing branch) provides recent Rust releases and thus it should generally work out of the box, e.g.:}(hj9hhhNhNubah}(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&]hhuh1jhhhKJhjyhhubeh}(h]nixah ]h"]nixah$]h&]uh1hhjvhhhhhKEubh)}(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)}(h3zypper install rust rust1.79-src rust-bindgen clangh]h3zypper install rust rust1.79-src rust-bindgen clang}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKWhjhhubeh}(h]opensuseah ]h"]opensuseah$]h&]uh1hhjvhhhhhKRubh)}(hhh](h)}(hUbuntuh]hUbuntu}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK[ubh)}(hUbuntu LTS and non-LTS (interim) releases provide recent Rust releases and thus they should generally work out of the box, e.g.::h]hUbuntu LTS and non-LTS (interim) releases provide recent Rust releases and thus they should generally work out of the box, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hjhhubj)}(hOapt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 rust-1.80-clippyh]hOapt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 rust-1.80-clippy}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK`hjhhubh)}(hJ``RUST_LIB_SRC`` needs to be set when using the versioned packages, e.g.::h](jO)}(h``RUST_LIB_SRC``h]h RUST_LIB_SRC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh9 needs to be set when using the versioned packages, e.g.:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKbhjhhubj)}(hKRUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/libraryh]hKRUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/library}hj,sbah}(h]h ]h"]h$]h&]hhuh1jhhhKdhjhhubh)}(hIn addition, ``bindgen-0.65`` is available in newer releases (24.04 LTS and 24.10), 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, }(hj:hhhNhNubjO)}(h``bindgen-0.65``h]h bindgen-0.65}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj:ubh is available in newer releases (24.04 LTS and 24.10), but it may not be available in older ones (20.04 LTS and 22.04 LTS), thus }(hj:hhhNhNubjO)}(h ``bindgen``h]hbindgen}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj:ubh2 may need to be built manually (please see below).}(hj:hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKfhjhhubeh}(h]ubuntuah ]h"]ubuntuah$]h&]uh1hhjvhhhhhK[ubeh}(h] distributionsah ]h"] distributionsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hRequirements: Buildingh]hRequirements: Building}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj|hhhhhKlubh)}(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&]uh1hhhhKnhj|hhubh)}(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&]uh1hhhhKphj|hhubj)}(hmake LLVM=1 rustavailableh]hmake LLVM=1 rustavailable}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKshj|hhubh)}(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 }(hjhhhNhNubjO)}(h``RUST_IS_AVAILABLE``h]hRUST_IS_AVAILABLE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhE should be enabled; but it also explains why not if that is the case.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKuhj|hhubh)}(hhh](h)}(hrustch]hrustc}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK{ubh)}(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&]uh1hhhhK}hjhhubh)}(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 }(hjhhhNhNubjO)}(h ``rustup``h]hrustup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh9 is being used, enter the kernel build directory (or use }(hjhhhNhNubjO)}(h``--path=``h]h--path=}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh argument to the }(hjhhhNhNubjO)}(h``set``h]hset}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh$ sub-command) and run, for instance:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hrustup override set stableh]hrustup override set stable}hj:sbah}(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 }(hjHhhhNhNubjO)}(h ``rustc``h]hrustc}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjHubh* without affecting your default toolchain.}(hjHhhhNhNubeh}(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).}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hCIf you are not using ``rustup``, fetch a standalone installer from:h](hIf you are not using }(hjvhhhNhNubjO)}(h ``rustup``h]hrustup}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjvubh$, fetch a standalone installer from:}(hjvhhhNhNubeh}(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]h)}(hjh]hLhttps://forge.rust-lang.org/infra/other-installation-methods.html#standalone}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1hhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubeh}(h]rustcah ]h"]rustcah$]h&]uh1hhj|hhhhhK{ubh)}(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 }(hjhhhNhNubjO)}(h``core``h]hcore}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h"If ``rustup`` is being used, run::h](hIf }(hjhhhNhNubjO)}(h ``rustup``h]hrustup}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh is being used, run:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hrustup component add rust-srch]hrustup component add rust-src}hjsbah}(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.}(hj!hhhNhNubah}(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:}(hj/hhhNhNubah}(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}hj=sbah}(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 }(hjKhhhNhNubjO)}(h1``$(rustc --print sysroot)/lib/rustlib/src/rust``h]h-$(rustc --print sysroot)/lib/rustlib/src/rust}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjKubh# then rerunning the above command).}(hjKhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]rust-standard-library-sourceah ]h"]rust standard library sourceah$]h&]uh1hhj|hhhhhKubh)}(hhh](h)}(hlibclangh]hlibclang}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjshhhhhKubh)}(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](jO)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh (part of LLVM) is used by }(hjhhhNhNubjO)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhw to understand the C code in the kernel, which means LLVM needs to be installed; like when the kernel is compiled with }(hjhhhNhNubjO)}(h ``LLVM=1``h]hLLVM=1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjshhubh)}(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&]uh1hhhhKhjshhubh)}(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&]uh1hhhhKhjshhubj)}(h(https://releases.llvm.org/download.html h]h)}(h'https://releases.llvm.org/download.htmlh]h)}(hjh]h'https://releases.llvm.org/download.html}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1hhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjshhubh)}(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&]uh1hhhhKhjshhubj)}(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]h)}(hjh]hShttps://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1hhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjshhubh)}(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.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjshhubeh}(h]libclangah ]h"]libclangah$]h&]uh1hhj|hhhhhKubh)}(hhh](h)}(hbindgenh]hbindgen}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjHhhhhhKubh)}(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 }(hjYhhhNhNubjO)}(h ``bindgen``h]hbindgen}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjYubh tool.}(hjYhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjHhhubh)}(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):}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjHhhubj)}(h"cargo install --locked bindgen-clih]h"cargo install --locked bindgen-cli}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjHhhubh)}(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](jO)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh uses the }(hjhhhNhNubjO)}(h ``clang-sys``h]h clang-sys}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh crate to find a suitable }(hjhhhNhNubjO)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhU (which may be linked statically, dynamically or loaded at runtime). By default, the }(hjhhhNhNubjO)}(h ``cargo``h]hcargo}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh command above will produce a }(hjhhhNhNubjO)}(h ``bindgen``h]hbindgen}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh binary that will load }(hjhhhNhNubjO)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh0 at runtime. If it is not found (or a different }(hjhhhNhNubjO)}(h ``libclang``h]hlibclang}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubhS than the one found should be used), the process can be tweaked, e.g. by using the }(hjhhhNhNubjO)}(h``LIBCLANG_PATH``h]h LIBCLANG_PATH}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh/ environment variable. For details, please see }(hjhhhNhNubjO)}(h ``clang-sys``h]h clang-sys}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjubh’s documentation at:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjHhhubj)}(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]h)}(hjGh]h.https://github.com/KyleMayes/clang-sys#linking}(hjIhhhNhNubah}(h]h ]h"]h$]h&]refurijGuh1hhjEubah}(h]h ]h"]h$]h&]uh1hhhhKhjAubh)}(h`_ language server can be used with many editors to enable syntax highlighting, completion, go to definition, and other features.h](hThe }(hj hhhNhNubh)}(h3`rust-analyzer `_h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]name rust-analyzerj https://rust-analyzer.github.io/uh1hhj ubj)}(h# h]h}(h]id1ah ]h"] rust-analyzerah$]h&]refurij uh1jjKhj 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&]uh1hhhhMhj hhubh)}(h``rust-analyzer`` needs a configuration file, ``rust-project.json``, which can be generated by the ``rust-analyzer`` Make target::h](jO)}(h``rust-analyzer``h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh needs a configuration file, }(hj hhhNhNubjO)}(h``rust-project.json``h]hrust-project.json}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh , which can be generated by the }(hj hhhNhNubjO)}(h``rust-analyzer``h]h rust-analyzer}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh Make target:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(hmake LLVM=1 rust-analyzerh]hmake LLVM=1 rust-analyzer}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubeh}(h] rust-analyzerah ]h"]h$]j ah&]uh1hhjhhhhhMjKubeh}(h]requirements-developingah ]h"]requirements: developingah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Configurationh]h Configuration}(hj@ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj= hhhhhMubh)}(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](jO)}(h``Rust support``h]h Rust support}(hjR hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjN ubh (}(hjN hhhNhNubjO)}(h``CONFIG_RUST``h]h CONFIG_RUST}(hjd hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjN ubh) needs to be enabled in the }(hjN hhhNhNubjO)}(h``General setup``h]h General setup}(hjv hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhjN 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.}(hjN hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj= hhubh)}(hAfterwards, go to::h]hAfterwards, go to:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hj= hhubj)}(h@Kernel hacking -> Sample kernel code -> Rust samplesh]h@Kernel hacking -> Sample kernel code -> Rust samples}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhM'hj= 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&]uh1hhhhM+hj= hhubeh}(h] configurationah ]h"] configurationah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hBuildingh]hBuilding}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhM/ubh)}(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&]uh1hhhhM1hj hhubj)}(h make LLVM=1h]h make LLVM=1}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhM4hj 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&]uh1hhhhM6hj hhubeh}(h]buildingah ]h"]buildingah$]h&]uh1hhhhhhhhM/ubh)}(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 hhhNhNubjO)}(h``samples/rust/``h]h samples/rust/}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh, the Rust support code under }(hj hhhNhNubjO)}(h ``rust/``h]hrust/}(hj. hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh and the }(hj hhhNhNubjO)}(h``Rust hacking``h]h Rust hacking}(hj@ hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh menu under }(hj hhhNhNubjO)}(h``Kernel hacking``h]hKernel hacking}(hjR hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM=hj hhubh)}(hIf GDB/Binutils is used and Rust symbols are not getting demangled, the reason is the toolchain does not support Rust's new v0 mangling scheme yet. There are a few ways out:h]hIf GDB/Binutils is used and Rust symbols are not getting demangled, the reason is the toolchain does not support Rust’s new v0 mangling scheme yet. There are a few ways out:}(hjj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhj hhubh bullet_list)}(hhh](h list_item)}(h9Install a newer release (GDB >= 10.2, Binutils >= 2.36). h]h)}(h8Install a newer release (GDB >= 10.2, Binutils >= 2.36).h]h8Install a newer release (GDB >= 10.2, Binutils >= 2.36).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhj ubah}(h]h ]h"]h$]h&]uh1j} hjz hhhhhNubj~ )}(hSome versions of GDB (e.g. vanilla GDB 10.1) are able to use the pre-demangled names embedded in the debug info (``CONFIG_DEBUG_INFO``).h]h)}(hSome versions of GDB (e.g. vanilla GDB 10.1) are able to use the pre-demangled names embedded in the debug info (``CONFIG_DEBUG_INFO``).h](hqSome versions of GDB (e.g. vanilla GDB 10.1) are able to use the pre-demangled names embedded in the debug info (}(hj hhhNhNubjO)}(h``CONFIG_DEBUG_INFO``h]hCONFIG_DEBUG_INFO}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jNhj ubh).}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMGhj ubah}(h]h ]h"]h$]h&]uh1j} hjz hhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jx hhhMEhj 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_sourceh _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 jj jyjvjjjjj%j"jvjsjjjjjqjnjjjjjpjmjEjBjj}j: j7 j@j=jjj j rust-analyzerj j j j j j j u nametypes}(j jjyjjj%jvjjjqjjjpjEjj: j@jj j@ j j j uh}(j hj jjvjvjjjjj"jjsj(jjyjjjnjjj|jjjmjjBjsj}jHj7 jj=jjjCj jj0 j j j j j= 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”.}(hjd hhhNhNubah}(h]h ]h"]h$]h&]uh1hhja ubah}(h]h ]h"]h$]h&]j alevelKtypeINFOsourcehlineKuh1j_ hj hhhhhMubatransform_messages] transformerN include_log] decorationNhhub.