ptools 0.2.23

Utilities for inspecting Linux processes
---
name: Build

on:
  push:
    branches:
      - master
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"

jobs:
  build:
    name: Build
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-24.04, ubuntu-24.04-arm]
    runs-on: ${{ matrix.os }}
    permissions:
      contents: read
    steps:
      - name: Check out
        uses: actions/checkout@v7.0.1

      - name: Install system dependencies
        run: sudo apt-get update && sudo apt-get install -y libdw-dev libsystemd-dev

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Check Markdown
        uses: DavidAnson/markdownlint-cli2-action@v24.2.0

      - name: Run Clippy
        run: cargo clippy --all-targets --all-features

      - name: Build
        run: cargo build --verbose

      - name: Test
        run: cargo test --verbose

      - name: Install coverage tooling
        run: rustup component add llvm-tools-preview

      - name: Build instrumented binaries for E2E coverage
        run: |
          RUSTFLAGS='-C instrument-coverage' \
          cargo build --all-features --workspace --bins --examples

      - name: Run coverage tests
        run: |
          mkdir -p target/coverage
          RUSTFLAGS='-C instrument-coverage' \
          LLVM_PROFILE_FILE='target/coverage/ptools-%p-%m.profraw' \
          cargo test --all-features --workspace --tests --bins

      - name: Report coverage
        shell: bash
        run: |
          host_target=$(rustc -vV | awk '/host:/ {print $2}')
          llvm_bin="$(rustc --print sysroot)/lib/rustlib/${host_target}/bin"
          "${llvm_bin}/llvm-profdata" merge -sparse target/coverage/*.profraw -o target/coverage/ptools.profdata
          "${llvm_bin}/llvm-cov" report \
            --ignore-filename-regex='/(\.cargo/registry|rustc)/' \
            --instr-profile=target/coverage/ptools.profdata \
            target/debug/pargs --object target/debug/pauxv --object target/debug/pcred \
            --object target/debug/penv \
            --object target/debug/pfiles --object target/debug/plgrp --object target/debug/plimit \
            --object target/debug/prun \
            --object target/debug/psig --object target/debug/pstack --object target/debug/pstop \
            --object target/debug/ptime --object target/debug/ptree \
            --object target/debug/pwait

  build-i686:
    name: Build (i686)
    runs-on: ubuntu-24.04
    permissions:
      contents: read
    env:
      PKG_CONFIG_ALLOW_CROSS: 1
      PKG_CONFIG_PATH: /usr/lib/i386-linux-gnu/pkgconfig
      CARGO_BUILD_TARGET: i686-unknown-linux-gnu
    steps:
      - name: Check out
        uses: actions/checkout@v7.0.1

      - name: Install i686 cross-compilation dependencies
        run: |
          sudo dpkg --add-architecture i386
          sudo apt-get update
          sudo apt-get install -y gcc-multilib libdw-dev:i386 libsystemd-dev:i386

      - name: Install Rust i686 target
        run: rustup target add i686-unknown-linux-gnu

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Check Markdown
        uses: DavidAnson/markdownlint-cli2-action@v24.2.0

      - name: Run Clippy
        run: cargo clippy --all-targets --all-features

      - name: Build
        run: cargo build --verbose

      - name: Test
        run: cargo test --verbose

      - name: Install coverage tooling
        run: rustup component add llvm-tools-preview

      - name: Build instrumented binaries for E2E coverage
        run: |
          RUSTFLAGS='-C instrument-coverage' \
          cargo build --all-features --workspace --bins --examples

      - name: Run coverage tests
        run: |
          mkdir -p target/coverage
          RUSTFLAGS='-C instrument-coverage' \
          LLVM_PROFILE_FILE='target/coverage/ptools-%p-%m.profraw' \
          cargo test --all-features --workspace --tests --bins

      - name: Report coverage
        shell: bash
        run: |
          target_dir="target/i686-unknown-linux-gnu/debug"
          host_target=$(rustc -vV | awk '/host:/ {print $2}')
          llvm_bin="$(rustc --print sysroot)/lib/rustlib/${host_target}/bin"
          "${llvm_bin}/llvm-profdata" merge -sparse target/coverage/*.profraw -o target/coverage/ptools.profdata
          "${llvm_bin}/llvm-cov" report \
            --ignore-filename-regex='/(\.cargo/registry|rustc)/' \
            --instr-profile=target/coverage/ptools.profdata \
            "${target_dir}/pargs" --object "${target_dir}/pauxv" --object "${target_dir}/pcred" \
            --object "${target_dir}/penv" \
            --object "${target_dir}/pfiles" --object "${target_dir}/plgrp" --object "${target_dir}/plimit" \
            --object "${target_dir}/prun" \
            --object "${target_dir}/psig" --object "${target_dir}/pstack" --object "${target_dir}/pstop" \
            --object "${target_dir}/ptime" --object "${target_dir}/ptree" \
            --object "${target_dir}/pwait"