liblitho 0.2.0

cli tool to flash/clone the images to storage devices
Documentation
name: build

on:
  push:
    branches:
      - "*"
  pull_request:

jobs:
  build-binaries-linux:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4

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

      - name: Rust cache
        uses: swatinem/rust-cache@v2

      - name: Run tests
        run: cargo test --locked

      - name: Build CLI and TUI (real-io)
        run: |
          cargo build --release --locked \
            --no-default-features --features real-io \
            --bin litho --bin litho-tui

      - name: Stage release artifacts
        run: |
          triple="$(rustc --print host-tuple)"
          mkdir -p dist
          cp target/release/litho "dist/litho-${triple}"
          cp target/release/litho-tui "dist/litho-tui-${triple}"
          chmod +x dist/*

      - uses: actions/upload-artifact@v4
        with:
          name: litho-binaries-linux-x86_64
          path: dist/*
          if-no-files-found: error

  build-binaries-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4

      # windows-latest ships OpenSSL at C:\Program Files\OpenSSL (see actions/runner-images Install-OpenSSL.ps1).
      - name: Configure pre-installed OpenSSL for openssl-sys
        shell: pwsh
        run: |
          $opensslDir = 'C:\Program Files\OpenSSL'
          if (-not (Test-Path $opensslDir)) {
            Write-Error "Pre-installed OpenSSL not found at $opensslDir"
            exit 1
          }

          $libMatch = Get-ChildItem -Path $opensslDir -Recurse -Filter 'libcrypto.lib' -ErrorAction SilentlyContinue | Select-Object -First 1
          if (-not $libMatch) {
            Write-Error "libcrypto.lib not found under $opensslDir"
            exit 1
          }
          $libDir = $libMatch.DirectoryName

          $includeDir = Join-Path $opensslDir 'include'
          if (-not (Test-Path $includeDir)) {
            Write-Error "OpenSSL include dir not found at $includeDir"
            exit 1
          }

          Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$opensslDir"
          Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_LIB_DIR=$libDir"
          Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_INCLUDE_DIR=$includeDir"

      # rust-lzma uses vcpkg on Windows; the runner has C:\vcpkg but not VCPKG_ROOT.
      - name: Configure pre-installed vcpkg for rust-lzma
        shell: pwsh
        run: |
          $vcpkgRoot = 'C:\vcpkg'
          $vcpkgExe = Join-Path $vcpkgRoot 'vcpkg.exe'
          if (-not (Test-Path $vcpkgExe)) {
            Write-Error "Pre-installed vcpkg not found at $vcpkgExe"
            exit 1
          }
          & $vcpkgExe install liblzma:x64-windows-static-md
          if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
          Add-Content -Path $env:GITHUB_ENV -Value "VCPKG_ROOT=$vcpkgRoot"

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

      - name: Rust cache
        uses: swatinem/rust-cache@v2

      - name: Run tests
        run: cargo test --locked

      - name: Build CLI and TUI (real-io)
        run: |
          cargo build --release --locked `
            --no-default-features --features real-io `
            --bin litho --bin litho-tui

      - name: Stage release artifacts
        shell: pwsh
        run: |
          $triple = (rustc --print host-tuple).Trim()
          New-Item -ItemType Directory -Force -Path dist | Out-Null
          Copy-Item "target\release\litho.exe" "dist\litho-$triple.exe"
          Copy-Item "target\release\litho-tui.exe" "dist\litho-tui-$triple.exe"

      - uses: actions/upload-artifact@v4
        with:
          name: litho-binaries-windows-x86_64
          path: dist/*
          if-no-files-found: error