hisi-hal 0.7.0-alpha.3

Hardware Abstraction Layer for HiSilicon WS63 (RISC-V RV32IMFC_Zicsr)
name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    types: [opened, synchronize, reopened]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  TARGET: riscv32imfc-unknown-none-elf

concurrency:
  cancel-in-progress: true
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

jobs:
  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      - run: cargo fmt --all --check

  register-access:
    name: Register access policy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: python3 scripts/check-register-access.py

  stable-api:
    name: Stable API snapshot
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      - run: cargo install cargo-public-api --version 0.52.0 --locked
      - run: scripts/check-stable-api.sh --check
      - run: scripts/check-rename-api.sh
      - name: Stable-only rustdoc has no private links
        run: cargo doc --locked --no-deps --no-default-features --features chip-ws63
        env:
          RUSTFLAGS: --cfg instability_disable_unstable_docs
          RUSTDOCFLAGS: -D warnings

  # NB: chip-ws63 and chip-bs21 are mutually exclusive (a compile_error in lib.rs),
  # so `--all-features` cannot be used. Test each chip with its supported feature
  # set instead. BS2X is experimental/no-silicon-HIL, so chip-bs21 always opts into
  # `unstable`; async/embassy are only wired for chip-ws63 today.
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features: ["chip-ws63,rt,async,embassy", "chip-ws63,rt,async,embassy,defmt", "chip-bs21,rt,unstable"]
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      - run: cargo clippy -Zbuild-std=core,alloc --target "$TARGET" --locked --no-default-features --features "${{ matrix.features }}" -- -D warnings

  build:
    name: Build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features: ["chip-ws63,rt,async,embassy", "chip-ws63,rt,async,embassy,defmt", "chip-bs21,rt,unstable"]
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      - run: cargo check -Zbuild-std=core,alloc --target "$TARGET" --locked --no-default-features --features "${{ matrix.features }}"
      - run: cargo check -Zbuild-std=core,alloc --target "$TARGET" --locked --no-default-features --features "${{ matrix.features }}" --release

  bs2x-gate:
    name: BS2X requires unstable
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      - run: |
          if cargo check -Zbuild-std=core,alloc --target "$TARGET" --locked --no-default-features --features chip-bs21,rt 2>bs2x-stable.log; then
            printf 'chip-bs21 built without unstable\n'
            exit 1
          fi
          grep -q 'BS2X support is experimental' bs2x-stable.log

  doc:
    name: Docs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: rustup show active-toolchain
      # The HAL has no default chip (esp-hal style) — docs must select one, matching
      # the [package.metadata.docs.rs] feature set.
      - run: cargo doc -Zbuild-std=core,alloc --target "$TARGET" --locked --no-deps --document-private-items --no-default-features --features "chip-ws63,rt,async,embassy"
        env:
          RUSTDOCFLAGS: -D warnings

  # Catch accidental SemVer-incompatible API changes: compares this crate's public
  # API against the last release on crates.io and fails if the change level (patch
  # / minor / major) is not reflected in the version bump. A breaking change with
  # no bump turns the PR red — exactly when an API tightening (e.g. a `configure`
  # signature change) needs a 0.x-minor bump. Runs on the host (the lib compiles
  # for x86_64 — same as the unit tests); the action installs cargo-semver-checks
  # and the nightly rustdoc it needs. The HAL has NO default chip (esp-hal style)
  # and its `default` pulls `rt` (whose startup asm does not assemble for the host),
  # so we check ONLY the explicitly-listed `chip-ws63` feature — not the default
  # group (which would fire the no-chip `compile_error!`) and not `--all-features`
  # (chip-ws63/chip-bs21 are mutually exclusive). chip-ws63 is the core host-buildable
  # surface; async/embassy/rt are riscv-target-only and out of the host semver scope.
  semver:
    name: SemVer
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Detect published package baseline
        id: baseline
        run: |
          if cargo search '^hisi-hal$' --limit 1 | grep -q '^hisi-hal = '; then
            echo 'available=true' >> "$GITHUB_OUTPUT"
          else
            echo 'available=false' >> "$GITHUB_OUTPUT"
          fi
      - name: cargo-semver-checks (vs last crates.io release)
        if: steps.baseline.outputs.available == 'true'
        uses: obi1kenobi/cargo-semver-checks-action@v2
        with:
          feature-group: only-explicit-features
          features: chip-ws63