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

feat(xtask): add xtask doc #1200

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions xtask/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions xtask/src/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
30 changes: 30 additions & 0 deletions xtask/src/doc.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
3 changes: 3 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod build;
mod cargo_build;
mod ci;
mod clippy;
mod doc;

use std::path::Path;

Expand All @@ -22,6 +23,7 @@ enum Cli {
#[command(subcommand)]
Ci(ci::Ci),
Clippy(clippy::Clippy),
Doc(doc::Doc),
}

impl Cli {
Expand All @@ -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(),
}
}
}
Expand Down