Skip to content

Commit fd87fe1

Browse files
committed
Add documentation on coding
Includes the bit on conditional compilation from [1]. [1] #32 (comment) Signed-off-by: Miguel Ojeda <[email protected]>
1 parent c28ec6f commit fd87fe1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Documentation/rust/coding.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _rust_coding:
2+
3+
Coding
4+
======
5+
6+
This document describes how to write Rust code in the kernel.
7+
8+
9+
Coding style
10+
------------
11+
12+
For the moment, we are following the idiomatic Rust style. For instance,
13+
we use 4 spaces for indentation rather than tabs.
14+
15+
16+
Abstractions vs. bindings
17+
-------------------------
18+
19+
We don't have abstractions for all the kernel internal APIs and concepts,
20+
but we would like to expand coverage as time goes on. Unless there is
21+
a good reason not to, always use the abstractions instead of calling
22+
the C bindings directly.
23+
24+
If you are writing some code that requires a call to an internal kernel API
25+
or concept that isn't abstracted yet, consider providing an (ideally safe)
26+
abstraction for everyone to use.
27+
28+
29+
Conditional compilation
30+
-----------------------
31+
32+
Rust code has access to conditional compilation based on the kernel
33+
configuration:
34+
35+
.. code-block:: rust
36+
37+
#[cfg(CONFIG_X)] // `CONFIG_X` is enabled (`y` or `m`)
38+
#[cfg(CONFIG_X="y")] // `CONFIG_X` is enabled as a built-in (`y`)
39+
#[cfg(CONFIG_X="m")] // `CONFIG_X` is enabled as a module (`m`)
40+
#[cfg(not(CONFIG_X))] // `CONFIG_X` is disabled
41+

Documentation/rust/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Documentation related to Rust within the kernel. If you are starting out, read t
77
:maxdepth: 1
88

99
quick-start
10+
coding
1011

1112
.. only:: subproject and html
1213

0 commit comments

Comments
 (0)