rust-sasa 0.9.2

RustSASA is a Rust library for computing the absolute solvent accessible surface area (ASA/SASA) of each atom in a given protein structure using the Shrake-Rupley algorithm.
Documentation
name: Rust
on:
  push:
    branches: ["main", "radical"]
    tags: ["v*"]
  pull_request:
    branches: ["main"]
env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
permissions:
  contents: write # Required for creating releases
  actions: read
  checks: read
jobs:
  quality:
    name: Code Quality
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v5
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.91.0
          components: rustfmt, clippy

      - name: Get submodules
        run: |
          git submodule update --init --recursive

      - name: Hack to fix clippy submodules issue
        run: |
          sed -i 's/pdbtbx = { path = "pdbtbx", version = "0.12.0" }/pdbtbx = "0.12.0"/' Cargo.toml
          rm -rf pdbtbx/

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

      - name: Run clippy
        env:
          RUSTFLAGS: "-Dwarnings"
        run: cargo clippy --all-targets --all-features

  test:
    name: Test
    runs-on: ubuntu-24.04
    needs: quality
    steps:
      - uses: actions/checkout@v5
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.91.0
      - name: Get submodules
        run: |
          git submodule update --init --recursive
      - name: Run tests
        run: cargo test

  build:
    name: Build PGO optimized binaries
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [quality, test]
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu # CONFIRMED WORKING
            os: ubuntu-24.04
            name: rust-sasa-linux-gnu-x86_64
          - target: x86_64-pc-windows-msvc # CONFIRMED WORKING
            os: windows-2025
            name: rust-sasa-windows-x86_64.exe
          # - target: aarch64-apple-darwin
          #   os: macos-15
          #   name: rust-sasa-aarch64-apple-darwin
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v5
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.91.0
          targets: ${{ matrix.target }}
          components: llvm-tools-preview

      - name: Get submodules
        run: |
          git submodule update --init --recursive

      - name: Install LLVM and Clang
        uses: KyleMayes/install-llvm-action@v2
        with:
          version: "20.1.0"

      - name: Install cargo-pgo
        run: cargo install cargo-pgo

      - name: Build initial binary for PGO
        if: matrix.os == 'windows-2025' || matrix.os == 'ubuntu-24.04'
        run: cargo pgo build -- --target ${{ matrix.target }}

      - name: Create temp output directory
        run: mkdir temp_out

      - name: Download AlphaFold dataset
        shell: bash
        run: |
          if [ ! -f UP000000625_83333_ECOLI_v4.tar ]; then
            curl -L -o UP000000625_83333_ECOLI_v4.tar https://ftp.ebi.ac.uk/pub/databases/alphafold/latest/UP000000625_83333_ECOLI_v6.tar
          fi

      - name: Run PGO profiling (Linux/Unix)
        if: matrix.os == 'ubuntu-24.04' || matrix.os == 'macos-15'
        run: |
          mkdir -p UP000000625_83333_ECOLI_v4/
          tar -xf UP000000625_83333_ECOLI_v4.tar -C UP000000625_83333_ECOLI_v4/
          rm -rf UP000000625_83333_ECOLI_v4/*.cif
          gunzip UP000000625_83333_ECOLI_v4/*.gz
          cargo pgo run -- --features="cli" UP000000625_83333_ECOLI_v4/ temp_out/ --format json

      - name: Run PGO profiling (Windows)
        if: matrix.os == 'windows-2025'
        shell: powershell
        run: |
          mkdir UP000000625_83333_ECOLI_v4/
          tar -xf UP000000625_83333_ECOLI_v4.tar -C UP000000625_83333_ECOLI_v4/
          Remove-Item -Path "UP000000625_83333_ECOLI_v4/*.cif" -Force -ErrorAction SilentlyContinue
          Get-ChildItem -Path "UP000000625_83333_ECOLI_v4" -Filter "*.gz" | ForEach-Object {
              & "C:\Program Files\7-Zip\7z.exe" x $_.FullName -o"$(Split-Path $_.FullName -Parent)" -y | Out-Null
              Remove-Item $_.FullName
          }
          cargo pgo run -- --features="cli" UP000000625_83333_ECOLI_v4/ temp_out/ --format json
      - name: Optimize with PGO
        run: |
          cargo pgo optimize build -- --target ${{ matrix.target }} --bin rust-sasa --features="cli"
      - name: Copy optimized binary (Unix)
        if: matrix.os != 'windows-2025'
        run: |
          cp target/${{ matrix.target }}/release/rust-sasa ${{ matrix.name }}
      - name: Copy optimized binary (Windows)
        if: matrix.os == 'windows-2025'
        run: |
          copy target\${{ matrix.target }}\release\rust-sasa.exe ${{ matrix.name }}
        shell: cmd
      - name: Upload binary artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.name }}
          path: ${{ matrix.name }}
          retention-days: 1

  release:
    name: Create Release
    needs: build
    runs-on: ubuntu-24.04
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - uses: actions/checkout@v5
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: ./artifacts
      - name: Display structure of downloaded files
        run: ls -la ./artifacts/
      - name: Prepare release files
        run: |
          mkdir -p ./release
          find ./artifacts -name "rust-sasa-*" -type f -exec cp {} ./release/ \;
          ls -la ./release/
      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: ./release/*
          draft: false
          prerelease: false
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}