diff --git a/xtask/src/doc.rs b/xtask/src/doc.rs new file mode 100644 index 00000000..d513c0bb --- /dev/null +++ b/xtask/src/doc.rs @@ -0,0 +1,41 @@ +use clap::Args; + +use crate::{cmd, Result}; + +#[derive(Args)] +pub struct DocTask { + /// Open the browser when the docs are built. + #[clap(long)] + pub open: bool, + + /// Fail on warnings. + #[clap(long)] + pub deny_warnings: bool, +} + +impl DocTask { + pub(crate) fn run(self) -> Result<()> { + let mut rustdocflags = "--enable-index-page -Zunstable-options --cfg docsrs".to_owned(); + if self.deny_warnings { + rustdocflags += " -Dwarnings"; + } + + // Keep in sync with .github/workflows/docs.yml + let mut cmd = cmd!( + " + rustup run nightly cargo doc --no-deps --workspace + --exclude ruma-macros --exclude ruma-identifiers-validation --exclude xtask + --all-features -Zrustdoc-map + " + ) + .env("RUSTDOCFLAGS", rustdocflags); + + if self.open { + cmd = cmd.arg("--open"); + } + + cmd.run()?; + + Ok(()) + } +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f30892d2..719d1dfc 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -14,12 +14,14 @@ use serde_json::from_str as from_json_str; #[cfg(feature = "default")] mod cargo; mod ci; +mod doc; #[cfg(feature = "default")] mod release; #[cfg(feature = "default")] mod util; use ci::{CiArgs, CiTask}; +use doc::DocTask; #[cfg(feature = "default")] use release::{ReleaseArgs, ReleaseTask}; @@ -35,6 +37,8 @@ struct Xtask { enum Command { /// Run continuous integration checks Ci(CiArgs), + /// Build the docs + Doc(DocTask), /// Publish a new version of a crate on crates.io, `publish` can be used as an alias #[cfg(feature = "default")] #[clap(alias = "publish")] @@ -47,6 +51,7 @@ fn main() -> Result<()> { let ci = CiTask::new(args.cmd)?; ci.run() } + Command::Doc(doc) => doc.run(), #[cfg(feature = "default")] Command::Release(args) => { let mut task = ReleaseTask::new(args.package, args.version)?;