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

generate docs for feature gated items #1332

Merged
merged 15 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ bitvec = { workspace = true }
scale-info = { workspace = true, features = ["bit-vec"] }
pretty_assertions = { workspace = true }
frame-metadata = { workspace = true }

[package.metadata.docs.rs]
all-features = true
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
2 changes: 2 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! be used directly if preferable.

#![deny(unused_crate_dependencies, missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod api;
mod ir;
Expand All @@ -18,6 +19,7 @@ pub mod error;
// macro and CLI tool, so they only live here because this is a common
// crate that both depend on.
#[cfg(feature = "fetch-metadata")]
#[cfg_attr(docsrs, doc(cfg(feature = "fetch-metadata")))]
pub mod fetch_metadata;

#[cfg(feature = "web")]
Expand Down
7 changes: 7 additions & 0 deletions lightclient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ pin-project = { workspace = true, optional = true }

# Included if "web" feature is enabled, to enable its js feature.
getrandom = { workspace = true, optional = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
3 changes: 3 additions & 0 deletions lightclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//!
//! This leverages the smoldot crate to connect to the chain.

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

#[cfg(any(
all(feature = "web", feature = "native"),
not(any(feature = "web", feature = "native"))
Expand All @@ -35,6 +37,7 @@ pub mod smoldot {
};

#[cfg(feature = "native")]
#[cfg_attr(docsrs, doc(cfg(feature = "native")))]
pub use smoldot_light::platform::default::DefaultPlatform;
}

Expand Down
7 changes: 7 additions & 0 deletions signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ sp-keyring = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["getrandom"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
4 changes: 4 additions & 0 deletions signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
//! Enable the `subxt` feature to enable use of this [`sr25519::Keypair`] in signing
//! subxt transactions for chains supporting sr25519 signatures.

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

#[macro_use]
mod utils;
mod crypto;

// An sr25519 key pair implementation.
#[cfg(feature = "sr25519")]
#[cfg_attr(docsrs, doc(cfg(feature = "sr25519")))]
pub mod sr25519;

// An ecdsa key pair implementation.
#[cfg(feature = "ecdsa")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa")))]
pub mod ecdsa;

// Re-export useful bits and pieces for generating a Pair from a phrase,
Expand Down
1 change: 1 addition & 0 deletions signer/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub mod dev {
// Make `Keypair` usable to sign transactions in Subxt. This is optional so that
// `subxt-signer` can be used entirely independently of Subxt.
#[cfg(feature = "subxt")]
#[cfg_attr(docsrs, doc(cfg(feature = "subxt")))]
mod subxt_compat {
use super::*;

Expand Down
7 changes: 7 additions & 0 deletions subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,10 @@ required-features = ["unstable-light-client", "jsonrpsee"]
name = "light_client_parachains"
path = "examples/light_client_parachains.rs"
required-features = ["unstable-light-client", "jsonrpsee", "native"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.playground]
all-features = true
1 change: 1 addition & 0 deletions subxt/src/backend/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#![allow(clippy::module_inception)]

#[cfg(feature = "jsonrpsee")]
#[cfg_attr(docsrs, doc(cfg(feature = "jsonrpsee")))]
mod jsonrpsee_impl;

mod rpc_client;
Expand Down
1 change: 1 addition & 0 deletions subxt/src/backend/rpc/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct RpcClient {

impl RpcClient {
#[cfg(feature = "jsonrpsee")]
#[cfg_attr(docsrs, doc(cfg(feature = "jsonrpsee")))]
/// Create a default RPC client pointed at some URL, currently based on [`jsonrpsee`].
pub async fn from_url<U: AsRef<str>>(url: U) -> Result<Self, Error> {
let client = jsonrpsee_helpers::client(url.as_ref())
Expand Down
2 changes: 2 additions & 0 deletions subxt/src/client/light_client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl<T: Config> LightClientBuilder<T> {
/// If smoldot panics, then the promise created will be leaked. For more details, see
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
#[cfg(feature = "jsonrpsee")]
#[cfg_attr(docsrs, doc(cfg(feature = "jsonrpsee")))]
pub async fn build_from_url<Url: AsRef<str>>(self, url: Url) -> Result<LightClient<T>, Error> {
let chain_spec = fetch_url(url.as_ref()).await?;

Expand Down Expand Up @@ -245,6 +246,7 @@ async fn fetch_url(url: impl AsRef<str>) -> Result<serde_json::Value, Error> {
}

#[cfg(all(feature = "jsonrpsee", feature = "native"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "jsonrpsee", feature = "native"))))]
mod jsonrpsee_helpers {
use crate::error::{Error, LightClientError};
pub use jsonrpsee::{
Expand Down
2 changes: 2 additions & 0 deletions subxt/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod offline_client;
mod online_client;

#[cfg(feature = "unstable-light-client")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-light-client")))]
mod light_client;

pub use offline_client::{OfflineClient, OfflineClientT};
Expand All @@ -20,6 +21,7 @@ pub use online_client::{
};

#[cfg(feature = "unstable-light-client")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-light-client")))]
pub use light_client::{
LightClient, LightClientBuilder, LightClientError, RawLightClient, RawLightClientBuilder,
};
1 change: 1 addition & 0 deletions subxt/src/client/online_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<T: Config> std::fmt::Debug for OnlineClient<T> {

// The default constructors assume Jsonrpsee.
#[cfg(feature = "jsonrpsee")]
#[cfg_attr(docsrs, doc(cfg(feature = "jsonrpsee")))]
impl<T: Config> OnlineClient<T> {
/// Construct a new [`OnlineClient`] using default settings which
/// point to a locally running node on `ws://127.0.0.1:9944`.
Expand Down
1 change: 1 addition & 0 deletions subxt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub trait Header: Sized + Encode + Decode {

/// implement subxt's Hasher and Header traits for some substrate structs
#[cfg(feature = "substrate-compat")]
#[cfg_attr(docsrs, doc(cfg(feature = "substrate-compat")))]
mod substrate_impls {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions subxt/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod dispatch_error;
use core::fmt::Debug;

#[cfg(feature = "unstable-light-client")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-light-client")))]
pub use crate::client::LightClientError;

// Re-export dispatch error types:
Expand Down Expand Up @@ -73,6 +74,7 @@ pub enum Error {
Unknown(Vec<u8>),
/// Light client error.
#[cfg(feature = "unstable-light-client")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-light-client")))]
#[error("An error occurred but it could not be decoded: {0}")]
LightClient(#[from] LightClientError),
/// Other error.
Expand Down
4 changes: 4 additions & 0 deletions subxt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
//!
//! Take a look at [the Subxt guide](book) to learn more about how to use Subxt.

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

#[cfg(any(
all(feature = "web", feature = "native"),
not(any(feature = "web", feature = "native"))
Expand Down Expand Up @@ -74,8 +76,10 @@ pub mod ext {
pub use scale_encode;
pub use scale_value;
#[cfg(feature = "substrate-compat")]
#[cfg_attr(docsrs, doc(cfg(feature = "substrate-compat")))]
pub use sp_core;
#[cfg(feature = "substrate-compat")]
#[cfg_attr(docsrs, doc(cfg(feature = "substrate-compat")))]
pub use sp_runtime;
}

Expand Down
1 change: 1 addition & 0 deletions subxt/src/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod tx_progress;
// The PairSigner impl currently relies on Substrate bits and pieces, so make it an optional
// feature if we want to avoid needing sp_core and sp_runtime.
#[cfg(feature = "substrate-compat")]
#[cfg_attr(docsrs, doc(cfg(feature = "substrate-compat")))]
pub use self::signer::PairSigner;

pub use self::{
Expand Down
1 change: 1 addition & 0 deletions subxt/src/tx/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub trait Signer<T: Config> {
}

#[cfg(feature = "substrate-compat")]
#[cfg_attr(docsrs, doc(cfg(feature = "substrate-compat")))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line that we have to add below each feature is sortof ugly! I'm not really familiar with it; what does it do? I also wonder whether we could avoid this line duplication somehow.

Copy link
Member Author

@niklasad1 niklasad1 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, we could write a macro for it as we have in jsonrpsee

pub use pair_signer::PairSigner;

// A signer suitable for substrate based chains. This provides compatibility with Substrate
Expand Down
Loading