Skip to content

Commit

Permalink
Merge branch 'rust-next' of https://github.com/Rust-for-Linux/linux.git
Browse files Browse the repository at this point in the history
# Conflicts:
#	Makefile
  • Loading branch information
broonie committed Sep 29, 2022
2 parents e4166af + fd9517a commit 60349a4
Show file tree
Hide file tree
Showing 89 changed files with 12,558 additions and 52 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -37,6 +37,8 @@
*.o
*.o.*
*.patch
*.rmeta
*.rsi
*.s
*.so
*.so.dbg
Expand Down Expand Up @@ -97,6 +99,7 @@ modules.order
!.gitattributes
!.gitignore
!.mailmap
!.rustfmt.toml

#
# Generated include files
Expand Down Expand Up @@ -162,3 +165,6 @@ x509.genkey

# Documentation toolchain
sphinx_*/

# Rust analyzer configuration
/rust-project.json
12 changes: 12 additions & 0 deletions .rustfmt.toml
@@ -0,0 +1,12 @@
edition = "2021"
newline_style = "Unix"

# Unstable options that help catching some mistakes in formatting and that we may want to enable
# when they become stable.
#
# They are kept here since they are useful to run from time to time.
#format_code_in_doc_comments = true
#reorder_impl_items = true
#comment_width = 100
#wrap_comments = true
#normalize_comments = true
10 changes: 10 additions & 0 deletions Documentation/core-api/printk-formats.rst
Expand Up @@ -625,6 +625,16 @@ Examples::
%p4cc Y10 little-endian (0x20303159)
%p4cc NV12 big-endian (0xb231564e)

Rust
----

::

%pA

Only intended to be used from Rust code to format ``core::fmt::Arguments``.
Do *not* use it from C.

Thanks
======

Expand Down
3 changes: 3 additions & 0 deletions Documentation/doc-guide/kernel-doc.rst
Expand Up @@ -14,6 +14,9 @@ when it is embedded in source files.
reasons. The kernel source contains tens of thousands of kernel-doc
comments. Please stick to the style described here.

.. note:: kernel-doc does not cover Rust code: please see
Documentation/rust/general-information.rst instead.

The kernel-doc structure is extracted from the comments, and proper
`Sphinx C Domain`_ function and type descriptions with anchors are
generated from them. The descriptions are filtered for special kernel-doc
Expand Down
1 change: 1 addition & 0 deletions Documentation/index.rst
Expand Up @@ -82,6 +82,7 @@ merged much easier.
maintainer/index
fault-injection/index
livepatch/index
rust/index


Kernel API documentation
Expand Down
17 changes: 17 additions & 0 deletions Documentation/kbuild/kbuild.rst
Expand Up @@ -48,6 +48,10 @@ KCFLAGS
-------
Additional options to the C compiler (for built-in and modules).

KRUSTFLAGS
----------
Additional options to the Rust compiler (for built-in and modules).

CFLAGS_KERNEL
-------------
Additional options for $(CC) when used to compile
Expand All @@ -57,6 +61,15 @@ CFLAGS_MODULE
-------------
Additional module specific options to use for $(CC).

RUSTFLAGS_KERNEL
----------------
Additional options for $(RUSTC) when used to compile
code that is compiled as built-in.

RUSTFLAGS_MODULE
----------------
Additional module specific options to use for $(RUSTC).

LDFLAGS_MODULE
--------------
Additional options used for $(LD) when linking modules.
Expand All @@ -69,6 +82,10 @@ HOSTCXXFLAGS
------------
Additional flags to be passed to $(HOSTCXX) when building host programs.

HOSTRUSTFLAGS
-------------
Additional flags to be passed to $(HOSTRUSTC) when building host programs.

HOSTLDFLAGS
-----------
Additional flags to be passed when linking host programs.
Expand Down
50 changes: 46 additions & 4 deletions Documentation/kbuild/makefiles.rst
Expand Up @@ -29,8 +29,9 @@ This document describes the Linux kernel Makefiles.
--- 4.1 Simple Host Program
--- 4.2 Composite Host Programs
--- 4.3 Using C++ for host programs
--- 4.4 Controlling compiler options for host programs
--- 4.5 When host programs are actually built
--- 4.4 Using Rust for host programs
--- 4.5 Controlling compiler options for host programs
--- 4.6 When host programs are actually built
=== 5 Userspace Program support
--- 5.1 Simple Userspace Program
Expand Down Expand Up @@ -824,7 +825,24 @@ Both possibilities are described in the following.
qconf-cxxobjs := qconf.o
qconf-objs := check.o

4.4 Controlling compiler options for host programs
4.4 Using Rust for host programs
--------------------------------

Kbuild offers support for host programs written in Rust. However,
since a Rust toolchain is not mandatory for kernel compilation,
it may only be used in scenarios where Rust is required to be
available (e.g. when ``CONFIG_RUST`` is enabled).

Example::

hostprogs := target
target-rust := y

Kbuild will compile ``target`` using ``target.rs`` as the crate root,
located in the same directory as the ``Makefile``. The crate may
consist of several source files (see ``samples/rust/hostprogs``).

4.5 Controlling compiler options for host programs
--------------------------------------------------

When compiling host programs, it is possible to set specific flags.
Expand Down Expand Up @@ -856,7 +874,7 @@ Both possibilities are described in the following.
When linking qconf, it will be passed the extra option
"-L$(QTDIR)/lib".

4.5 When host programs are actually built
4.6 When host programs are actually built
-----------------------------------------

Kbuild will only build host-programs when they are referenced
Expand Down Expand Up @@ -1169,6 +1187,17 @@ When kbuild executes, the following steps are followed (roughly):
The first example utilises the trick that a config option expands
to 'y' when selected.

KBUILD_RUSTFLAGS
$(RUSTC) compiler flags

Default value - see top level Makefile
Append or modify as required per architecture.

Often, the KBUILD_RUSTFLAGS variable depends on the configuration.

Note that target specification file generation (for ``--target``)
is handled in ``scripts/generate_rust_target.rs``.

KBUILD_AFLAGS_KERNEL
Assembler options specific for built-in

Expand Down Expand Up @@ -1196,6 +1225,19 @@ When kbuild executes, the following steps are followed (roughly):
are used for $(CC).
From commandline CFLAGS_MODULE shall be used (see kbuild.rst).

KBUILD_RUSTFLAGS_KERNEL
$(RUSTC) options specific for built-in

$(KBUILD_RUSTFLAGS_KERNEL) contains extra Rust compiler flags used to
compile resident kernel code.

KBUILD_RUSTFLAGS_MODULE
Options for $(RUSTC) when building modules

$(KBUILD_RUSTFLAGS_MODULE) is used to add arch-specific options that
are used for $(RUSTC).
From commandline RUSTFLAGS_MODULE shall be used (see kbuild.rst).

KBUILD_LDFLAGS_MODULE
Options for $(LD) when linking modules

Expand Down
41 changes: 41 additions & 0 deletions Documentation/process/changes.rst
Expand Up @@ -31,6 +31,8 @@ you probably needn't concern yourself with pcmciautils.
====================== =============== ========================================
GNU C 5.1 gcc --version
Clang/LLVM (optional) 11.0.0 clang --version
Rust (optional) 1.62.0 rustc --version
bindgen (optional) 0.56.0 bindgen --version
GNU make 3.81 make --version
bash 4.2 bash --version
binutils 2.23 ld -v
Expand Down Expand Up @@ -80,6 +82,29 @@ kernels. Older releases aren't guaranteed to work, and we may drop workarounds
from the kernel that were used to support older versions. Please see additional
docs on :ref:`Building Linux with Clang/LLVM <kbuild_llvm>`.

Rust (optional)
---------------

A particular version of the Rust toolchain is required. Newer versions may or
may not work because the kernel depends on some unstable Rust features, for
the moment.

Each Rust toolchain comes with several "components", some of which are required
(like ``rustc``) and some that are optional. The ``rust-src`` component (which
is optional) needs to be installed to build the kernel. Other components are
useful for developing.

Please see Documentation/rust/quick-start.rst for instructions on how to
satisfy the build requirements of Rust support. In particular, the ``Makefile``
target ``rustavailable`` is useful to check why the Rust toolchain may not
be detected.

bindgen (optional)
------------------

``bindgen`` is used to generate the Rust bindings to the C side of the kernel.
It depends on ``libclang``.

Make
----

Expand Down Expand Up @@ -348,6 +373,12 @@ Sphinx
Please see :ref:`sphinx_install` in :ref:`Documentation/doc-guide/sphinx.rst <sphinxdoc>`
for details about Sphinx requirements.

rustdoc
-------

``rustdoc`` is used to generate the documentation for Rust code. Please see
Documentation/rust/general-information.rst for more information.

Getting updated software
========================

Expand All @@ -364,6 +395,16 @@ Clang/LLVM

- :ref:`Getting LLVM <getting_llvm>`.

Rust
----

- Documentation/rust/quick-start.rst.

bindgen
-------

- Documentation/rust/quick-start.rst.

Make
----

Expand Down
19 changes: 19 additions & 0 deletions Documentation/rust/arch-support.rst
@@ -0,0 +1,19 @@
.. SPDX-License-Identifier: GPL-2.0
Arch Support
============

Currently, the Rust compiler (``rustc``) uses LLVM for code generation,
which limits the supported architectures that can be targeted. In addition,
support for building the kernel with LLVM/Clang varies (please see
Documentation/kbuild/llvm.rst). This support is needed for ``bindgen``
which uses ``libclang``.

Below is a general summary of architectures that currently work. Level of
support corresponds to ``S`` values in the ``MAINTAINERS`` file.

============ ================ ==============================================
Architecture Level of support Constraints
============ ================ ==============================================
``x86`` Maintained ``x86_64`` only.
============ ================ ==============================================

0 comments on commit 60349a4

Please sign in to comment.