name: Rust

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build_lin:
    name: Build and publish (Linux)
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - name: Install GPU drivers
      run: |
        sudo apt-get install -y gpg-agent wget
        wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | sudo apt-key add -
        sudo apt-add-repository 'deb [arch=amd64] https://repositories.intel.com/graphics/ubuntu focal main'
        sudo apt-get update
        sudo apt-get install intel-opencl-icd intel-level-zero-gpu level-zero intel-media-va-driver-non-free libmfx1 libigc-dev intel-igc-cm libigdfcl-dev libigfxcmrt-dev level-zero-dev ocl-icd-opencl-dev
    - name: Build
      run: cargo build --workspace --verbose --release
    - name: Rename to libcuda.so
      run: |
        mv target/release/libnvcuda.so target/release/libcuda.so
        ln -s libcuda.so target/release/libcuda.so.1
    - uses: actions/upload-artifact@v2
      with:
        name: Linux
        path: |
          target/release/libcuda.so
          target/release/libcuda.so.1
          target/release/libnvml.so
  build_win:
    name: Build and publish (Windows)
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - name: Build
      run: cargo build --workspace --verbose --release
    - uses: actions/upload-artifact@v2
      with:
        name: Windows
        path: |
          target/release/nvcuda.dll
          target/release/nvml.dll
          target/release/zluda_redirect.dll
          target/release/zluda_with.exe
          target/release/zluda_dump.dll
    # TODO(take-cheeze): Support testing
    # - name: Run tests
    #   run: cargo test --verbose
