atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git
xtask/src/main.rsRust95 lines2.1 KB
1
#![allow(unexpected_cfgs)]
2
3
mod ci;
4
mod fixup;
5
mod kotlin;
6
mod log;
7
mod release;
8
mod swift;
9
mod workspace;
10
11
use std::rc::Rc;
12
13
use ci::CiArgs;
14
use clap::{Parser, Subcommand};
15
use fixup::FixupArgs;
16
use kotlin::KotlinArgs;
17
use log::LogArgs;
18
use release::ReleaseArgs;
19
use swift::SwiftArgs;
20
use xshell::{Shell, cmd};
21
22
const NIGHTLY: &str = "nightly-2026-02-26";
23
24
type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
25
26
#[derive(Parser)]
27
struct Xtask {
28
    #[clap(subcommand)]
29
    cmd: Command,
30
}
31
32
#[derive(Subcommand)]
33
enum Command {
34
    /// Run continuous integration checks
35
    Ci(CiArgs),
36
    /// Fix up automatic checks
37
    Fixup(FixupArgs),
38
    /// Build the SDKs documentation
39
    Doc {
40
        /// Opens the docs in a browser after the operation
41
        #[clap(long)]
42
        open: bool,
43
    },
44
    /// Prepare and publish a release of the matrix-sdk crates
45
    Release(ReleaseArgs),
46
    Swift(SwiftArgs),
47
    Kotlin(KotlinArgs),
48
    Log(LogArgs),
49
}
50
51
fn main() -> Result<()> {
52
    match Xtask::parse().cmd {
53
        Command::Ci(ci) => ci.run(),
54
        Command::Fixup(cfg) => cfg.run(),
55
        Command::Doc { open } => build_docs(open.then_some("--open"), DenyWarnings::No),
56
        Command::Swift(cfg) => cfg.run(),
57
        Command::Kotlin(cfg) => cfg.run(),
58
        Command::Release(cfg) => cfg.run(),
59
        Command::Log(cfg) => cfg.run(),
60
    }
61
}
62
63
enum DenyWarnings {
64
    Yes,
65
    No,
66
}
67
68
fn build_docs(
69
    extra_args: impl IntoIterator<Item = &'static str>,
70
    deny_warnings: DenyWarnings,
71
) -> Result<()> {
72
    let mut rustdocflags = "--enable-index-page -Zunstable-options --cfg docsrs".to_owned();
73
    if let DenyWarnings::Yes = deny_warnings {
74
        rustdocflags += " -Dwarnings";
75
    }
76
77
    let sh = sh();
78
    // Keep in sync with .github/workflows/docs.yml
79
    cmd!(sh, "rustup run {NIGHTLY} cargo doc --no-deps --workspace --features docsrs")
80
        .env("RUSTDOCFLAGS", rustdocflags)
81
        .args(extra_args)
82
        .run()?;
83
84
    Ok(())
85
}
86
87
thread_local! {
88
    /// The shared shell API.
89
    static SH: Rc<Shell> = Rc::new(Shell::new().unwrap())
90
}
91
92
/// Get a reference to the shared shell API.
93
fn sh() -> Rc<Shell> {
94
    SH.with(|sh| sh.clone())
95
}