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

Add (optional) doc_auto_cfg attribute to generated library #855

Open
robamu opened this issue Jun 25, 2024 · 2 comments
Open

Add (optional) doc_auto_cfg attribute to generated library #855

robamu opened this issue Jun 25, 2024 · 2 comments

Comments

@robamu
Copy link
Contributor

robamu commented Jun 25, 2024

In my crates, I currently use the following code snippet at the top of lib.rs:

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

For documentation built by docs.rs, this explicitly displays required features for modules/functions etc. without requiring additional attributes.
What do you think about adding this to the generated library?

In all my libraries using this, I use the following snippets in Cargo.toml to use this for the docs-rs build:

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]
@robamu
Copy link
Contributor Author

robamu commented Jun 25, 2024

Actually, I have issue building this locally without warnings with current nightly.

Adding the following snippet to Cargo.toml:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(docs_rs)'] }

fixes the warning ,but the documentation still is not built properly.. In any case https://docs.rs/va108xx/0.3.0/va108xx/ shows the end result , with the documentation displaying where the rt feature is required.

@robamu
Copy link
Contributor Author

robamu commented Jun 25, 2024

After some more research:

It is sufficient to use

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

in the lib.rs. The docsrs configuration will be set by docs-rs automatically.
In the Cargo.toml

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]

is sufficient now.

The old way I used to build this locally does not work anymore. I tested this locally using

RUSTDOCFLAGS="--cfg docsrs --generate-link-to-definition -Z unstable-options" cargo +nightly doc --all-features  --open

the old way

cargo +nightly doc --all-features --config 'build.rustdocflags=["--cfg", "docsrs", "--generate-link-to-definition"]' --open

does not work anymore for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant