Skip to content

Commit bc2e7d5

Browse files
committed
rust: support srctree-relative links
Some of our links use relative paths in order to point to files in the source tree, e.g.: //! C header: [`include/linux/printk.h`](../../../../include/linux/printk.h) /// [`struct mutex`]: ../../../../include/linux/mutex.h These are problematic because they are hard to maintain and do not support `O=` builds. Instead, provide support for `srctree`-relative links, e.g.: //! C header: [`include/linux/printk.h`](srctree/include/linux/printk.h) /// [`struct mutex`]: srctree/include/linux/mutex.h The links are fixed after `rustdoc` generation to be based on the absolute path to the source tree. Essentially, this is the automatic version of Tomonori's fix [1], suggested by Gary [2]. Suggested-by: Gary Guo <[email protected]> Reported-by: FUJITA Tomonori <[email protected]> Closes: https://lore.kernel.org/r/[email protected] [1] Fixes: 48fadf4 ("docs: Move rustdoc output, cross-reference it") Link: https://lore.kernel.org/rust-for-linux/20231026154525.6d14b495@eugeo/ [2] Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 0a7f5ba commit bc2e7d5

File tree

12 files changed

+28
-14
lines changed

12 files changed

+28
-14
lines changed

Documentation/rust/coding-guidelines.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ please take a look at the ``rustdoc`` book at:
177177

178178
https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html
179179

180+
In addition, the kernel supports creating links relative to the source tree by
181+
prefixing the link destination with ``srctree/``. For instance:
182+
183+
.. code-block:: rust
184+
185+
//! C header: [`include/linux/printk.h`](srctree/include/linux/printk.h)
186+
187+
or:
188+
189+
.. code-block:: rust
190+
191+
/// [`struct mutex`]: srctree/include/linux/mutex.h
192+
180193
181194
Naming
182195
------

rust/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
9999
$(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
100100
-e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \
101101
-e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \
102-
-e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g'
102+
-e 's:<link rel="alternate icon" type="image/png" href="[/.]+/static\.files/favicon-(16x16|32x32)-[0-9a-f]+\.png">::g' \
103+
-e 's:<a href="srctree/([^"]+)">:<a href="$(abs_srctree)/\1">:g'
103104
$(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \
104105
echo ".logo-container > img { object-fit: contain; }" >> $$f; done
105106

rust/kernel/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! Kernel errors.
44
//!
5-
//! C header: [`include/uapi/asm-generic/errno-base.h`](../../../include/uapi/asm-generic/errno-base.h)
5+
//! C header: [`include/uapi/asm-generic/errno-base.h`](srctree/include/uapi/asm-generic/errno-base.h)
66
77
use crate::str::CStr;
88

rust/kernel/ioctl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! ioctl() number definitions
44
//!
5-
//! C header: [`include/asm-generic/ioctl.h`](../../../../include/asm-generic/ioctl.h)
5+
//! C header: [`include/asm-generic/ioctl.h`](srctree/include/asm-generic/ioctl.h)
66
77
#![allow(non_snake_case)]
88

rust/kernel/kunit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! KUnit-based macros for Rust unit tests.
44
//!
5-
//! C header: [`include/kunit/test.h`](../../../../../include/kunit/test.h)
5+
//! C header: [`include/kunit/test.h`](srctree/include/kunit/test.h)
66
//!
77
//! Reference: <https://docs.kernel.org/dev-tools/kunit/index.html>
88

rust/kernel/print.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! Printing facilities.
44
//!
5-
//! C header: [`include/linux/printk.h`](../../../../include/linux/printk.h)
5+
//! C header: [`include/linux/printk.h`](srctree/include/linux/printk.h)
66
//!
77
//! Reference: <https://www.kernel.org/doc/html/latest/core-api/printk-basics.html>
88
@@ -48,7 +48,7 @@ pub mod format_strings {
4848
/// The format string is always the same for a given level, i.e. for a
4949
/// given `prefix`, which are the kernel's `KERN_*` constants.
5050
///
51-
/// [`_printk`]: ../../../../include/linux/printk.h
51+
/// [`_printk`]: srctree/include/linux/printk.h
5252
const fn generate(is_cont: bool, prefix: &[u8; 3]) -> [u8; LENGTH] {
5353
// Ensure the `KERN_*` macros are what we expect.
5454
assert!(prefix[0] == b'\x01');
@@ -97,7 +97,7 @@ pub mod format_strings {
9797
/// The format string must be one of the ones in [`format_strings`], and
9898
/// the module name must be null-terminated.
9999
///
100-
/// [`_printk`]: ../../../../include/linux/_printk.h
100+
/// [`_printk`]: srctree/include/linux/_printk.h
101101
#[doc(hidden)]
102102
#[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))]
103103
pub unsafe fn call_printk(
@@ -120,7 +120,7 @@ pub unsafe fn call_printk(
120120
///
121121
/// Public but hidden since it should only be used from public macros.
122122
///
123-
/// [`_printk`]: ../../../../include/linux/printk.h
123+
/// [`_printk`]: srctree/include/linux/printk.h
124124
#[doc(hidden)]
125125
#[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))]
126126
pub fn call_printk_cont(args: fmt::Arguments<'_>) {

rust/kernel/sync/condvar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ macro_rules! new_condvar {
6969
/// }
7070
/// ```
7171
///
72-
/// [`struct wait_queue_head`]: ../../../include/linux/wait.h
72+
/// [`struct wait_queue_head`]: srctree/include/linux/wait.h
7373
#[pin_data]
7474
pub struct CondVar {
7575
#[pin]

rust/kernel/sync/lock/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ macro_rules! new_mutex {
8484
/// }
8585
/// ```
8686
///
87-
/// [`struct mutex`]: ../../../../include/linux/mutex.h
87+
/// [`struct mutex`]: srctree/include/linux/mutex.h
8888
pub type Mutex<T> = super::Lock<T, MutexBackend>;
8989

9090
/// A kernel `struct mutex` lock backend.

rust/kernel/sync/lock/spinlock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ macro_rules! new_spinlock {
8282
/// }
8383
/// ```
8484
///
85-
/// [`spinlock_t`]: ../../../../include/linux/spinlock.h
85+
/// [`spinlock_t`]: srctree/include/linux/spinlock.h
8686
pub type SpinLock<T> = super::Lock<T, SpinLockBackend>;
8787

8888
/// A kernel `spinlock_t` lock backend.

rust/kernel/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! Tasks (threads and processes).
44
//!
5-
//! C header: [`include/linux/sched.h`](../../../../include/linux/sched.h).
5+
//! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h).
66
77
use crate::{bindings, types::Opaque};
88
use core::{marker::PhantomData, ops::Deref, ptr};

rust/kernel/workqueue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
//! }
133133
//! ```
134134
//!
135-
//! C header: [`include/linux/workqueue.h`](../../../../include/linux/workqueue.h)
135+
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
136136
137137
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
138138
use alloc::alloc::AllocError;

rust/macros/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use proc_macro::TokenStream;
2020
/// The `type` argument should be a type which implements the [`Module`]
2121
/// trait. Also accepts various forms of kernel metadata.
2222
///
23-
/// C header: [`include/linux/moduleparam.h`](../../../include/linux/moduleparam.h)
23+
/// C header: [`include/linux/moduleparam.h`](srctree/include/linux/moduleparam.h)
2424
///
2525
/// [`Module`]: ../kernel/trait.Module.html
2626
///

0 commit comments

Comments
 (0)