From dde40e613f378b888da1ed6ca4cb88b56a1ffe45 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 31 Jan 2022 18:16:44 +0300 Subject: [PATCH] Change process of building docs - introduce `docs` alias that does the right thing (tm) - use `-Zrustdoc-scrape-examples` --- .cargo/config.toml | 13 +++++++++++++ Cargo.toml | 6 +++++- netlify.toml | 3 +-- src/lib.rs | 5 +++-- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..b565a218 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,13 @@ +[alias] +# Using `--features=full --features=nightly` instead of `--all-features` because of +# https://github.com/rust-lang/cargo/issues/10333 +# +# "tokio/macros" and "tokio/rt-multi-thread" are required for examples +docs = """doc +-Zrustdoc-scrape-examples=examples +--features=full --features=nightly +--features=tokio/macros --features=tokio/rt-multi-thread +""" + +# We pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.` +rustdocflags = ["--cfg", "docsrs", "-Znormalize-docs"] diff --git a/Cargo.toml b/Cargo.toml index d0b0923c..4a12bea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,12 +80,16 @@ cache_me = [] # AutoSend bot adaptor auto_send = [] +# All features except nightly and tls-related full = ["throttle", "trace_adaptor", "erased", "cache_me", "auto_send"] [package.metadata.docs.rs] -all-features = true +features = ["full", "nightly", "tokio/macros", "tokio/rt-multi-thread"] rustdoc-args = ["--cfg", "docsrs", "-Znormalize-docs"] +# https://github.com/rust-lang/rust/issues/88791 +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"] + [[example]] name = "self_info" required-features = ["tokio/macros", "tokio/rt-multi-thread", "auto_send"] diff --git a/netlify.toml b/netlify.toml index e55e0d1a..6493423a 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,5 @@ [build] -command = "rustup install nightly --profile minimal && cargo +nightly doc --all-features --no-deps && cp -r target/doc _netlify_out" -environment = { RUSTDOCFLAGS= "--cfg docsrs -Znormalize-docs" } +command = "rustup install nightly --profile minimal && cargo +nightly docs --no-deps && cp -r target/doc _netlify_out" publish = "_netlify_out" [[redirects]] diff --git a/src/lib.rs b/src/lib.rs index dd7b59a1..9f50eae5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,7 +51,7 @@ //! - `erased` — enables [`ErasedRequester`] bot adaptor //! - `throttle` — enables [`Throttle`] bot adaptor //! - `cache_me` — enables [`CacheMe`] bot adaptor -//! - `full` — enables all features except `nigthly` +//! - `full` — enables all features except `nigthly` and tls-related //! - `nightly` — enables nigthly-only features, currently: //! - Removes some future boxing using `#![feature(type_alias_impl_trait)]` //! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`) @@ -74,8 +74,9 @@ // // To properly build docs of this crate run // ```console -// $ RUSTDOCFLAGS="--cfg docsrs -Znormalize-docs" cargo doc --open --all-features +// $ cargo docs // ``` +// (docs alias is defined in `.cargo/config.toml`) // // `dep_docsrs` is used for the same purpose, but when `teloxide-core` is built as a dependency // (see: `teloxide`). We can't use `docsrs` as it breaks tokio compilation in this case.