[04/13] rust: kernel: add srctree-relative doclinks

Message ID 20240116220411.168016-1-kernel@valentinobst.de
State New
Headers
Series rust: kernel: documentation improvements |

Commit Message

Valentin Obst Jan. 16, 2024, 10:04 p.m. UTC
  Convert existing references to C header files to make use of
Commit bc2e7d5c298a ("rust: support `srctree`-relative links").

Signed-off-by: Valentin Obst <kernel@valentinobst.de>
---
 rust/kernel/lib.rs          | 2 +-
 rust/kernel/sync/condvar.rs | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
  

Comments

Trevor Gross Jan. 18, 2024, 12:38 a.m. UTC | #1
On Tue, Jan 16, 2024 at 5:35 PM Valentin Obst <kernel@valentinobst.de> wrote:
>
> Convert existing references to C header files to make use of
> Commit bc2e7d5c298a ("rust: support `srctree`-relative links").
>
> Signed-off-by: Valentin Obst <kernel@valentinobst.de>
> ---
>  rust/kernel/lib.rs          | 2 +-
>  rust/kernel/sync/condvar.rs | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index e6aff80b521f..0d365c71cae2 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -75,7 +75,7 @@ pub trait Module: Sized + Sync {
>
>  /// Equivalent to `THIS_MODULE` in the C API.
>  ///
> -/// C header: `include/linux/export.h`
> +/// C header: [`include/linux/export.h`](srctree/include/linux/export.h)
>  pub struct ThisModule(*mut bindings::module);
>
>  // SAFETY: `THIS_MODULE` may be used from all threads within a module.
> diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
> index f65e19d5a37c..0bb76400efd9 100644
> --- a/rust/kernel/sync/condvar.rs
> +++ b/rust/kernel/sync/condvar.rs
> @@ -77,6 +77,8 @@ pub struct CondVar {
>
>      /// A condvar needs to be pinned because it contains a [`struct list_head`] that is
>      /// self-referential, so it cannot be safely moved once it is initialised.
> +    ///
> +    /// [`struct list_head`]: srctree/include/linux/types.h

Hm, I wonder if we could figure out a way to make links point to
specific definitions in the C headers with # anchors. I'm not sure
what the intended platform to view these links is.

>      #[pin]
>      _pin: PhantomPinned,
>  }
> --
> 2.43.0
>
>

Reviewed-by: Trevor Gross <tmgross@umich.edu>
  
Valentin Obst Jan. 18, 2024, 8:30 a.m. UTC | #2
> Hm, I wonder if we could figure out a way to make links point to
> specific definitions in the C headers with # anchors. I'm not sure
> what the intended platform to view these links is.

Currently the links simply open the plain .h file from your local tree in your
browser, i.e.,

```rust
/// [`struct wait_queue_head`]: srctree/include/linux/wait.h
```

becomes something like:

file:///mnt/build/rust-for-linux/rust4lx/include/linux/wait.h

and fragments won't work on that.

I agree that it would be nice to link to type definitions, variables,
functions, ect. in the file, maybe with something like:

```
#(type|var|func);<identifier>
```

However, I think this will require some parsing and embedding the C
source file into some html.
  

Patch

diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index e6aff80b521f..0d365c71cae2 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -75,7 +75,7 @@  pub trait Module: Sized + Sync {
 
 /// Equivalent to `THIS_MODULE` in the C API.
 ///
-/// C header: `include/linux/export.h`
+/// C header: [`include/linux/export.h`](srctree/include/linux/export.h)
 pub struct ThisModule(*mut bindings::module);
 
 // SAFETY: `THIS_MODULE` may be used from all threads within a module.
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index f65e19d5a37c..0bb76400efd9 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -77,6 +77,8 @@  pub struct CondVar {
 
     /// A condvar needs to be pinned because it contains a [`struct list_head`] that is
     /// self-referential, so it cannot be safely moved once it is initialised.
+    ///
+    /// [`struct list_head`]: srctree/include/linux/types.h
     #[pin]
     _pin: PhantomPinned,
 }