catboost-rust 0.4.0

Rust bindings for CatBoost, a gradient boosting library for machine learning. Downloads CatBoost binaries at runtime for cross-platform compatibility.
name: CI

on:
  push:
    branches: [ publish ]
  pull_request:
    branches: [ publish ]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Test ${{ matrix.os }} (${{ matrix.arch }}) - CatBoost ${{ matrix.catboost_version }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # macOS ARM64 (M1/M2/M3)
          - os: macos
            arch: arm64
            runner: macos-14
            catboost_version: "1.2.7"
          - os: macos
            arch: arm64
            runner: macos-14
            catboost_version: "1.2.5"

          # Linux x86_64
          - os: linux
            arch: x86_64
            runner: ubuntu-latest
            catboost_version: "1.2.7"
          - os: linux
            arch: x86_64
            runner: ubuntu-latest
            catboost_version: "1.2.5"

          - os: linux
            arch: arm64
            runner: ubuntu-24.04-arm
            catboost_version: "1.2.7"

          - os: linux
            arch: arm64
            runner: ubuntu-24.04-arm
            catboost_version: "1.2.10"

          # Windows x86_64
          - os: windows
            arch: x86_64
            runner: windows-latest
            catboost_version: "1.2.7"

    steps:
    - uses: actions/checkout@v4

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

    - name: Cache cargo registry
      uses: actions/cache@v4
      with:
        path: ~/.cargo/registry
        key: ${{ runner.os }}-${{ matrix.arch }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-${{ matrix.arch }}-cargo-registry-

    - name: Cache cargo index
      uses: actions/cache@v4
      with:
        path: ~/.cargo/git
        key: ${{ runner.os }}-${{ matrix.arch }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-${{ matrix.arch }}-cargo-index-

    - name: Cache cargo build
      uses: actions/cache@v4
      with:
        path: target
        key: ${{ runner.os }}-${{ matrix.arch }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-${{ matrix.arch }}-cargo-build-target-

    - name: Install system dependencies (Linux)
      if: matrix.os == 'linux'
      run: |
        sudo apt-get update
        sudo apt-get install -y libclang-dev

    - name: Check build (no features)
      env:
        CATBOOST_VERSION: ${{ matrix.catboost_version }}
      run: cargo check --verbose

    - name: Build (no features)
      env:
        CATBOOST_VERSION: ${{ matrix.catboost_version }}
      run: cargo build --verbose

    - name: Run tests (no features)
      env:
        CATBOOST_VERSION: ${{ matrix.catboost_version }}
      run: cargo test --verbose

    - name: Build examples
      env:
        CATBOOST_VERSION: ${{ matrix.catboost_version }}
      run: |
        cargo build --example basic_usage --verbose
        cargo build --example advanced_usage --verbose

    - name: Verify library architecture (macOS)
      if: matrix.os == 'macos'
      run: |
        echo "Checking library architecture..."
        file target/debug/libcatboostmodel.dylib || file target/debug/libcatboost.dylib || true
        lipo -info target/debug/libcatboostmodel.dylib || lipo -info target/debug/libcatboost.dylib || true

    - name: Verify library architecture (Linux)
      if: matrix.os == 'linux'
      run: |
        echo "Checking library architecture..."
        file target/debug/libcatboostmodel.so || file target/debug/libcatboost.so || true
        readelf -h target/debug/libcatboostmodel.so | grep Machine || readelf -h target/debug/libcatboost.so | grep Machine || true

    - name: Verify library exists (Windows)
      if: matrix.os == 'windows'
      run: |
        echo "Checking library exists..."
        Get-Item target/debug/catboostmodel.dll -ErrorAction SilentlyContinue
        Get-Item target/debug/catboost.dll -ErrorAction SilentlyContinue

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

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

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y libclang-dev

    - name: Run clippy (no features)
      run: cargo clippy -- -D warnings

  fmt:
    name: Format
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

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

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

  # Test minimum supported CatBoost version
  min-version:
    name: Test minimum CatBoost version
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

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

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y libclang-dev

    - name: Test with CatBoost 1.2.1
      env:
        CATBOOST_VERSION: "1.2.1"
      run: |
        cargo check --verbose
        cargo build --verbose