diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f95064be82..554985ecef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,20 +57,16 @@ jobs: - run: rustup component add rustfmt - run: cargo fmt -- --check - check-docs: - name: Check docs + doc: + name: Doc runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: mkroening/rust-toolchain-toml@main - - run: rustup target add x86_64-unknown-none aarch64-unknown-none-softfloat - uses: Swatinem/rust-cache@v2 with: save-if: ${{ github.ref == 'refs/heads/main' }} - - name: Check docs - run: | - cargo doc --package hermit-kernel --no-deps --document-private-items --target x86_64-unknown-none - cargo doc --package hermit-kernel --no-deps --document-private-items --target aarch64-unknown-none-softfloat --no-default-features + - run: cargo xtask doc build: name: Build diff --git a/xtask/src/arch.rs b/xtask/src/arch.rs index 52c743eb6f..90da9898c3 100644 --- a/xtask/src/arch.rs +++ b/xtask/src/arch.rs @@ -15,6 +15,10 @@ pub enum Arch { } impl Arch { + pub fn all() -> &'static [Self] { + &[Self::X86_64, Self::Aarch64, Self::Riscv64] + } + pub fn install(&self) -> Result<()> { let sh = crate::sh()?; let triple = self.triple(); diff --git a/xtask/src/clippy.rs b/xtask/src/clippy.rs index b241ed53a0..34c5dc464e 100644 --- a/xtask/src/clippy.rs +++ b/xtask/src/clippy.rs @@ -12,10 +12,10 @@ impl Clippy { pub fn run(self) -> Result<()> { let sh = crate::sh()?; - for target in [Arch::X86_64, Arch::Aarch64, Arch::Riscv64] { - target.install()?; + for arch in Arch::all() { + arch.install()?; - let triple = target.triple(); + let triple = arch.triple(); cmd!(sh, "cargo clippy --target={triple}").run()?; cmd!(sh, "cargo clippy --target={triple}") .arg("--no-default-features") @@ -29,7 +29,7 @@ impl Clippy { .arg("--features=acpi,fsgsbase,pci,smp,vga") .run()?; - if target == Arch::Riscv64 { + if *arch == Arch::Riscv64 { cmd!(sh, "cargo clippy --target={triple}") .arg("--no-default-features") .arg("--features=gem-net,tcp") diff --git a/xtask/src/doc.rs b/xtask/src/doc.rs new file mode 100644 index 0000000000..7d7adddcb9 --- /dev/null +++ b/xtask/src/doc.rs @@ -0,0 +1,30 @@ +use anyhow::Result; +use clap::Args; +use xshell::cmd; + +use crate::arch::Arch; + +/// Run rustdoc for all targets. +#[derive(Args)] +pub struct Doc; + +impl Doc { + pub fn run(self) -> Result<()> { + let sh = crate::sh()?; + + let mut doc = cmd!( + sh, + "cargo doc --package hermit-kernel --no-deps --document-private-items" + ); + + for arch in Arch::all() { + arch.install()?; + let triple = arch.triple(); + doc = doc.arg(format!("--target={triple}")); + } + + doc.run()?; + + Ok(()) + } +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index af71cf868c..f8a6df8271 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -8,6 +8,7 @@ mod build; mod cargo_build; mod ci; mod clippy; +mod doc; use std::path::Path; @@ -22,6 +23,7 @@ enum Cli { #[command(subcommand)] Ci(ci::Ci), Clippy(clippy::Clippy), + Doc(doc::Doc), } impl Cli { @@ -30,6 +32,7 @@ impl Cli { Self::Build(build) => build.run(), Self::Ci(ci) => ci.run(), Self::Clippy(clippy) => clippy.run(), + Self::Doc(doc) => doc.run(), } } }