dtoolkit 0.1.1

A library for parsing and manipulating Flattened Device Tree (FDT) blobs.
Documentation
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

name: Rust CI

on:
  push:
  pull_request:
  merge_group:
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0

jobs:
  check:
    # Run on external PRs and pushes to branches on the repo
    # This is to avoid double running on PRs from internal branches
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Cargo check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'

      - name: Run cargo check
        run: cargo check --all-targets --all-features

  build:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository
    strategy:
      matrix:
        rust: [stable, nightly, "1.88"] # 1.88 is the MSRV
        os: [ubuntu-latest, macos-latest, windows-latest]

    name: Build & test
    runs-on: ${{ matrix.os }}
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'

      - name: Fetch dependencies
        run: cargo +${{ matrix.rust }} fetch

      - name: Build
        run: cargo +${{ matrix.rust }} build --all-features --tests

      - name: Test
        run: cargo +${{ matrix.rust }} test --all-features

  clippy:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Clippy lint checks
    runs-on: ubuntu-latest
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
          components: clippy

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'
          save-if: 'false'

      - name: Run clippy
        run: cargo clippy --no-deps --all-targets -- -D warnings

  rustfmt:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Code formatting checks
    runs-on: ubuntu-latest
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          # nightly-only rustfmt settings
          toolchain: nightly
          components: rustfmt

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'
          save-if: 'false'

      - name: Run fmt
        run: cargo fmt --all -- --check

  machete:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Machete dependencies checks
    runs-on: ubuntu-latest
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Run cargo-machete
        uses: bnjbvr/cargo-machete@v0.9.1

  minimal-versions:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Minimal dependency versions build
    runs-on: ubuntu-latest
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          # the `-Z` flag is only accepted on the nightly channel of Cargo
          toolchain: nightly

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'
          save-if: 'false'

      - name: Install cargo-hack
        uses: taiki-e/install-action@cargo-hack

      - name: Run cargo check with minimal versions
        run: |
          # Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
          # from determining minimal versions based on dev-dependencies.
          cargo hack --remove-dev-deps --workspace
          # Update Cargo.lock to minimal version dependencies.
          cargo update -Z minimal-versions
          cargo hack check --all-features --ignore-private

  build-feature-power-set:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Build with each feature combination
    runs-on: ubuntu-latest
    needs: ["check"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'
          save-if: 'false'

      - name: Install cargo-hack
        uses: taiki-e/install-action@cargo-hack

      - name: Run cargo check with every combination of features
        run: cargo hack check --feature-powerset --depth 3 --no-dev-deps

  miri:
    if: github.event_name == 'push' || github.event_name == 'schedule' || github.event.pull_request.head.repo.full_name != github.repository

    name: Miri test
    runs-on: ubuntu-latest
    needs: ["build"]
    steps:
      - name: Checkout source
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          # miri requires nightly
          toolchain: nightly
          components: miri

      - name: Cache Cargo registry
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: 'rust-ci'
          cache-bin: 'false'
          save-if: 'false'

      - name: Miri setup
        run: cargo miri setup

      - name: Miri test
        run: cargo miri test --no-fail-fast --all-features
        env:
          MIRIFLAGS: -Zmiri-disable-isolation