sys-lib 0.2.0

System facts for Rust services: OS, CPU, memory, disks, network, host, this process, virtualization, power, and device identity, container-aware by default, plus build info, instance info, and a process guard. No subprocesses, zero third-party dependencies.
Documentation
name: CI

on:
  push:
    branches: [main, dev]
  pull_request:
    branches: [main, dev]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"
  # Run every JS action on Node.js 24 ahead of GitHub's forced migration,
  # silencing "Node.js 20 actions are deprecated" runner warnings.
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
  test:
    name: Test (${{ matrix.os }} / ${{ matrix.rust }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # x86_64 and aarch64 on every OS: macos-latest is aarch64 only, so
        # macos-15-intel covers x86_64 macOS (dev/PLAN.md, D-009).
        os:
          - ubuntu-latest
          - ubuntu-24.04-arm
          - macos-latest
          - macos-15-intel
          - windows-latest
          - windows-11-arm
        rust: [stable, "1.89"]
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@v2
      - name: Format
        run: cargo fmt --all -- --check
      - name: Clippy (default features)
        run: cargo clippy --all-targets -- -D warnings
      - name: Clippy (all features)
        run: cargo clippy --all-targets --all-features -- -D warnings
      - name: Clippy (no default features)
        run: cargo clippy --all-targets --no-default-features -- -D warnings
      - name: Test (default features)
        run: cargo test
      - name: Test (all features)
        run: cargo test --all-features
      - name: Test (no default features)
        run: cargo test --no-default-features
      - name: Build examples
        run: cargo build --examples
      # Both modes: a doc link to a feature-gated item breaks only when that
      # feature is off (dev/PLAN.md, D-010).
      - name: Doc (default features)
        run: cargo doc --no-deps
        env:
          RUSTDOCFLAGS: "-D warnings"
      - name: Doc (all features)
        run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: "-D warnings"

  cross:
    name: Check (${{ matrix.target }} / ${{ matrix.rust }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-musl
          - i686-pc-windows-msvc
          - aarch64-linux-android
          - aarch64-apple-ios
        rust: [stable, "1.89"]
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          targets: ${{ matrix.target }}
          components: clippy
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}
      - name: Check (default features)
        run: cargo check --target ${{ matrix.target }}
      - name: Check (all features)
        run: cargo check --target ${{ matrix.target }} --all-features
      - name: Check (no default features)
        run: cargo check --target ${{ matrix.target }} --no-default-features
      # --all-targets compiles the unit tests too, and with them the layout
      # oracles in src/sys/<platform>/ffi.rs (dev/PLAN.md, D-012): every OS
      # struct is checked against libc or windows-sys for this target.
      - name: Clippy and layout oracles (all features)
        run: cargo clippy --target ${{ matrix.target }} --all-targets --all-features -- -D warnings
      - name: Clippy and layout oracles (no default features)
        run: cargo clippy --target ${{ matrix.target }} --all-targets --no-default-features -- -D warnings

  no-subprocess:
    name: No subprocess at run time
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Only the build helper may start a program
        shell: bash
        run: |
          set -euo pipefail
          # 1. std::process::Command anywhere in src/ outside the build helper
          #    (src/build.rs, src/build/).
          std_hits=$(grep -rnE 'Command::new|process::Command|process::\{[^}]*\bCommand\b' src --include='*.rs' \
            | grep -vE '^src/build(\.rs|/)' || true)
          # 2. Process-creation calls declared or called in the OS modules.
          #    Names followed by `(` (a declaration or a call); comment lines are
          #    skipped so prose such as "a system call" does not match.
          ffi_hits=$(grep -rnE '\b(CreateProcess(A|W|AsUserW)?|ShellExecute(Ex)?W|WinExec)\b|\b(posix_spawnp?|execv[pe]?|execl[pe]?|popen|v?fork|system)[[:space:]]*\(' src/sys --include='*.rs' 2>/dev/null \
            | grep -vE '^[^:]+:[0-9]+:[[:space:]]*//' || true)
          if [ -n "$std_hits$ffi_hits" ]; then
            echo "sys-lib never runs a program at run time (dev/PLAN.md, D-004)."
            echo "$std_hits"
            echo "$ffi_hits"
            exit 1
          fi
          echo "No subprocess found outside the build helper."

  package:
    name: Package
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Package
        run: cargo package

  security:
    name: Security (audit + deny)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Install cargo-audit and cargo-deny
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-audit,cargo-deny
      - name: Generate lockfile
        run: cargo generate-lockfile
      - name: Audit
        run: cargo audit
      - name: Deny
        run: cargo deny check