Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_cfg #442

Closed
kloenk opened this issue Jul 12, 2021 · 5 comments
Closed

doc_cfg #442

kloenk opened this issue Jul 12, 2021 · 5 comments
Labels
• docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos...

Comments

@kloenk
Copy link
Member

kloenk commented Jul 12, 2021

I would like to use doc_cfg for documentation. I don't have a clue about the current build system. Would it be trivial to allow? @ojeda can you do that? Also, is this allowed, or would it be a to unstable feature?

@kloenk kloenk added the • docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos... label Jul 12, 2021
@kloenk
Copy link
Member Author

kloenk commented Jul 12, 2021

I figured out that I can just enable it (in #439). But We should discuss if I'm allowed to use it :-)

@ojeda
Copy link
Member

ojeda commented Jul 14, 2021

Not sure what you mean by allowing it in the current build system -- all unstable features are allowed inside rust/, so you should not need any change in particular.

The big question is, as usual, whether to add it to the list of unstable features or not. While for "custom" docs (i.e. docs generated for a given .config) it is fine to skip things that are not enabled, for the "global" docs, i.e. those that we will put in kernel.org, it would definitely nice to document everything. And I assume the "global" docs are the ones that most people will read.

From a quick look, there is still discussion going around doc_cfg, including talk about automatically inferring the doc(cfg(...)) attributes from the usual ones (to avoid duplication) etc., so there are things that may change and may take a while to get stabilized. On the other hand, it seems the feature will get stabilized one way or the other.

Ideally the compiler would ignore this feature when not generating the docs (so that it would not "count" as an unstable feature when not generating docs).

I have taken a look at the generated docs for something like:

#[cfg(any(CONFIG_SYSCTL, doc))]
#[doc(cfg(CONFIG_SYSCTL))]
pub mod sysctl;

and it looks very nice!

@ojeda
Copy link
Member

ojeda commented Jul 14, 2021

Actually, that gives me an idea: rustdoc could have a way to provide it with a custom map with the "nicer names" (like it has, hardcoded, for some key-values e.g. unix -> "Unix").

On our side, we could then automatically fill it with the titles from Kconfig, or something like that. For instance, for CONFIG_NET we could have the banner with:

This is supported when Networking (CONFIG_NET) is enabled only.

instead of:

This is supported on CONFIG_NET only.

(It looks worse here than in the generated docs).

@nbdd0121
Copy link
Member

The big question is, as usual, whether to add it to the list of unstable features or not.

Given that we pin to a specify Rust version, I think we could be more liberal when it comes to use unstable features that wouldn't be difficult to remove in the future. For things like doc_cfg even it's gone from rustc, we can remove all usages easily, so I don't think it'll be problematic to use it.

Actually, that gives me an idea: rustdoc could have a way to provide it with a custom map with the "nicer names" (like it has, hardcoded, for some key-values e.g. unix -> "Unix").

On our side, we could then automatically fill it with the titles from Kconfig, or something like that. For instance, for CONFIG_NET we could have the banner with:

Supported only when Networking support (CONFIG_NET) is enabled.

instead of:

This is supported on CONFIG_NET only.

Sounds like something doable by some simple text postprocessing :)

@ojeda
Copy link
Member

ojeda commented Jul 14, 2021

Given that we pin to a specify Rust version, I think we could be more liberal when it comes to use unstable features that wouldn't be difficult to remove in the future. For things like doc_cfg even it's gone from rustc, we can remove all usages easily, so I don't think it'll be problematic to use it.

The problem is not so much about removing them (which introduces churn, specially in mainline, but it is not a big deal), but about getting sooner to the point where we can compile the kernel without unstable features. In general, we should see the pinning as temporary, and work towards avoiding it, rather than the opposite (i.e. adding more features :)

Sounds like something doable by some simple text postprocessing :)

Definitely! I usually try to describe things in terms of what upstream could provide as a feature.

Submitted, by the way: rust-lang/rust#87139.

ojeda added a commit to ojeda/linux that referenced this issue Jul 14, 2021
Closes Rust-for-Linux#442.

Suggested-by: Finn Behrens <me@kloenk.de>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
@ojeda ojeda closed this as completed in faf7ea6 Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
• docs Related to `Documentation/rust/`, `samples/`, generated docs, doctests, typos...
Development

No branches or pull requests

3 participants