Miguel Ojeda
2025-Nov-04 18:35 UTC
[PATCH RFC 1/4] rust: clist: Add abstraction for iterating over C linked lists
On Tue, Nov 4, 2025 at 3:35?PM Guillaume Gomez <guillaume1.gomez at gmail.com> wrote:> > You can use `cfg(doc)` and `cfg(doctest)` to only include parts of the > docs when running doctests (if that's what this is about).Thanks for the quick reply! I think this is more about having some code essentially "prefixed" to certain doctests without having to repeat it in every one. Or, more generally, to provide custom "environments" for certain doctests, including perhaps a custom prelude and things like that. So one way would be writing a `mod` (perhaps with a `path` attribute) or an `include` to manually do that. Or perhaps having an auxiliary crate or similar that contains those mods/files (that probably only gets built when the KUnit doctests are enabled). Orthogonally, the script that generates the doctests could perhaps help to automate some of that. For instance, we could have a way to specify an "environment" for a given Rust file or Rust `mod` or similar, and then every doctests would have the code prefixed to them. But I prefer to wait until we have real users of this and the new JSON generation. Using `cfg(doctest)` in some code in the `kernel` crate wouldn't work, unless I am missing something, because we wouldn't want to have a "parallel `kernel` crate" in the same build that only the doctests would use. Cheers, Miguel
Miguel Ojeda
2025-Nov-04 19:06 UTC
[PATCH RFC 1/4] rust: clist: Add abstraction for iterating over C linked lists
On Tue, Nov 4, 2025 at 7:35?PM Miguel Ojeda <miguel.ojeda.sandonis at gmail.com> wrote:> > Orthogonally, the script that generates the doctests could perhaps > help to automate some of that. For instance, we could have a way to > specify an "environment" for a given Rust file or Rust `mod` or > similar, and then every doctests would have the code prefixed to them.I guess this could probably best generalized as "tagging" doctests with custom tags that `rustdoc` just forwards in the generated JSON. Something like: /// ```tag:foo,tag:bar would give us a: "tags": ["foo", "bar"] in the JSON. Then a custom generator like the one we have could do whatever it needs with it, including prepending code or other things. Now, I see there is already an `unknown` field in the attributes which already give us the unrecognized ones, which is great and we could potentially use that. However, should there be a particular way/namespace we should create our custom tags so that we don't conflict in the future with `rustdoc` ones? I have added it to the usual list: https://github.com/Rust-for-Linux/linux/issues/350 (There is also the question about supporting the old non-JSON way for things like this, but I am ignoring that for now) Cheers, Miguel