Skip to content

Commit 2ae860e

Browse files
committed
tasks: add docs and bench commands
1 parent 7e16550 commit 2ae860e

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

tasks/src/bench.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Benchmark testing tasks.
2+
3+
use crate::environment::{get_crate_dirs, quiet_println};
4+
use crate::quiet_cmd;
5+
use crate::toolchain::{check_toolchain, Toolchain};
6+
use xshell::Shell;
7+
8+
/// Run benchmark tests for all crates in the workspace.
9+
pub fn run(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
10+
check_toolchain(sh, Toolchain::Nightly)?;
11+
12+
let crate_dirs = get_crate_dirs(sh)?;
13+
14+
quiet_println(&format!(
15+
"Running bench tests for {} crates",
16+
crate_dirs.len()
17+
));
18+
19+
for crate_dir in &crate_dirs {
20+
quiet_println(&format!("Running bench tests in: {}", crate_dir));
21+
22+
// Use pushd pattern to change and restore directory.
23+
let _dir = sh.push_dir(crate_dir);
24+
25+
quiet_cmd!(sh, "cargo bench")
26+
.env("RUSTFLAGS", "--cfg=bench")
27+
.run()?;
28+
}
29+
30+
Ok(())
31+
}

tasks/src/docs.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Documentation building tasks.
2+
3+
use crate::quiet_cmd;
4+
use crate::toolchain::{check_toolchain, Toolchain};
5+
use xshell::Shell;
6+
7+
/// Build documentation with stable toolchain.
8+
pub fn build_docs_stable(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
9+
check_toolchain(sh, Toolchain::Stable)?;
10+
11+
quiet_cmd!(sh, "cargo doc --all-features")
12+
.env("RUSTDOCFLAGS", "-D warnings")
13+
.run()?;
14+
15+
Ok(())
16+
}
17+
18+
/// Build documentation with nightly toolchain for docs.rs.
19+
pub fn build_docs_nightly(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
20+
check_toolchain(sh, Toolchain::Nightly)?;
21+
22+
quiet_cmd!(sh, "cargo doc --all-features")
23+
.env(
24+
"RUSTDOCFLAGS",
25+
"--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links",
26+
)
27+
.run()?;
28+
29+
Ok(())
30+
}

tasks/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod bench;
2+
mod docs;
13
mod environment;
24
mod lint;
35
mod toolchain;
@@ -20,6 +22,12 @@ struct Cli {
2022
enum Commands {
2123
/// Run the linter (clippy) for workspace and all crates.
2224
Lint,
25+
/// Build documentation with stable toolchain.
26+
Docs,
27+
/// Build documentation with nightly toolchain for docs.rs.
28+
Docsrs,
29+
/// Run benchmark tests for all crates.
30+
Bench,
2331
}
2432

2533
fn main() {
@@ -35,5 +43,23 @@ fn main() {
3543
process::exit(1);
3644
}
3745
}
46+
Commands::Docs => {
47+
if let Err(e) = docs::build_docs_stable(&sh) {
48+
eprintln!("Error building docs: {}", e);
49+
process::exit(1);
50+
}
51+
}
52+
Commands::Docsrs => {
53+
if let Err(e) = docs::build_docs_nightly(&sh) {
54+
eprintln!("Error building docs.rs docs: {}", e);
55+
process::exit(1);
56+
}
57+
}
58+
Commands::Bench => {
59+
if let Err(e) = bench::run(&sh) {
60+
eprintln!("Error running bench tests: {}", e);
61+
process::exit(1);
62+
}
63+
}
3864
}
3965
}

0 commit comments

Comments
 (0)