From a4f83f80570eb63cc5327f767d7d37bf2129fb47 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 11 Jun 2022 20:51:23 +0200 Subject: [PATCH] Enable `doc_cfg` and `doc_auto_cfg` for all `[features]` crates on https://docs.rs The documentation currently doesn't expose what features a user needs to enable before certain functionality becomes available, requiring them to look at the sourcecode as we don't really provide much documentation or guideance towards this. That's totally fine because it is a job for `rustdoc`, one that it performs very well when the experimental `doc_cfg` feature is enabled, and specifically `doc_auto_cfg` to not have to manually re-specify every `#[cfg()]` within a `#[cfg_attr(docs_rs, doc(cfg()))]`. docs.rs builds on `nightly` which makes this possible, and docs can be built with the `docsrs` cfg enabled locally to see the result, e.g.: RUSTDOCFLAGS="-Dwarnings --cfg docsrs" cargo +nightly doc --no-deps --workspace --target aarch64-linux-android --all-features --document-private-items --open --- ndk-glue/Cargo.toml | 1 + ndk-glue/src/lib.rs | 2 ++ ndk-macro/Cargo.toml | 3 +++ ndk-macro/src/lib.rs | 2 ++ ndk-sys/Cargo.toml | 1 + ndk-sys/src/lib.rs | 1 + ndk/Cargo.toml | 1 + ndk/src/lib.rs | 1 + 8 files changed, 12 insertions(+) diff --git a/ndk-glue/Cargo.toml b/ndk-glue/Cargo.toml index c37827ae..70806b6d 100644 --- a/ndk-glue/Cargo.toml +++ b/ndk-glue/Cargo.toml @@ -27,6 +27,7 @@ test = ["ndk/test", "ndk-sys/test"] logger = ["android_logger", "ndk-macro/logger"] [package.metadata.docs.rs] +rustdoc-args = ["--cfg", "docsrs"] targets = [ "aarch64-linux-android", "armv7-linux-androideabi", diff --git a/ndk-glue/src/lib.rs b/ndk-glue/src/lib.rs index 4c89d51e..6af3ab72 100644 --- a/ndk-glue/src/lib.rs +++ b/ndk-glue/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + use log::Level; use ndk::input_queue::InputQueue; use ndk::looper::{FdEvent, ForeignLooper, ThreadLooper}; diff --git a/ndk-macro/Cargo.toml b/ndk-macro/Cargo.toml index d5aaea36..8d46010b 100644 --- a/ndk-macro/Cargo.toml +++ b/ndk-macro/Cargo.toml @@ -24,3 +24,6 @@ darling = "0.13" [features] default = [] logger = [] + +[package.metadata.docs.rs] +rustdoc-args = ["--cfg", "docsrs"] diff --git a/ndk-macro/src/lib.rs b/ndk-macro/src/lib.rs index 1fd17374..19daf679 100644 --- a/ndk-macro/src/lib.rs +++ b/ndk-macro/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + use darling::FromMeta; use proc_macro::TokenStream; use syn::{parse_macro_input, ItemFn}; diff --git a/ndk-sys/Cargo.toml b/ndk-sys/Cargo.toml index eee1dff0..8d243ea0 100644 --- a/ndk-sys/Cargo.toml +++ b/ndk-sys/Cargo.toml @@ -21,6 +21,7 @@ bitmap = [] media = [] [package.metadata.docs.rs] +rustdoc-args = ["--cfg", "docsrs"] targets = [ "aarch64-linux-android", "armv7-linux-androideabi", diff --git a/ndk-sys/src/lib.rs b/ndk-sys/src/lib.rs index 5adcb0ca..e2fe0814 100644 --- a/ndk-sys/src/lib.rs +++ b/ndk-sys/src/lib.rs @@ -14,6 +14,7 @@ #![allow(deref_nullptr)] // Test setup lints #![cfg_attr(test, allow(dead_code))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use jni_sys::*; diff --git a/ndk/Cargo.toml b/ndk/Cargo.toml index 9974be1b..80534d11 100644 --- a/ndk/Cargo.toml +++ b/ndk/Cargo.toml @@ -53,6 +53,7 @@ version = "0.3.0" [package.metadata.docs.rs] features = ["jni", "jni-glue", "all"] +rustdoc-args = ["--cfg", "docsrs"] targets = [ "aarch64-linux-android", "armv7-linux-androideabi", diff --git a/ndk/src/lib.rs b/ndk/src/lib.rs index ae56bf2a..4c34fd7a 100644 --- a/ndk/src/lib.rs +++ b/ndk/src/lib.rs @@ -4,6 +4,7 @@ //! //! [Android NDK]: https://developer.android.com/ndk/reference #![warn(missing_debug_implementations, trivial_casts)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] pub mod asset; pub mod audio;